Make WordPress Core


Ignore:
Timestamp:
11/17/2023 05:09:09 PM (12 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Rewrite a few capability checks for clarity and readability.

This aims to:

  • Perform the checks as early as possible to avoid redundant function calls.
  • Remove an empty conditiaonal branch and make the exit conditions clearer.
  • Bring the formatting in line with other multi-line conditionals in core.

Follow-up to [56836].

See #59650.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r56836 r57123  
    10891089
    10901090        foreach ( $possible as $comment ) {
    1091             if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
     1091            $comment_post = get_post( $comment->comment_post_ID );
     1092
     1093            if ( ! current_user_can( 'edit_post', $comment->comment_post_ID )
     1094                && ( ! empty( $comment_post->post_password )
     1095                    || ! current_user_can( 'read_post', $comment->comment_post_ID ) )
     1096            ) {
     1097                // The user has no access to the post and thus cannot see the comments.
    10921098                continue;
    10931099            }
     
    11101116        echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
    11111117        foreach ( $comments as $comment ) {
    1112             $comment_post = get_post( $comment->comment_post_ID );
    1113             if (
    1114                 current_user_can( 'edit_post', $comment->comment_post_ID ) ||
    1115                 (
    1116                     empty( $comment_post->post_password ) &&
    1117                     current_user_can( 'read_post', $comment->comment_post_ID )
    1118                 )
    1119             ) {
    1120                 _wp_dashboard_recent_comments_row( $comment );
    1121             }
     1118            _wp_dashboard_recent_comments_row( $comment );
    11221119        }
    11231120        echo '</ul>';
Note: See TracChangeset for help on using the changeset viewer.