Make WordPress Core

Changeset 48424


Ignore:
Timestamp:
07/10/2020 04:02:00 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Administration: Bring some consistency to handling list table view modes.

  • Remove duplicate variables and DocBlocks.
  • Add missing description for the $mode global.
  • Use sentence case for "Compact view" and "Extended view" labels.

Follow-up to [48398], [48423].

Props afercia, Offereins, SergeyBiryukov.
See #49715.

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

Legend:

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

    r48415 r48424  
    8181         * @global int    $post_id
    8282         * @global string $comment_status
     83         * @global string $comment_type
    8384         * @global string $search
    84          * @global string $comment_type
    8585         */
    8686        public function prepare_items() {
    87                 global $post_id, $comment_status, $search, $comment_type;
     87                global $post_id, $comment_status, $comment_type, $search;
     88
     89                if ( ! empty( $_REQUEST['mode'] ) ) {
     90                        $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
     91                        set_user_setting( 'posts_list_mode', $mode );
     92                }
    8893
    8994                $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
     
    123128                if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) {
    124129                        $start += $_REQUEST['offset'];
    125                 }
    126 
    127                 if ( ! empty( $_REQUEST['mode'] ) ) {
    128                         $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
    129                         set_user_setting( 'posts_list_mode', $mode );
    130                 } else {
    131                         $mode = get_user_setting( 'posts_list_mode', 'list' );
    132130                }
    133131
     
    760758
    761759                $always_visible = false;
    762                 $mode           = get_user_setting( 'posts_list_mode', 'list' );
     760
     761                $mode = get_user_setting( 'posts_list_mode', 'list' );
     762
    763763                if ( 'extended' === $mode ) {
    764764                        $always_visible = true;
    765765                }
    766766
    767                 $i    = 0;
    768767                $out .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
     768
     769                $i = 0;
     770
    769771                foreach ( $actions as $action => $link ) {
    770772                        ++$i;
    771                         ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
    772 
    773                         // Reply and quickedit need a hide-if-no-js span when not added with ajax.
     773
     774                        if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
     775                                || 1 === $i
     776                        ) {
     777                                $sep = '';
     778                        } else {
     779                                $sep = ' | ';
     780                        }
     781
     782                        // Reply and quickedit need a hide-if-no-js span when not added with Ajax.
    774783                        if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
    775784                                $action .= ' hide-if-no-js';
    776                         } elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status ) || ( 'unspam' === $action && 'spam' === $the_comment_status ) ) {
     785                        } elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status )
     786                                || ( 'unspam' === $action && 'spam' === $the_comment_status )
     787                        ) {
    777788                                if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
    778789                                        $action .= ' approve';
     
    784795                        $out .= "<span class='$action'>$sep$link</span>";
    785796                }
     797
    786798                $out .= '</div>';
    787799
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r48415 r48424  
    167167                if ( empty( $this->modes ) ) {
    168168                        $this->modes = array(
    169                                 'list'     => __( 'Compact View' ),
    170                                 'extended' => __( 'Extended View' ),
     169                                'list'     => __( 'Compact view' ),
     170                                'extended' => __( 'Extended view' ),
    171171                        );
    172172                }
     
    518518        protected function row_actions( $actions, $always_visible = false ) {
    519519                $action_count = count( $actions );
    520                 $i            = 0;
    521520
    522521                if ( ! $action_count ) {
     
    525524
    526525                $mode = get_user_setting( 'posts_list_mode', 'list' );
     526
    527527                if ( 'extended' === $mode ) {
    528528                        $always_visible = true;
     
    530530
    531531                $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
     532
     533                $i = 0;
     534
    532535                foreach ( $actions as $action => $link ) {
    533536                        ++$i;
    534                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
    535                         $out                          .= "<span class='$action'>$link$sep</span>";
    536                 }
     537
     538                        $sep = ( $i < $action_count ) ? ' | ' : '';
     539
     540                        $out .= "<span class='$action'>$link$sep</span>";
     541                }
     542
    537543                $out .= '</div>';
    538544
     
    12531259         */
    12541260        protected function get_table_classes() {
    1255                 $mode       = get_user_setting( 'posts_list_mode', 'list' );
    1256                 $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-list';
    1257                 $mode       = get_user_setting( 'posts_list_mode', 'list' );
    1258                 /**
    1259                  * Filters the current view mode.
    1260                  *
    1261                  * @since 5.5.0
    1262                  *
    1263                  * @param string $mode The current selected mode. Default value of
    1264                  *                     posts_list_mode user setting.
    1265                  */
     1261                $mode = get_user_setting( 'posts_list_mode', 'list' );
     1262
     1263                /** This filter is documented in wp-admin/includes/class-wp-screen.php */
    12661264                $mode = apply_filters( 'table_view_mode', $mode );
    12671265
    1268                 $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
     1266                $mode_class = esc_attr( 'table-view-' . $mode );
    12691267
    12701268                return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r48417 r48424  
    6262
    6363        /**
     64         * @global string   $mode                  List table view mode.
    6465         * @global WP_Query $wp_query              WordPress Query object.
    6566         * @global array    $post_mime_types
    6667         * @global array    $avail_post_mime_types
    67          * @global string   $mode
    6868         */
    6969        public function prepare_items() {
    70                 global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
     70                global $mode, $wp_query, $post_mime_types, $avail_post_mime_types;
     71
     72                $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
    7173
    7274                // Exclude attachments scheduled for deletion in the next two hours
     
    9698
    9799                $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
    98 
    99                 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
    100100
    101101                $this->set_pagination_args(
  • trunk/src/wp-admin/includes/class-wp-ms-sites-list-table.php

    r47219 r48424  
    6363         * @since 3.1.0
    6464         *
     65         * @global string $mode List table view mode.
    6566         * @global string $s
    66          * @global string $mode
    6767         * @global wpdb   $wpdb WordPress database abstraction object.
    6868         */
    6969        public function prepare_items() {
    70                 global $s, $mode, $wpdb;
     70                global $mode, $s, $wpdb;
    7171
    7272                if ( ! empty( $_REQUEST['mode'] ) ) {
     
    577577
    578578        /**
    579          * @global string $mode
     579         * @global string $mode List table view mode.
    580580         */
    581581        public function display_rows() {
  • trunk/src/wp-admin/includes/class-wp-ms-users-list-table.php

    r47557 r48424  
    2525
    2626        /**
     27         * @global string $mode       List table view mode.
    2728         * @global string $usersearch
    2829         * @global string $role
    29          * @global string $mode
    3030         */
    3131        public function prepare_items() {
    32                 global $usersearch, $role, $mode;
     32                global $mode, $usersearch, $role;
     33
     34                if ( ! empty( $_REQUEST['mode'] ) ) {
     35                        $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
     36                        set_user_setting( 'network_users_list_mode', $mode );
     37                } else {
     38                        $mode = get_user_setting( 'network_users_list_mode', 'list' );
     39                }
    3340
    3441                $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
     
    8289                if ( isset( $_REQUEST['order'] ) ) {
    8390                        $args['order'] = $_REQUEST['order'];
    84                 }
    85 
    86                 if ( ! empty( $_REQUEST['mode'] ) ) {
    87                         $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
    88                         set_user_setting( 'network_users_list_mode', $mode );
    89                 } else {
    90                         $mode = get_user_setting( 'network_users_list_mode', 'list' );
    9191                }
    9292
     
    423423                        $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
    424424
    425                         $i            = 0;
    426425                        $action_count = count( $actions );
     426
     427                        $i = 0;
     428
    427429                        foreach ( $actions as $action => $link ) {
    428430                                ++$i;
    429                                 $sep = ( $i == $action_count ) ? '' : ' | ';
     431
     432                                $sep = ( $i < $action_count ) ? ' | ' : '';
     433
    430434                                echo "<span class='$action'>$link$sep</span>";
    431435                        }
     436
    432437                        echo '</small></span><br/>';
    433438                }
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r48415 r48424  
    136136
    137137        /**
     138         * @global string   $mode             List table view mode.
    138139         * @global array    $avail_post_stati
    139140         * @global WP_Query $wp_query         WordPress Query object.
    140141         * @global int      $per_page
    141          * @global string   $mode
    142142         */
    143143        public function prepare_items() {
    144                 global $avail_post_stati, $wp_query, $per_page, $mode;
     144                global $mode, $avail_post_stati, $wp_query, $per_page;
     145
     146                if ( ! empty( $_REQUEST['mode'] ) ) {
     147                        $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
     148                        set_user_setting( 'posts_list_mode', $mode );
     149                } else {
     150                        $mode = get_user_setting( 'posts_list_mode', 'list' );
     151                }
    145152
    146153                // Is going to call wp().
     
    176183                                }
    177184                        }
    178                 }
    179 
    180                 if ( ! empty( $_REQUEST['mode'] ) ) {
    181                         $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
    182                         set_user_setting( 'posts_list_mode', $mode );
    183                 } else {
    184                         $mode = get_user_setting( 'posts_list_mode', 'list' );
    185185                }
    186186
     
    596596
    597597        /**
     598         * @global string $mode List table view mode.
     599         *
    598600         * @return array
    599601         */
    600602        protected function get_table_classes() {
    601                 $mode       = get_user_setting( 'posts_list_mode', 'list' );
    602                 $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-list';
    603                 $mode       = get_user_setting( 'posts_list_mode', 'list' );
    604                 /**
    605                  * Filters the current view mode.
    606                  *
    607                  * @since 5.5.0
    608                  *
    609                  * @param string $mode The current selected mode. Default value of
    610                  *                     posts_list_mode user setting.
    611                  */
     603                global $mode;
     604
     605                /** This filter is documented in wp-admin/includes/class-wp-screen.php */
    612606                $mode = apply_filters( 'table_view_mode', $mode );
    613607
    614                 $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
     608                $mode_class = esc_attr( 'table-view-' . $mode );
    615609
    616610                return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
  • trunk/src/wp-admin/includes/dashboard.php

    r48191 r48424  
    757757
    758758                $i = 0;
     759
    759760                foreach ( $actions as $action => $link ) {
    760761                        ++$i;
    761762
    762                         if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) {
     763                        if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
     764                                || 1 === $i
     765                        ) {
    763766                                $sep = '';
    764767                        } else {
Note: See TracChangeset for help on using the changeset viewer.