Make WordPress Core

Changeset 50804


Ignore:
Timestamp:
05/03/2021 01:55:08 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-admin/includes/class-wp-posts-list-table.php.

Includes minor code layout fixes for better readability.

See #52627.

Location:
trunk/src/wp-admin/includes
Files:
3 edited

Legend:

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

    r50768 r50804  
    414414                }
    415415
    416                 if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $has_items ) {
     416                if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && $has_items
     417                        && current_user_can( 'moderate_comments' )
     418                ) {
    417419                        wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
    418420                        $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r50770 r50804  
    172172        protected function get_bulk_actions() {
    173173                $actions = array();
     174
    174175                if ( MEDIA_TRASH ) {
    175176                        if ( $this->is_trash ) {
    … …  
    209210                        submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    210211
    211                         if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
     212                        if ( $this->is_trash && $this->has_items()
     213                                && current_user_can( 'edit_others_posts' )
     214                        ) {
    212215                                submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
    213216                        }
    … …  
    337340                                $column_key = 'taxonomy-' . $taxonomy;
    338341                        }
     342
    339343                        $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
    340344                }
    … …  
    347351                        }
    348352                }
     353
    349354                /* translators: Column name. */
    350355                $posts_columns['date'] = _x( 'Date', 'column name' );
     356
    351357                /**
    352358                 * Filters the Media list table columns.
    … …  
    425431                        <?php
    426432                        echo $link_start;
     433
    427434                        if ( $thumb ) :
    428435                                ?>
    … …  
    430437                                <?php
    431438                        endif;
     439
    432440                        echo $title . $link_end;
     441
    433442                        _media_states( $post );
    434443                        ?>
    … …  
    599608                if ( $taxonomy ) {
    600609                        $terms = get_the_terms( $post->ID, $taxonomy );
     610
    601611                        if ( is_array( $terms ) ) {
    602612                                $out = array();
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r50505 r50804  
    8585                $post_type_object = get_post_type_object( $post_type );
    8686
    87                 $exclude_states         = get_post_stati(
     87                $exclude_states = get_post_stati(
    8888                        array(
    8989                                'show_in_admin_all_list' => false,
    9090                        )
    9191                );
     92
    9293                $this->user_posts_count = (int) $wpdb->get_var(
    9394                        $wpdb->prepare(
    94                                 "
    95                         SELECT COUNT( 1 )
    96                         FROM $wpdb->posts
    97                         WHERE post_type = %s
    98                         AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
    99                         AND post_author = %d
    100                 ",
     95                                "SELECT COUNT( 1 )
     96                                FROM $wpdb->posts
     97                                WHERE post_type = %s
     98                                AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
     99                                AND post_author = %d",
    101100                                $post_type,
    102101                                get_current_user_id()
    … …  
    104103                );
    105104
    106                 if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
     105                if ( $this->user_posts_count
     106                        && ! current_user_can( $post_type_object->cap->edit_others_posts )
     107                        && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] )
     108                        && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] )
     109                ) {
    107110                        $_GET['author'] = get_current_user_id();
    108111                }
    109112
    110113                $sticky_posts = get_option( 'sticky_posts' );
     114
    111115                if ( 'post' === $post_type && $sticky_posts ) {
    112                         $sticky_posts             = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
    113                         $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
     116                        $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
     117
     118                        $this->sticky_posts_count = (int) $wpdb->get_var(
     119                                $wpdb->prepare(
     120                                        "SELECT COUNT( 1 )
     121                                        FROM $wpdb->posts
     122                                        WHERE post_type = %s
     123                                        AND post_status NOT IN ('trash', 'auto-draft')
     124                                        AND ID IN ($sticky_posts)",
     125                                        $post_type
     126                                )
     127                        );
    114128                }
    115129        }
    … …  
    152166                $avail_post_stati = wp_edit_posts_query();
    153167
    154                 $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
     168                $this->set_hierarchical_display(
     169                        is_post_type_hierarchical( $this->screen->post_type )
     170                        && 'menu_order title' === $wp_query->query['orderby']
     171                );
    155172
    156173                $post_type = $this->screen->post_type;
    … …  
    171188                        } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
    172189                                $total_items = $this->sticky_posts_count;
    173                         } elseif ( isset( $_GET['author'] ) && get_current_user_id() == $_GET['author'] ) {
     190                        } elseif ( isset( $_GET['author'] ) && get_current_user_id() === (int) $_GET['author'] ) {
    174191                                $total_items = $this->user_posts_count;
    175192                        } else {
    … …  
    245262                $class_html   = '';
    246263                $aria_current = '';
     264
    247265                if ( ! empty( $class ) ) {
    248266                        $class_html = sprintf(
    … …  
    294312
    295313                if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
    296                         if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
     314                        if ( isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ) ) {
    297315                                $class = 'current';
    298316                        }
    … …  
    336354
    337355                $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
     356
    338357                if ( $mine ) {
    339358                        $status_links['mine'] = $mine;
    … …  
    514533                                // Pretty, translated version of the post format slug.
    515534                                $pretty_name = get_post_format_string( $slug );
     535
    516536                                // Skip the standard post format.
    517537                                if ( 'standard' === $slug ) {
    … …  
    566586                }
    567587
    568                 if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) {
     588                if ( $this->is_trash && $this->has_items()
     589                        && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts )
     590                ) {
    569591                        submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
    570592                }
    … …  
    604626                $mode_class = esc_attr( 'table-view-' . $mode );
    605627
    606                 return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
     628                return array(
     629                        'widefat',
     630                        'fixed',
     631                        'striped',
     632                        $mode_class,
     633                        is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts',
     634                );
    607635        }
    608636
    … …  
    659687
    660688                $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
    661                 if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) ) {
    662                         $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
     689
     690                if ( post_type_supports( $post_type, 'comments' )
     691                        && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true )
     692                ) {
     693                        $posts_columns['comments'] = sprintf(
     694                                '<span class="vers comment-grey-bubble" title="%1$s"><span class="screen-reader-text">%2$s</span></span>',
     695                                esc_attr__( 'Comments' ),
     696                                __( 'Comments' )
     697                        );
    663698                }
    664699
    … …  
    790825                 */
    791826                if ( empty( $_REQUEST['s'] ) ) {
    792 
    793827                        $top_level_pages = array();
    794828                        $children_pages  = array();
    795829
    796830                        foreach ( $pages as $page ) {
    797 
    798831                                // Catch and repair bad pages.
    799                                 if ( $page->post_parent == $page->ID ) {
     832                                if ( $page->post_parent === $page->ID ) {
    800833                                        $page->post_parent = 0;
    801834                                        $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
    … …  
    803836                                }
    804837
    805                                 if ( 0 == $page->post_parent ) {
     838                                if ( $page->post_parent > 0 ) {
     839                                        $children_pages[ $page->post_parent ][] = $page;
     840                                } else {
    806841                                        $top_level_pages[] = $page;
    807                                 } else {
    808                                         $children_pages[ $page->post_parent ][] = $page;
    809842                                }
    810843                        }
    … …  
    893926
    894927                        // If the page starts in a subtree, print the parents.
    895                         if ( $count == $start && $page->post_parent > 0 ) {
     928                        if ( $count === $start && $page->post_parent > 0 ) {
    896929                                $my_parents = array();
    897930                                $my_parent  = $page->post_parent;
     931
    898932                                while ( $my_parent ) {
    899933                                        // Get the ID from the list or the attribute if my_parent is an object.
    900934                                        $parent_id = $my_parent;
     935
    901936                                        if ( is_object( $my_parent ) ) {
    902937                                                $parent_id = $my_parent->ID;
    … …  
    905940                                        $my_parent    = get_post( $parent_id );
    906941                                        $my_parents[] = $my_parent;
     942
    907943                                        if ( ! $my_parent->post_parent ) {
    908944                                                break;
    909945                                        }
     946
    910947                                        $my_parent = $my_parent->post_parent;
    911948                                }
     949
    912950                                $num_parents = count( $my_parents );
     951
    913952                                while ( $my_parent = array_pop( $my_parents ) ) {
    914953                                        $to_display[ $my_parent->ID ] = $level - $num_parents;
    … …  
    10051044                                // Sent level 0 by accident, by default, or because we don't know the actual level.
    10061045                                $find_main_page = (int) $post->post_parent;
     1046
    10071047                                while ( $find_main_page > 0 ) {
    10081048                                        $parent = get_post( $find_main_page );
    … …  
    10681108                        echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
    10691109                }
     1110
    10701111                echo "</strong>\n";
    10711112
    … …  
    12091250                        $taxonomy = false;
    12101251                }
     1252
    12111253                if ( $taxonomy ) {
    12121254                        $taxonomy_object = get_taxonomy( $taxonomy );
    12131255                        $terms           = get_the_terms( $post->ID, $taxonomy );
     1256
    12141257                        if ( is_array( $terms ) ) {
    12151258                                $term_links = array();
     1259
    12161260                                foreach ( $terms as $t ) {
    12171261                                        $posts_in_term_qv = array();
     1262
    12181263                                        if ( 'post' !== $post->post_type ) {
    12191264                                                $posts_in_term_qv['post_type'] = $post->post_type;
    12201265                                        }
     1266
    12211267                                        if ( $taxonomy_object->query_var ) {
    12221268                                                $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
    … …  
    13131359                setup_postdata( $post );
    13141360
    1315                 $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
     1361                $classes = 'iedit author-' . ( get_current_user_id() === (int) $post->post_author ? 'self' : 'other' );
    13161362
    13171363                $lock_holder = wp_check_post_lock( $post->ID );
     1364
    13181365                if ( $lock_holder ) {
    13191366                        $classes .= ' wp-locked';
    … …  
    14031450                                );
    14041451                        }
     1452
    14051453                        if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
    14061454                                $actions['delete'] = sprintf(
    … …  
    15021550
    15031551                foreach ( $taxonomy_names as $taxonomy_name ) {
    1504 
    15051552                        $taxonomy = get_taxonomy( $taxonomy_name );
    15061553
    … …  
    15381585                        'author'     => true,
    15391586                );
    1540 
    15411587                ?>
    15421588
    … …  
    15501596
    15511597                $bulk = 0;
     1598
    15521599                while ( $bulk < 2 ) :
    15531600                        $classes  = $inline_edit_classes . ' ';
    … …  
    15981645
    15991646                                <?php
    1600                                 if ( post_type_supports( $screen->post_type, 'author' ) ) :
     1647                                if ( post_type_supports( $screen->post_type, 'author' ) ) {
    16011648                                        $authors_dropdown = '';
    16021649
    1603                                         if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) :
     1650                                        if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) {
    16041651                                                $users_opt = array(
    16051652                                                        'hide_if_only_one_author' => false,
    … …  
    16291676
    16301677                                                $authors = wp_dropdown_users( $users_opt );
    1631                                                 if ( $authors ) :
     1678
     1679                                                if ( $authors ) {
    16321680                                                        $authors_dropdown  = '<label class="inline-edit-author">';
    16331681                                                        $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
    16341682                                                        $authors_dropdown .= $authors;
    16351683                                                        $authors_dropdown .= '</label>';
    1636                                                 endif;
    1637                                         endif; // current_user_can( 'edit_others_posts' )
    1638                                         ?>
    1639 
    1640                                         <?php
     1684                                                }
     1685                                        } // current_user_can( 'edit_others_posts' )
     1686
    16411687                                        if ( ! $bulk ) {
    16421688                                                echo $authors_dropdown;
    16431689                                        }
    1644                                 endif; // post_type_supports( ... 'author' )
     1690                                } // post_type_supports( ... 'author' )
    16451691                                ?>
    16461692
Note: See TracChangeset for help on using the changeset viewer.