Make WordPress Core


Ignore:
Timestamp:
07/10/2020 04:02:00 PM (5 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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' );
Note: See TracChangeset for help on using the changeset viewer.