Make WordPress Core

Changeset 56843


Ignore:
Timestamp:
10/12/2023 01:22:17 PM (3 years ago)
Author:
audrasjb
Message:

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

Props peterwilsoncc, jorbin, audrasjb.
Merges [56836] to the 6.3 branch.

Location:
branches/6.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-admin/includes/class-wp-comments-list-table.php

    r56004 r56843  
    651651
    652652                $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
     653
     654                $edit_post_cap = $post ? 'edit_post' : 'edit_posts';
     655                if (
     656                        current_user_can( $edit_post_cap, $comment->comment_post_ID ) ||
     657                        (
     658                                empty( $post->post_password ) &&
     659                                current_user_can( 'read_post', $comment->comment_post_ID )
     660                        )
     661                ) {
     662                        // The user has access to the post
     663                } else {
     664                        return false;
     665                }
    653666
    654667                echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
  • branches/6.3/src/wp-admin/includes/class-wp-list-table.php

    r56261 r56843  
    818818                        $pending_comments_number
    819819                );
     820
     821                $post_object   = get_post( $post_id );
     822                $edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
     823                if (
     824                        current_user_can( $edit_post_cap, $post_id ) ||
     825                        (
     826                                empty( $post_object->post_password ) &&
     827                                current_user_can( 'read_post', $post_id )
     828                        )
     829                ) {
     830                        // The user has access to the post and thus can see comments
     831                } else {
     832                        return false;
     833                }
    820834
    821835                if ( ! $approved_comments && ! $pending_comments ) {
  • branches/6.3/src/wp-admin/includes/dashboard.php

    r56294 r56843  
    11041104                echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
    11051105                foreach ( $comments as $comment ) {
    1106                         _wp_dashboard_recent_comments_row( $comment );
     1106                        $comment_post = get_post( $comment->comment_post_ID );
     1107                        if (
     1108                                current_user_can( 'edit_post', $comment->comment_post_ID ) ||
     1109                                (
     1110                                        empty( $comment_post->post_password ) &&
     1111                                        current_user_can( 'read_post', $comment->comment_post_ID )
     1112                                )
     1113                        ) {
     1114                                _wp_dashboard_recent_comments_row( $comment );
     1115                        }
    11071116                }
    11081117                echo '</ul>';
Note: See TracChangeset for help on using the changeset viewer.