Hook & Filter Reference
Hook & Filter Reference
The Private Comments plugin is designed to be extensible. Developers can use the following filters to modify the privacy logic, allow specific user roles to bypass restrictions, or conditionally enable/disable private comments based on custom criteria.
Custom Filters
The plugin provides custom filters to hook into the comment filtering logic.
wp_private_comments_bypass
This filter allows you to programmatically determine if the comment restriction should be bypassed for a specific request or user.
- Type: Filter
- Input:
bool(Default:false) - Output:
bool - Example:
// Allow editors to see all private comments add_filter('wp_private_comments_bypass', function($bypass) { if (current_user_can('editor')) { return true; } return $bypass; });
wp_private_comments_enabled
Use this filter to toggle the entire plugin functionality on or off based on specific conditions (e.g., only enable private comments on specific post types).
- Type: Filter
- Input:
bool(Default:true) - Output:
bool - Example:
// Disable private comments on 'product' post type add_filter('wp_private_comments_enabled', function($is_enabled) { if (is_singular('product')) { return false; } return $is_enabled; });
Core WordPress Hooks
The plugin interacts with WordPress core filters to modify database queries and UI components. While these are internal, understanding them is useful for debugging how the plugin restricts data.
comments_clauses
The plugin hooks into this core filter to modify the WHERE clause of the comment query.
- Role: Internal/Critical.
- Description: It appends logic to the SQL query to ensure that for non-administrators and non-post authors, the query only returns comments where the
user_idmatches the current logged-in user. - Note: If you are running custom
WP_Comment_Queryinstances, ensure you are not passing'suppress_filters' => true, or the privacy logic will be bypassed.
wp_list_comments_args
The plugin hooks into this to ensure the comment count UI matches the filtered results.
- Role: UI Consistency.
- Description: Adjusts the arguments passed to the comment list to prevent "ghost" pagination or incorrect comment counts from appearing in the template.
Capability Requirements
By default, the plugin uses the manage_options capability to define an "Administrator" who can see all comments. To change which capability grants "Super User" access to comments, use the following filter:
wp_private_comments_admin_capability
- Type: Filter
- Input:
string(Default:'manage_options') - Output:
string - Example:
// Allow users with 'moderate_comments' cap to see all private comments add_filter('wp_private_comments_admin_capability', function($cap) { return 'moderate_comments'; });