Constants

VERSION

VERSION

Properties

$_query_name

$_query_name

$_blog_id

$_blog_id

$_options

$_options

$_allow_feature_toggle

$_allow_feature_toggle

$_blog_charset

$_blog_charset

$_convert_charset

$_convert_charset

Methods

set_query_name()

set_query_name(string $name) : \Jetpack_RelatedPosts_Raw

Allows callers of this class to tag each query with a unique name for tracking purposes.

Parameters

string $name

Returns

\Jetpack_RelatedPosts_Raw

action_admin_init()

action_admin_init() : null

Add a checkbox field to Settings > Reading for enabling related posts.

Returns

null

action_frontend_init()

action_frontend_init()

Load related posts assets if it's a elegiable frontend page or execute search and return JSON if it's an endpoint request.

get_options()

get_options() : array

Gets options set for Jetpack_RelatedPosts and merge with defaults.

Returns

array

init()

init() : \Jetpack_RelatedPosts

Creates and returns a static instance of Jetpack_RelatedPosts.

Returns

\Jetpack_RelatedPosts

init_raw()

init_raw() : \Jetpack_RelatedPosts

Creates and returns a static instance of Jetpack_RelatedPosts_Raw.

Returns

\Jetpack_RelatedPosts

__construct()

__construct(int $blog_id) : null

Constructor for Jetpack_RelatedPosts.

Parameters

int $blog_id

Returns

null

filter_add_target_to_dom()

filter_add_target_to_dom(string $content)

Adds a target to the post content to load related posts into.

Parameters

string $content

parse_options()

parse_options(array $input) : array

Parses input and returnes normalized options array.

Parameters

array $input

Returns

array

print_setting_html()

print_setting_html()

HTML for admin settings page.

print_setting_head()

print_setting_head()

Head JS/CSS for admin settings page.

get_for_post_id()

get_for_post_id(int $post_id, array $args) : array

Gets an array of related posts that match the given post_id.

Parameters

int $post_id
array $args
  • params to use when building ElasticSearch filters to narrow down the search domain.

Returns

array

_get_related_posts()

_get_related_posts(int $blog_id, int $post_id, int $size, array $filters) : array

Workhorse method to return array of related posts matched by ElasticSearch.

Parameters

int $blog_id
int $post_id
int $size
array $filters

Returns

array

_get_es_filters_from_args()

_get_es_filters_from_args(int $post_id, array $args) : array

Creates an array of ElasticSearch filters based on the post_id and args.

Parameters

int $post_id
array $args

Returns

array

_get_coalesced_range()

_get_coalesced_range(array $date_range) : array

Takes a range and coalesces it into a month interval bracketed by a time as determined by the blog_id to enhance caching.

Parameters

array $date_range

Returns

array

_action_frontend_init_ajax()

_action_frontend_init_ajax(array $excludes) : null

Generate and output ajax response for related posts API call.

NOTE: Calls exit() to end all further processing after payload has been outputed.

Parameters

array $excludes

array of post_ids to exclude

Returns

null

_action_frontend_redirect()

_action_frontend_redirect(int $to_post_id, int $link_position) : null

Blog reader has clicked on a related link, log this action for future relevance analysis and redirect the user to their post.

NOTE: Calls exit() to end all further processing after redirect has been outputed.

Parameters

int $to_post_id
int $link_position

Returns

null

_get_related_post_data_for_post()

_get_related_post_data_for_post(int $blog_id, int $post_id, int $position) : array

Returns a UTF-8 encoded array of post information for the given post_id

Parameters

int $blog_id
int $post_id
int $position

Returns

array

_get_title()

_get_title(string $post_title, string $post_content) : string

Returns either the title or a small excerpt to use as title for post.

Parameters

string $post_title
string $post_content

Returns

string

_get_excerpt()

_get_excerpt(string $post_excerpt, string $post_content) : string

Returns a plain text post excerpt for title attribute of links.

Parameters

string $post_excerpt
string $post_content

Returns

string

_generate_related_post_image_params()

_generate_related_post_image_params(int $blog_id, int $post_id) : string

Generates the thumbnail image to be used for the post. Uses the image as returned by Jetpack_PostImages::get_image()

Parameters

int $blog_id
int $post_id

Returns

string

_to_utf8()

_to_utf8(string $text) : string

Returns the string UTF-8 encoded

Parameters

string $text

Returns

string

_get_related_post_ids()

_get_related_post_ids(int $blog_id, int $post_id, int $size, array $filters) : array

Get array of related posts matched by ElasticSearch.

Parameters

int $blog_id
int $post_id
int $size
array $filters

Returns

array

_generate_related_post_context()

_generate_related_post_context(int $blog_id, int $post_id) : string

Generates a context for the related content (second line in related post output).

Order of importance:

  • First category (Not 'Uncategorized')
  • First post tag
  • Number of comments

Parameters

int $blog_id
int $post_id

Returns

string

_log_click()

_log_click( $post_id,  $to_post_id,  $link_position) : null

Logs clicks for clickthrough analysis and related result tuning.

Parameters

$post_id
$to_post_id
$link_position

Returns

null

_show_config_in_admin()

_show_config_in_admin(int $blog_id) : bool

Determines if we should show config in admin dashboard to turn on related posts.

Parameters

int $blog_id

Returns

bool

_enabled_for_request()

_enabled_for_request(int $blog_id) : bool

Determines if the current post is able to use related posts.

Parameters

int $blog_id

Returns

bool

_action_frontend_init_page()

_action_frontend_init_page() : null

Adds filters and enqueues assets.

Returns

null

_enqueue_assets()

_enqueue_assets( $script,  $style) : null

Enqueues assets needed to do async loading of related posts.

Parameters

$script
$style

Returns

null

_allow_feature_toggle()

_allow_feature_toggle()