Lazy Load for Comments offers a set of hooks that let you extend the plugin's functionality without modifying its core files. This ensures your custom code remains intact even after a plugin update. There are two primary types of hooks: Actions and Filters.
To use either type of hook, you must first create a callback function — a custom function that contains the code you want to run. You then register this callback with a specific Lazy Load for Comments hook, telling the plugin exactly when and where to execute your code.
All hooks should be added to your theme's functions.php file or to a custom plugin.
This action fires once the plugin is fully loaded and all of its classes are ready. Addons and extensions should hook into this action so they only run when Lazy Load for Comments is active.
add_action( 'lazy_load_for_comments_init', 'my_addon_init' );function my_addon_init( $core ) { // Lazy Load for Comments is loaded and ready. // Safe to initialize your addon here.}
add_action( 'lazy_load_for_comments_activated', 'my_addon_on_activate' );function my_addon_on_activate() { // Runs when Lazy Load for Comments is activated.}
add_action( 'lazy_load_for_comments_deactivated', 'my_addon_on_deactivate' );function my_addon_on_deactivate() { // Runs when Lazy Load for Comments is deactivated.}
This filter decides whether the comments should be lazy loaded for the current request. The plugin already checks the load method, whether the page is a single post, the minimum comment count, and the bot check — this filter lets you add your own conditions on top.
defaults: An associative array of setting keys and their default values (load_method, button_text, button_style, button_class, show_loader, minimum_count, disable_for_bots).
This filter gives fine-grained control over whether the current user can manage the plugin and use its REST API. It runs after the capability check, so you can override the result for specific users.
add_filter( 'lazy_load_for_comments_has_access', 'my_restrict_access' );function my_restrict_access( $has_access ) { // Only allow user ID 1 to manage the plugin. return get_current_user_id() === 1;}
Need help?
If you think something is missing or need help extending Lazy Load for Comments, feel free to contact us.
Developer Docs
Lazy Load for Comments offers a set of hooks that let you extend the plugin's functionality without modifying its core files. This ensures your custom code remains intact even after a plugin update. There are two primary types of hooks: Actions and Filters.
To use either type of hook, you must first create a callback function — a custom function that contains the code you want to run. You then register this callback with a specific Lazy Load for Comments hook, telling the plugin exactly when and where to execute your code.
All hooks should be added to your theme's
functions.phpfile or to a custom plugin.Actions
Actions let you run a custom function at a specific, predefined point in the plugin's execution.
1.
lazy_load_for_comments_initThis action fires once the plugin is fully loaded and all of its classes are ready. Addons and extensions should hook into this action so they only run when Lazy Load for Comments is active.
Parameters
core: The main plugin core instance (DuckDev\LazyComments\Core).Example Usage
2.
lazy_load_for_comments_activatedThis action fires right after the plugin is activated. Use it to run one-time setup tasks for your addon.
Example Usage
3.
lazy_load_for_comments_deactivatedThis action fires right after the plugin is deactivated. Use it to run cleanup tasks.
Example Usage
Filters
Filters let you modify data that is being processed by the plugin. A filter callback receives a value, modifies it, and returns the modified value.
1.
lazy_load_for_comments_can_lazy_loadThis filter decides whether the comments should be lazy loaded for the current request. The plugin already checks the load method, whether the page is a single post, the minimum comment count, and the bot check — this filter lets you add your own conditions on top.
Parameters
can: A boolean. Returntrueto lazy load the comments, orfalseto load them normally.Example Usage
2.
lazy_load_for_comments_rendered_htmlThis filter modifies the comments HTML returned by the REST API before it is sent to the browser and injected into the page.
Parameters
html: The rendered comments HTML.post: TheWP_Postobject the comments belong to.Example Usage
3.
lazy_load_for_comments_default_settingsThis filter modifies the plugin's default settings values. Addons can use it to change the fallback value of an existing setting.
Parameters
defaults: An associative array of setting keys and their default values (load_method,button_text,button_style,button_class,show_loader,minimum_count,disable_for_bots).Example Usage
4.
lazy_load_for_comments_capabilityThis filter changes the user capability required to access and manage the plugin's settings page. The default capability is
manage_options.Parameters
capability: The capability string.Example Usage
5.
lazy_load_for_comments_has_accessThis filter gives fine-grained control over whether the current user can manage the plugin and use its REST API. It runs after the capability check, so you can override the result for specific users.
Parameters
has_access: A boolean. Returntrueto grant access,falseto deny it.Example Usage
Need help?
If you think something is missing or need help extending Lazy Load for Comments, feel free to contact us.