By using the ‘pre_get_comments’ action, found in wp-includes/comment.php
:
function restrict_visible_comments( $comments_query ) {
if ( !is_singular() )
return;
if ( current_user_can( 'moderate_comments' ) )
return; // moderators can see all comments
if ( get_current_user_id() == get_queried_object()->post_author )
return; // the author of the post can see all comments
$comments_query->query_vars['user_id'] = get_current_user_id();
}
if ( !is_admin() )
add_action( 'pre_get_comments', 'restrict_visible_comments' );
Note that the above won’t display comments left by non-registered users.
Update: Nevermind, this won’t work because get_comments() isn’t used consistently in comments_template():
http://core.trac.wordpress.org/browser/tags/3.1.3/wp-includes/comment-template.php#L882
Related Posts:
- How do I comment out a block of tags in XML?
- Commenting in user profile page?
- How to enable comments for pending and draft posts?
- A plugin where users can comment with Facebook or Twitter or OpenID [closed]
- What’s the easiest way to close comments on media/attachments?
- Using Disqus, how to stop storing comments in wp database?
- Multiple Comment Moderators and Notifications
- function to remove ‘comments and trackbacks are closed’
- Custom Field Added In Comment Form Not Showing In Edit
- Add a drop down list to comment form?
- Get threaded comments number
- SQL query to delete comments older than 90 days?
- How to refresh the page when an admin trashes a comment from Comments in the admin site?
- Let user edit his own comment
- Get the number of comments awaiting moderation
- Changing position of cancel_comment_reply_link and other elements of comment form
- What does the “$depth” parameter in the Walker_Comment stand for?
- Send Notifications to All Admins
- Why do comment moderators need to have all create/edit/delete toboth posts and pages?
- Comment pagination – How to show determined number of comments on the first page?
- How to allow a particular role like Contributor be able to only view pending comments and approve them?
- Disable comments
- Sort comments by karma
- Bots posting comments on pages
- default callback function in wp_list_comments
- Why are authors allowed to approve comments on their posts? How to revoke privilege?
- Comment form connection to Gravity Forms
- Add classname comment template from functions.php
- Comments deactivated
- List user comments in author page
- Filter custom posts with / without comments
- Create comments.php form of custom HTML code
- Display comments on homepage of twenty seventeen theme
- How to dynamic Heart Like in WordPress?
- Disqus comments and pingback script – how to change the order?
- To whom do emails get sent via the WordPress comments form?
- Comment Moderation and CDN Caching
- Comments feed – Undefined named entity: ndash
- Assign author to comment from post edit page
- The “\” is missing when comments is updated
- warnCommentChanges always being triggered on update
- how get comments only on post of current logged in user?
- How to get comment id in callback function?
- Posting comment returns 404
- How-To and Troubleshooting Canonical Links for Paginated Comments
- Get declared variable in single.php to work in comments.php without re-declaring it [closed]
- What is causing wp-comments-post.php to redirect to the browser’s IP address?
- Extra Title field for Comments
- Comments offset
- How to hide trackbacks on wp-admin/edit-comments.php
- Using a static callback on wp_insert_comment
- Show comment pop up links as text only
- WordPress Recent Comments Widget exclude own comments
- How to prevent multiple comments
- Displaying comments on pages distinguished by GET IDs
- How to get comment images stored as serialized comment meta
- Hide comments on specific pages, not just disable future comments
- Is there a hook to update / replace values in the “Enable threaded (nested) comments x levels deep” drop down?
- Add comment_meta to wp_comment_reply
- How to change comment texts that has a specific comment_ID – Hook into comment
- How do comments work?
- Can’t reply to comments [closed]
- counting trackbacks, pingbacks and comments of a post
- Adding comments section to website integrated WordPress instance
- ask and edit an extra comment field
- Modify links in user comments
- How indicate when a functions was upgraded in relationship to the entire program [closed]
- Empty comments field or
- What templates/funtions needed in custom theme to allow comments the new 3.0 way
- Default Gravatar not showing for pings
- How to filter comments by comment_meta
- Prevent users to delete comments from trash
- How can I hide comment of the authors from their published posts?
- How to customize ‘children comments’ in WordPress?
- How to display replies to his comments in user profile of current user
- Top rated posts Average rating issue
- stop url changing when user comments
- Keep comment author’s name on their comment even when their account is deleted
- Badges for Guests based on their comment counts [closed]
- How to add a class to comment submit button?
- WordPress Commenting System User access and Security
- Comments.php is not getting called on main blog page
- Allowing comments on author pages
- How can I see whether a commenter has subscribed to be notified of replies / other comments to a post
- WordPress Comments – Only show part of user name
- Where is the Leave a Comment link set
- Broken comments section – WordPress 2014 Theme
- Auto disable comments with custom field
- Need an advice about comments
- I want to fill the comment with the comment count?
- delete user not working
- By Default, Turn Comments Off for Pages & Leave Comments On for Posts
- same comment list for two posts
- Replace do_action() with a normal submit form in comments.php
- How to remove or customize “Comment” in comments form?
- edit-comments.php in Admin – how to change ‘Comments’ title?
- Comments on pages not appearing, even though I enabled them
- check if a comment was made by a registered user
- Stop future commenting on specific post
- comment_approved custom value