I found another piece of code on the internet which I have modified to work.
add_filter('the_comments', 'edit_comments_filter_comments');
function edit_comments_filter_comments($comments){
global $pagenow;
$currentuserid = get_current_user_id();
if($pagenow == 'edit-comments.php' && !current_user_can('edit_others_posts')){
foreach($comments as $i => $comment){
$the_post = get_post($comment->comment_post_ID);
if($comment->user_id != $currentuserid && $the_post->post_author != $currentuserid)
unset($comments[$i]);
}
}
return $comments;
}
As I understand it, this takes the comments pulled in by the query and checks them before displaying them.
Related Posts:
- show number of open comments on custom dashboard
- Capability for allowing user to post own comments without moderation
- Why do comment moderators need to have all create/edit/delete toboth posts and pages?
- Users with custom roles can’t read each other’s comments
- edit_comment capability for subscriber
- Allow contributors to moderate comments comments on posts they write
- “Discussion” checkboxes unchecked by default on pages? [duplicate]
- Admin Dashboard – Recent Comments source
- Allow comments only for custom post type
- where can I find the missing comments in my wordpress dashboard?
- Why the capability ‘activate_plugins’ is needed to allow a role to see all posts/pages/comments?
- Admin – Dashboard – Unset recent comments
- Embed a page within WordPress dashboard?
- Disable comments on all posts/pages
- Stop WordPress redirecting comment-page-1 to the post page?
- Importing old Disqus comments into WordPress
- How to add a class to the comment submit button?
- Would switching to InnoDB from MyISAM improve performance of comments table?
- Linking to Page Showing Only Comments Without Parent Post
- Post Comments using WP REST API v2 in WordPress
- Show content only if member left a comment
- Using filter to add additional fields to comment_form()
- Disable wordpress comments API
- List Recent Comments from Across a Multi-site Network
- Comments waiting but no comments found
- Programmatically block commenting by restricting view of comment form
- Hooking into add_submenu_page
- Comments screen in backend, how to disable Quick Edit | Edit | History | Spam | for non admins
- Plugin from WordPress.com for comment notification…available? [closed]
- How to add text to comment form #content textarea?
- Get most active users sort by comment count
- Passing arguments to wp_list_comments callback function
- What are the additional fields in wp_comments used for?
- comments_template not working correcly in custom template files
- Why are my comments closed?
- How to change style of Disqus comment count on main page
- Adding another arg to comments_popup_link
- Exclude Duplicate Posts in this SELECT Query
- List User Comments on User Profile BuddyPress [closed]
- Filter custom comment type from Manage Comments & Dash Widgets
- How to allow more HTML tags in comment for a certain comment_type
- How to deal with spam comments and distinguish them from non-spam comments?
- How to get all comment authors of a single post?
- Get return value of wp_insert_comment (comment ID)
- comment_reply_link not work with me
- have_comments() does not work
- How to use the ‘comments_number’ filter?
- How to allow duplicate comments AND without comment text
- Remove the deleted user comment
- Show Social Sharing Buttons And Facebook Comments In Lightbox Modal Dialog (Image Overlay)?
- Cannot post comments if I don’t post a website?
- How Do I Allow Comment Moderation for Other User’s Posts?
- How to display custom comment fields onto any page
- Make every comment go to the spam folder
- Limit number of comments from get_comments()
- Correct way to retrieve comment attributes for desired results
- The comment could not be saved. No comment_ID on comments
- how to remove WordPress default comment system
- ‘comment_post’ hook doesn’t seem to work? [closed]
- count number of all comments by a user on different (non-repeated) posts
- Facebook comments widget – App ID
- Comments screen in backend, how to disable visual editor when replying to a comment
- Genesis Child Theme Modifying Comments display
- Adding a comment link to the top of every post
- WordPress comment reply link image
- Comment Pagination
- See some statistics about the comments
- Comment form in wordpress theme returns a javascript alert
- How to output comments in Descending order by date using wp_list_comments?
- Embedding local video in WordPress comments
- How to add inside WordPress comments loop?
- Difference between date and date_gmt
- How do I edit Comments.php so I can add Schema markup to comment output?
- Check if comment author has url
- Migrate comments and likes wordpress.com to selfhosted site
- How to pass settings to comment_form() if theme only uses comments_template()?
- How to enable truly anonymous posting in bbPress forums? [closed]
- Change author, disable comments, enable trackbacks for all items in library
- Prevent author from editing comments from others in their post
- Display Most Recent Three Comments Per Post
- reply to comment excerpt instead of author in comment title
- Front End User(bloger) turn on and off his comments
- Does not show comment list
- Can’t post comment to blog in wp-multisite
- Display Comment Form on dedicated Page for each post
- Change comment author after new comment posted
- Show ‘add comment’ link for status updates in Twenty Thirteen
- Pull & display new comments without refreshing the page
- How to display comments by logged in user and responses?
- Identify and display the fact that user is admin next to username in comment section
- Display facebook comments made on site
- Disable Link to Post from Showing Up in Post’s Comments?
- different levels of nested comments per page
- Image Upload Form is Disabling Comment Addition
- db query for retrieving comments without any reply
- Clicking Comment “Reply” Button only replies to first comment
- How stop the process of submitting a comment if a fields are empty?
- Page to view single comment and all replies
- How can I add a check and not send an auto-reply to certain comments if the user fills in a custom field?
- Show success message on comment submit when email and name is not required field