Make WordPress Core


Ignore:
Timestamp:
10/12/2023 12:36:29 PM (12 months ago)
Author:
audrasjb
Message:

Comments: Prevent users who can not see a post from seeing comments on it.

Props peterwilsoncc, jorbin, audrasjb.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r56747 r56836  
    654654
    655655        $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
     656
     657        $edit_post_cap = $post ? 'edit_post' : 'edit_posts';
     658        if (
     659            current_user_can( $edit_post_cap, $comment->comment_post_ID ) ||
     660            (
     661                empty( $post->post_password ) &&
     662                current_user_can( 'read_post', $comment->comment_post_ID )
     663            )
     664        ) {
     665            // The user has access to the post
     666        } else {
     667            return false;
     668        }
    656669
    657670        echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
Note: See TracChangeset for help on using the changeset viewer.