Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack_RelatedPosts often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack_RelatedPosts, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 2 | class Jetpack_RelatedPosts { |
||
| 3 | const VERSION = '20150408'; |
||
| 4 | const SHORTCODE = 'jetpack-related-posts'; |
||
| 5 | |||
| 6 | /** |
||
| 7 | * Creates and returns a static instance of Jetpack_RelatedPosts. |
||
| 8 | * |
||
| 9 | * @return Jetpack_RelatedPosts |
||
| 10 | */ |
||
| 11 | View Code Duplication | public static function init() { |
|
| 12 | static $instance = NULL; |
||
| 13 | |||
| 14 | if ( ! $instance ) { |
||
| 15 | if ( class_exists('WPCOM_RelatedPosts') && method_exists( 'WPCOM_RelatedPosts', 'init' ) ) { |
||
| 16 | $instance = WPCOM_RelatedPosts::init(); |
||
| 17 | } else { |
||
| 18 | $instance = new Jetpack_RelatedPosts( |
||
| 19 | get_current_blog_id(), |
||
| 20 | Jetpack_Options::get_option( 'id' ) |
||
| 21 | ); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | return $instance; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Creates and returns a static instance of Jetpack_RelatedPosts_Raw. |
||
| 30 | * |
||
| 31 | * @return Jetpack_RelatedPosts |
||
| 32 | */ |
||
| 33 | View Code Duplication | public static function init_raw() { |
|
| 34 | static $instance = NULL; |
||
| 35 | |||
| 36 | if ( ! $instance ) { |
||
| 37 | if ( class_exists('WPCOM_RelatedPosts') && method_exists( 'WPCOM_RelatedPosts', 'init_raw' ) ) { |
||
| 38 | $instance = WPCOM_RelatedPosts::init_raw(); |
||
| 39 | } else { |
||
| 40 | $instance = new Jetpack_RelatedPosts_Raw( |
||
| 41 | get_current_blog_id(), |
||
| 42 | Jetpack_Options::get_option( 'id' ) |
||
| 43 | ); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return $instance; |
||
| 48 | } |
||
| 49 | |||
| 50 | protected $_blog_id_local; |
||
| 51 | protected $_blog_id_wpcom; |
||
| 52 | protected $_options; |
||
| 53 | protected $_allow_feature_toggle; |
||
| 54 | protected $_blog_charset; |
||
| 55 | protected $_convert_charset; |
||
| 56 | protected $_previous_post_id; |
||
| 57 | protected $_found_shortcode = false; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Constructor for Jetpack_RelatedPosts. |
||
| 61 | * |
||
| 62 | * @param int $blog_id_local |
||
| 63 | * @param int $blog_id_wpcom |
||
| 64 | * @uses get_option, add_action, apply_filters |
||
| 65 | * @return null |
||
|
|
|||
| 66 | */ |
||
| 67 | public function __construct( $blog_id_local, $blog_id_wpcom ) { |
||
| 68 | $this->_blog_id_local = $blog_id_local; |
||
| 69 | $this->_blog_id_wpcom = $blog_id_wpcom; |
||
| 70 | $this->_blog_charset = get_option( 'blog_charset' ); |
||
| 71 | $this->_convert_charset = ( function_exists( 'iconv' ) && ! preg_match( '/^utf\-?8$/i', $this->_blog_charset ) ); |
||
| 72 | |||
| 73 | add_action( 'admin_init', array( $this, 'action_admin_init' ) ); |
||
| 74 | add_action( 'wp', array( $this, 'action_frontend_init' ) ); |
||
| 75 | |||
| 76 | if ( ! class_exists( 'Jetpack_Media_Summary' ) ) { |
||
| 77 | jetpack_require_lib( 'class.media-summary' ); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * ================= |
||
| 83 | * ACTIONS & FILTERS |
||
| 84 | * ================= |
||
| 85 | */ |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Add a checkbox field to Settings > Reading for enabling related posts. |
||
| 89 | * |
||
| 90 | * @action admin_init |
||
| 91 | * @uses add_settings_field, __, register_setting, add_action |
||
| 92 | * @return null |
||
| 93 | */ |
||
| 94 | public function action_admin_init() { |
||
| 95 | |||
| 96 | // Add the setting field [jetpack_relatedposts] and place it in Settings > Reading |
||
| 97 | add_settings_field( 'jetpack_relatedposts', '<span id="jetpack_relatedposts">' . __( 'Related posts', 'jetpack' ) . '</span>', array( $this, 'print_setting_html' ), 'reading' ); |
||
| 98 | register_setting( 'reading', 'jetpack_relatedposts', array( $this, 'parse_options' ) ); |
||
| 99 | add_action('admin_head', array( $this, 'print_setting_head' ) ); |
||
| 100 | |||
| 101 | if( 'options-reading.php' == $GLOBALS['pagenow'] ) { |
||
| 102 | // Enqueue style for live preview on the reading settings page |
||
| 103 | $this->_enqueue_assets( false, true ); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Load related posts assets if it's a elegiable frontend page or execute search and return JSON if it's an endpoint request. |
||
| 109 | * |
||
| 110 | * @global $_GET |
||
| 111 | * @action wp |
||
| 112 | * @uses add_shortcode, get_the_ID |
||
| 113 | * @returns null |
||
| 114 | */ |
||
| 115 | public function action_frontend_init() { |
||
| 116 | // Add a shortcode handler that outputs nothing, this gets overridden later if we can display related content |
||
| 117 | add_shortcode( self::SHORTCODE, array( $this, 'get_target_html_unsupported' ) ); |
||
| 118 | |||
| 119 | if ( ! $this->_enabled_for_request() ) |
||
| 120 | return; |
||
| 121 | |||
| 122 | if ( isset( $_GET['relatedposts'] ) ) { |
||
| 123 | $excludes = array(); |
||
| 124 | if ( isset( $_GET['relatedposts_exclude'] ) ) { |
||
| 125 | $excludes = explode( ',', $_GET['relatedposts_exclude'] ); |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->_action_frontend_init_ajax( $excludes ); |
||
| 129 | } else { |
||
| 130 | if ( isset( $_GET['relatedposts_hit'], $_GET['relatedposts_origin'], $_GET['relatedposts_position'] ) ) { |
||
| 131 | $this->_log_click( $_GET['relatedposts_origin'], get_the_ID(), $_GET['relatedposts_position'] ); |
||
| 132 | $this->_previous_post_id = (int) $_GET['relatedposts_origin']; |
||
| 133 | } |
||
| 134 | |||
| 135 | $this->_action_frontend_init_page(); |
||
| 136 | } |
||
| 137 | |||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Adds a target to the post content to load related posts into if a shortcode for it did not already exist. |
||
| 142 | * |
||
| 143 | * @filter the_content |
||
| 144 | * @param string $content |
||
| 145 | * @returns string |
||
| 146 | */ |
||
| 147 | public function filter_add_target_to_dom( $content ) { |
||
| 148 | if ( !$this->_found_shortcode ) { |
||
| 149 | $content .= "\n" . $this->get_target_html(); |
||
| 150 | } |
||
| 151 | |||
| 152 | return $content; |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Looks for our shortcode on the unfiltered content, this has to execute early. |
||
| 157 | * |
||
| 158 | * @filter the_content |
||
| 159 | * @param string $content |
||
| 160 | * @uses has_shortcode |
||
| 161 | * @returns string |
||
| 162 | */ |
||
| 163 | public function test_for_shortcode( $content ) { |
||
| 164 | $this->_found_shortcode = has_shortcode( $content, self::SHORTCODE ); |
||
| 165 | |||
| 166 | return $content; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Returns the HTML for the related posts section. |
||
| 171 | * |
||
| 172 | * @uses esc_html__, apply_filters |
||
| 173 | * @returns string |
||
| 174 | */ |
||
| 175 | public function get_target_html() { |
||
| 176 | $options = $this->get_options(); |
||
| 177 | |||
| 178 | if ( $options['show_headline'] ) { |
||
| 179 | $headline = sprintf( |
||
| 180 | '<h3 class="jp-relatedposts-headline"><em>%s</em></h3>', |
||
| 181 | esc_html__( 'Related', 'jetpack' ) |
||
| 182 | ); |
||
| 183 | } else { |
||
| 184 | $headline = ''; |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Filter the Related Posts headline. |
||
| 189 | * |
||
| 190 | * @module related-posts |
||
| 191 | * |
||
| 192 | * @since 3.0.0 |
||
| 193 | * |
||
| 194 | * @param string $headline Related Posts heading. |
||
| 195 | */ |
||
| 196 | $headline = apply_filters( 'jetpack_relatedposts_filter_headline', $headline ); |
||
| 197 | |||
| 198 | if ( $this->_previous_post_id ) { |
||
| 199 | $exclude = "data-exclude='{$this->_previous_post_id}'"; |
||
| 200 | } else { |
||
| 201 | $exclude = ""; |
||
| 202 | } |
||
| 203 | |||
| 204 | return <<<EOT |
||
| 205 | <div id='jp-relatedposts' class='jp-relatedposts' $exclude> |
||
| 206 | $headline |
||
| 207 | </div> |
||
| 208 | EOT; |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Returns the HTML for the related posts section if it's running in the loop or other instances where we don't support related posts. |
||
| 213 | * |
||
| 214 | * @returns string |
||
| 215 | */ |
||
| 216 | public function get_target_html_unsupported() { |
||
| 217 | return "\n\n<!-- Jetpack Related Posts is not supported in this context. -->\n\n"; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * ======================== |
||
| 222 | * PUBLIC UTILITY FUNCTIONS |
||
| 223 | * ======================== |
||
| 224 | */ |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Gets options set for Jetpack_RelatedPosts and merge with defaults. |
||
| 228 | * |
||
| 229 | * @uses Jetpack_Options::get_option, apply_filters |
||
| 230 | * @return array |
||
| 231 | */ |
||
| 232 | public function get_options() { |
||
| 233 | if ( null === $this->_options ) { |
||
| 234 | $this->_options = Jetpack_Options::get_option( 'relatedposts' ); |
||
| 235 | if ( ! is_array( $this->_options ) ) |
||
| 236 | $this->_options = array(); |
||
| 237 | if ( ! isset( $this->_options['enabled'] ) ) |
||
| 238 | $this->_options['enabled'] = true; |
||
| 239 | if ( ! isset( $this->_options['show_headline'] ) ) |
||
| 240 | $this->_options['show_headline'] = true; |
||
| 241 | if ( ! isset( $this->_options['show_thumbnails'] ) ) |
||
| 242 | $this->_options['show_thumbnails'] = false; |
||
| 243 | if ( empty( $this->_options['size'] ) || (int)$this->_options['size'] < 1 ) |
||
| 244 | $this->_options['size'] = 3; |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Filter Related Posts basic options. |
||
| 248 | * |
||
| 249 | * @module related-posts |
||
| 250 | * |
||
| 251 | * @since 2.8.0 |
||
| 252 | * |
||
| 253 | * @param array $this->_options Array of basic Related Posts options. |
||
| 254 | */ |
||
| 255 | $this->_options = apply_filters( 'jetpack_relatedposts_filter_options', $this->_options ); |
||
| 256 | } |
||
| 257 | |||
| 258 | return $this->_options; |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Parses input and returnes normalized options array. |
||
| 263 | * |
||
| 264 | * @param array $input |
||
| 265 | * @uses self::get_options |
||
| 266 | * @return array |
||
| 267 | */ |
||
| 268 | public function parse_options( $input ) { |
||
| 269 | $current = $this->get_options(); |
||
| 270 | |||
| 271 | if ( !is_array( $input ) ) |
||
| 272 | $input = array(); |
||
| 273 | |||
| 274 | if ( isset( $input['enabled'] ) && '1' == $input['enabled'] ) { |
||
| 275 | $current['enabled'] = true; |
||
| 276 | $current['show_headline'] = ( isset( $input['show_headline'] ) && '1' == $input['show_headline'] ); |
||
| 277 | $current['show_thumbnails'] = ( isset( $input['show_thumbnails'] ) && '1' == $input['show_thumbnails'] ); |
||
| 278 | } else { |
||
| 279 | $current['enabled'] = false; |
||
| 280 | } |
||
| 281 | |||
| 282 | if ( isset( $input['size'] ) && (int)$input['size'] > 0 ) |
||
| 283 | $current['size'] = (int)$input['size']; |
||
| 284 | else |
||
| 285 | $current['size'] = null; |
||
| 286 | |||
| 287 | return $current; |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * HTML for admin settings page. |
||
| 292 | * |
||
| 293 | * @uses self::get_options, checked, esc_html__ |
||
| 294 | * @returns null |
||
| 295 | */ |
||
| 296 | public function print_setting_html() { |
||
| 297 | $options = $this->get_options(); |
||
| 298 | |||
| 299 | $ui_settings_template = <<<EOT |
||
| 300 | <ul id="settings-reading-relatedposts-customize"> |
||
| 301 | <li> |
||
| 302 | <label><input name="jetpack_relatedposts[show_headline]" type="checkbox" value="1" %s /> %s</label> |
||
| 303 | </li> |
||
| 304 | <li> |
||
| 305 | <label><input name="jetpack_relatedposts[show_thumbnails]" type="checkbox" value="1" %s /> %s</label> |
||
| 306 | </li> |
||
| 307 | </ul> |
||
| 308 | <div id='settings-reading-relatedposts-preview'> |
||
| 309 | %s |
||
| 310 | <div id="jp-relatedposts" class="jp-relatedposts"></div> |
||
| 311 | </div> |
||
| 312 | EOT; |
||
| 313 | $ui_settings = sprintf( |
||
| 314 | $ui_settings_template, |
||
| 315 | checked( $options['show_headline'], true, false ), |
||
| 316 | esc_html__( 'Show a "Related" header to more clearly separate the related section from posts', 'jetpack' ), |
||
| 317 | checked( $options['show_thumbnails'], true, false ), |
||
| 318 | esc_html__( 'Use a large and visually striking layout', 'jetpack' ), |
||
| 319 | esc_html__( 'Preview:', 'jetpack' ) |
||
| 320 | ); |
||
| 321 | |||
| 322 | if ( !$this->_allow_feature_toggle() ) { |
||
| 323 | $template = <<<EOT |
||
| 324 | <input type="hidden" name="jetpack_relatedposts[enabled]" value="1" /> |
||
| 325 | %s |
||
| 326 | EOT; |
||
| 327 | printf( |
||
| 328 | $template, |
||
| 329 | $ui_settings |
||
| 330 | ); |
||
| 331 | } else { |
||
| 332 | $template = <<<EOT |
||
| 333 | <ul id="settings-reading-relatedposts"> |
||
| 334 | <li> |
||
| 335 | <label><input type="radio" name="jetpack_relatedposts[enabled]" value="0" class="tog" %s /> %s</label> |
||
| 336 | </li> |
||
| 337 | <li> |
||
| 338 | <label><input type="radio" name="jetpack_relatedposts[enabled]" value="1" class="tog" %s /> %s</label> |
||
| 339 | %s |
||
| 340 | </li> |
||
| 341 | </ul> |
||
| 342 | EOT; |
||
| 343 | printf( |
||
| 344 | $template, |
||
| 345 | checked( $options['enabled'], false, false ), |
||
| 346 | esc_html__( 'Hide related content after posts', 'jetpack' ), |
||
| 347 | checked( $options['enabled'], true, false ), |
||
| 348 | esc_html__( 'Show related content after posts', 'jetpack' ), |
||
| 349 | $ui_settings |
||
| 350 | ); |
||
| 351 | } |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Head JS/CSS for admin settings page. |
||
| 356 | * |
||
| 357 | * @uses esc_html__ |
||
| 358 | * @returns null |
||
| 359 | */ |
||
| 360 | public function print_setting_head() { |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Gets an array of related posts that match the given post_id. |
||
| 501 | * |
||
| 502 | * @param int $post_id |
||
| 503 | * @param array $args - params to use when building ElasticSearch filters to narrow down the search domain. |
||
| 504 | * @uses self::get_options, get_post_type, wp_parse_args, apply_filters |
||
| 505 | * @return array |
||
| 506 | */ |
||
| 507 | public function get_for_post_id( $post_id, array $args ) { |
||
| 508 | $options = $this->get_options(); |
||
| 509 | |||
| 510 | if ( ! empty( $args['size'] ) ) |
||
| 563 | |||
| 564 | /** |
||
| 565 | * ========================= |
||
| 566 | * PRIVATE UTILITY FUNCTIONS |
||
| 567 | * ========================= |
||
| 568 | */ |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Creates an array of ElasticSearch filters based on the post_id and args. |
||
| 572 | * |
||
| 573 | * @param int $post_id |
||
| 574 | * @param array $args |
||
| 575 | * @uses apply_filters, get_post_types, get_post_format_strings |
||
| 576 | * @return array |
||
| 577 | */ |
||
| 578 | protected function _get_es_filters_from_args( $post_id, array $args ) { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Takes a range and coalesces it into a month interval bracketed by a time as determined by the blog_id to enhance caching. |
||
| 704 | * |
||
| 705 | * @param array $date_range |
||
| 706 | * @return array |
||
| 707 | */ |
||
| 708 | protected function _get_coalesced_range( array $date_range ) { |
||
| 727 | |||
| 728 | /** |
||
| 729 | * Generate and output ajax response for related posts API call. |
||
| 730 | * NOTE: Calls exit() to end all further processing after payload has been outputed. |
||
| 731 | * |
||
| 732 | * @param array $excludes array of post_ids to exclude |
||
| 733 | * @uses send_nosniff_header, self::get_for_post_id, get_the_ID |
||
| 734 | * @return null |
||
| 735 | */ |
||
| 736 | protected function _action_frontend_init_ajax( array $excludes ) { |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Returns a UTF-8 encoded array of post information for the given post_id |
||
| 767 | * |
||
| 768 | * @param int $post_id |
||
| 769 | * @param int $position |
||
| 770 | * @param int $origin The post id that this is related to |
||
| 771 | * @uses get_post, get_permalink, remove_query_arg, get_post_format, apply_filters |
||
| 772 | * @return array |
||
| 773 | */ |
||
| 774 | protected function _get_related_post_data_for_post( $post_id, $position, $origin ) { |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Returns either the title or a small excerpt to use as title for post. |
||
| 832 | * |
||
| 833 | * @param string $post_title |
||
| 834 | * @param string $post_content |
||
| 835 | * @uses strip_shortcodes, wp_trim_words, __ |
||
| 836 | * @return string |
||
| 837 | */ |
||
| 838 | protected function _get_title( $post_title, $post_content ) { |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Returns a plain text post excerpt for title attribute of links. |
||
| 853 | * |
||
| 854 | * @param string $post_excerpt |
||
| 855 | * @param string $post_content |
||
| 856 | * @uses strip_shortcodes, wp_strip_all_tags, wp_trim_words |
||
| 857 | * @return string |
||
| 858 | */ |
||
| 859 | protected function _get_excerpt( $post_excerpt, $post_content ) { |
||
| 867 | |||
| 868 | /** |
||
| 869 | * Generates the thumbnail image to be used for the post. Uses the |
||
| 870 | * image as returned by Jetpack_PostImages::get_image() |
||
| 871 | * |
||
| 872 | * @param int $post_id |
||
| 873 | * @uses self::get_options, apply_filters, Jetpack_PostImages::get_image, Jetpack_PostImages::fit_image_url |
||
| 874 | * @return string |
||
| 875 | */ |
||
| 876 | protected function _generate_related_post_image_params( $post_id ) { |
||
| 939 | |||
| 940 | /** |
||
| 941 | * Returns the string UTF-8 encoded |
||
| 942 | * |
||
| 943 | * @param string $text |
||
| 944 | * @return string |
||
| 945 | */ |
||
| 946 | protected function _to_utf8( $text ) { |
||
| 953 | |||
| 954 | /** |
||
| 955 | * ============================================= |
||
| 956 | * PROTECTED UTILITY FUNCTIONS EXTENDED BY WPCOM |
||
| 957 | * ============================================= |
||
| 958 | */ |
||
| 959 | |||
| 960 | /** |
||
| 961 | * Workhorse method to return array of related posts matched by ElasticSearch. |
||
| 962 | * |
||
| 963 | * @param int $post_id |
||
| 964 | * @param int $size |
||
| 965 | * @param array $filters |
||
| 966 | * @uses wp_remote_post, is_wp_error, get_option, wp_remote_retrieve_body, get_post, add_query_arg, remove_query_arg, get_permalink, get_post_format, apply_filters |
||
| 967 | * @return array |
||
| 968 | */ |
||
| 969 | protected function _get_related_posts( $post_id, $size, array $filters ) { |
||
| 996 | |||
| 997 | /** |
||
| 998 | * Get array of related posts matched by ElasticSearch. |
||
| 999 | * |
||
| 1000 | * @param int $post_id |
||
| 1001 | * @param int $size |
||
| 1002 | * @param array $filters |
||
| 1003 | * @uses wp_remote_post, is_wp_error, wp_remote_retrieve_body, get_post_meta, update_post_meta |
||
| 1004 | * @return array |
||
| 1005 | */ |
||
| 1006 | protected function _get_related_post_ids( $post_id, $size, array $filters ) { |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Filter out any hits that are not public anymore. |
||
| 1082 | * |
||
| 1083 | * @param array $related_posts |
||
| 1084 | * @uses get_post_stati, get_post_status |
||
| 1085 | * @return array |
||
| 1086 | */ |
||
| 1087 | protected function _filter_non_public_posts( array $related_posts ) { |
||
| 1098 | |||
| 1099 | /** |
||
| 1100 | * Generates a context for the related content (second line in related post output). |
||
| 1101 | * Order of importance: |
||
| 1102 | * - First category (Not 'Uncategorized') |
||
| 1103 | * - First post tag |
||
| 1104 | * - Number of comments |
||
| 1105 | * |
||
| 1106 | * @param int $post_id |
||
| 1107 | * @uses get_the_category, get_the_terms, get_comments_number, number_format_i18n, __, _n |
||
| 1108 | * @return string |
||
| 1109 | */ |
||
| 1110 | protected function _generate_related_post_context( $post_id ) { |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Logs clicks for clickthrough analysis and related result tuning. |
||
| 1170 | * |
||
| 1171 | * @return null |
||
| 1172 | */ |
||
| 1173 | protected function _log_click( $post_id, $to_post_id, $link_position ) { |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Determines if the current post is able to use related posts. |
||
| 1179 | * |
||
| 1180 | * @uses self::get_options, is_admin, is_single, apply_filters |
||
| 1181 | * @return bool |
||
| 1182 | */ |
||
| 1183 | protected function _enabled_for_request() { |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Adds filters and enqueues assets. |
||
| 1217 | * |
||
| 1218 | * @uses self::_enqueue_assets, self::_setup_shortcode, add_filter |
||
| 1219 | * @return null |
||
| 1220 | */ |
||
| 1221 | protected function _action_frontend_init_page() { |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Enqueues assets needed to do async loading of related posts. |
||
| 1230 | * |
||
| 1231 | * @uses wp_enqueue_script, wp_enqueue_style, plugins_url |
||
| 1232 | * @return null |
||
| 1233 | */ |
||
| 1234 | protected function _enqueue_assets( $script, $style ) { |
||
| 1257 | |||
| 1258 | /** |
||
| 1259 | * Sets up the shortcode processing. |
||
| 1260 | * |
||
| 1261 | * @uses add_filter, add_shortcode |
||
| 1262 | * @return null |
||
| 1263 | */ |
||
| 1264 | protected function _setup_shortcode() { |
||
| 1269 | |||
| 1270 | protected function _allow_feature_toggle() { |
||
| 1285 | } |
||
| 1286 | |||
| 1341 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.