Comment Visibility Logic
Comment Visibility Logic
The Private Comments plugin modifies the default WordPress comment retrieval process to ensure privacy. By default, WordPress displays all approved comments to all visitors. This plugin restricts that behavior based on the relationship between the viewer and the comment.
Visibility Matrix
The following table defines which users can see comments on a post:
| User Role / Status | Can See Their Own Comments | Can See Others' Comments | | :--- | :---: | :---: | | Administrator | Yes | Yes | | Post Author | Yes | Yes | | Comment Author (Logged In) | Yes | No | | Comment Author (Guest/Cookie) | Yes* | No | | General Visitor / Subscriber | No | No |
*Guest authors can view their own comments as long as their browser session/cookie persists, matching standard WordPress behavior for "awaiting moderation" or recently posted comments.
Authorized Access Levels
The logic is applied automatically across the site. Access is granted if a user meets any of the following criteria:
1. Site Administrators
Users with the manage_options capability (typically Administrators) bypass all restrictions. They can view, moderate, and reply to all comments across the entire website to ensure proper site management.
2. Post Authors
The author of a specific post or page acts as the moderator for that discussion. They have full visibility of every comment left on their content, allowing them to engage privately with their audience.
3. Comment Authors
To maintain a functional user experience, individuals can always see the comments they have submitted.
- Logged-in Users: Visibility is determined by matching the User ID of the viewer with the User ID stored in the comment record.
- Guest Commenters: Visibility is determined by matching the email address and name stored in the commenter's browser cookies with the data in the WordPress database.
Public Interface & Behavior
This plugin works "out of the box" and does not require manual configuration.
- Comment Counts: The plugin filters the comment count displayed on the frontend. A visitor who is not the post author or an administrator will only see a count that includes their own comments.
- Frontend Display: When a user views a post, the comment list is filtered before it is rendered by the theme. No additional theme modifications are required.
Example Scenario
If a post has 10 comments from 10 different people:
- The Admin sees 10 comments.
- The Post Author sees 10 comments.
- Commenter A sees 1 comment (their own).
- A New Visitor sees 0 comments.
Technical Integration
While the logic is internal, developers should note that the plugin hooks into the comments_clauses and wp_count_comments filters. This ensures that privacy is maintained not just in the visual comment list, but also in sidebar widgets and metadata.