Lazy_Load_Module
Lazy loads the related posts across all display methods: content filter, shortcode, widget, block and manual calls.
Replaces the related posts with a placeholder which is swapped with the rendered output, fetched via the REST API, when it is about to enter the viewport.
The display arguments are round-tripped through the placeholder as an HMAC-signed payload so that the REST endpoint renders the exact output the inline render would have produced, while rejecting arbitrary client-supplied arguments. The signature is deterministic (no nonce) so pages remain compatible with long-lived page caches; an invalid signature degrades gracefully to rendering with the site settings.
The Pro Query block (a core Query Loop variation) is intentionally out of scope: it only flags the query vars and is rendered by core with arbitrary inner blocks, so it never passes through Display::related_posts().
Namespace: WebberZone\Contextual_Related_Posts\Pro
Since: 4.3.0
Source: includes/class-lazy-load-module.php line 40
Methods
__construct()
Constructor.
Since: 4.3.0
Line: 75
public function __construct( );
shortcode_defaults()
Add the lazy_load attribute to the shortcode defaults so it can be used as a per-instance override, e.g. [crp lazy_load=“0”].
Since: 4.3.0
Line: 92
public function shortcode_defaults( $defaults ): array;
| Type | Name | Description |
|---|---|---|
array | $defaults | Default shortcode settings. |
Returns: array — Updated shortcode settings.
maybe_lazy_load()
Replace the related posts output with the lazy load placeholder.
Since: 4.3.0
Line: 108
public function maybe_lazy_load( $pre, $args, $post ): string|null;
| Type | Name | Description |
|---|---|---|
string|null | $pre | Pre-rendered output. Default null. |
array | $args | Fully parsed arguments array. |
\WP_Post | $post | Post object. |
Returns: string|null — Placeholder HTML or the original value.
should_lazy_load()
Whether the related posts should be lazy loaded.
Since: 4.3.0
Line: 128
public function should_lazy_load( $post = ..., array $args = ... ): bool;
| Type | Name | Description |
|---|---|---|
\WP_Post|null | $post | Current post object. |
array | $args | Arguments array. The lazy_load key acts as a |
Returns: bool — Whether to lazy load the related posts.
lazy_load_placeholder()
Generate the lazy load placeholder for the related posts and enqueue the loader script.
Since: 4.3.0
Line: 171
public function lazy_load_placeholder( $post = ..., array $args = ... ): string;
| Type | Name | Description |
|---|---|---|
\WP_Post|int|null | $post | Post object or ID. Defaults to the current post. |
array | $args | Arguments array used for the render. |
Returns: string — Placeholder HTML. Empty string if the placeholder cannot be
enqueue_script()
Register and enqueue the lazy load script.
Since: 4.3.0
Line: 311
public function enqueue_script( );
register_html_route()
Register the REST route that returns the rendered related posts HTML.
Since: 4.3.0
Line: 345
public function register_html_route( );
get_item_html()
Get the rendered related posts HTML for a post.
Used by the lazy load script to fetch the related posts output. Display arguments are only honoured when they carry a valid signature generated by a server-side render; otherwise the output is rendered with the site settings.
Since: 4.3.0
Line: 385
public function get_item_html( $request ): \WP_Error|\WP_REST_Response;
| Type | Name | Description |
|---|---|---|
\WP_REST_Request | $request | WP Rest request. |
Returns: \WP_Error|\WP_REST_Response — Response containing the rendered HTML.