Make WordPress Core

Ticket #49715: 49715.6.diff

File 49715.6.diff, 9.5 KB (added by audrasjb, 4 years ago)

Introduce extensibility to posts and comments list table views, for accessibility purposes

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

    diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php
    index 904a2dce47..38d7ed36ee 100644
    a b class WP_Comments_List_Table extends WP_List_Table { 
    124124                        $start += $_REQUEST['offset'];
    125125                }
    126126
     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' );
     132                }
     133
    127134                $status_map = array(
    128135                        'mine'      => '',
    129136                        'moderated' => 'hold',
    class WP_Comments_List_Table extends WP_List_Table { 
    751758                /** This filter is documented in wp-admin/includes/dashboard.php */
    752759                $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
    753760
     761                $always_visible = false;
     762                $mode = get_user_setting( 'posts_list_mode', 'list' );
     763                if ( 'extended' === $mode ) {
     764                        $always_visible = true;
     765                }
     766
    754767                $i    = 0;
    755                 $out .= '<div class="row-actions">';
     768                $out .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
    756769                foreach ( $actions as $action => $link ) {
    757770                        ++$i;
    758771                        ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  • src/wp-admin/includes/class-wp-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php
    index e6d829e39f..a2851203e1 100644
    a b class WP_List_Table { 
    166166
    167167                if ( empty( $this->modes ) ) {
    168168                        $this->modes = array(
    169                                 'list'    => __( 'List View' ),
    170                                 'excerpt' => __( 'Excerpt View' ),
     169                                'list'     => __( 'Compact View' ),
     170                                'extended' => __( 'Extended View' ),
    171171                        );
    172172                }
    173173        }
    class WP_List_Table { 
    523523                        return '';
    524524                }
    525525
     526                $mode = get_user_setting( 'posts_list_mode', 'list' );
     527                if ( 'extended' === $mode ) {
     528                        $always_visible = true;
     529                }
     530
    526531                $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
    527532                foreach ( $actions as $action => $link ) {
    528533                        ++$i;
    class WP_List_Table { 
    12471252         * @return string[] Array of CSS classes for the table tag.
    12481253         */
    12491254        protected function get_table_classes() {
    1250                 return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
     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                 */
     1266                $mode = apply_filters( 'table_view_mode', $mode );
     1267
     1268                $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
     1269
     1270                return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
    12511271        }
    12521272
    12531273        /**
  • src/wp-admin/includes/class-wp-posts-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php
    index 141ca89a58..b3d9e7da31 100644
    a b class WP_Posts_List_Table extends WP_List_Table { 
    178178                }
    179179
    180180                if ( ! empty( $_REQUEST['mode'] ) ) {
    181                         $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
     181                        $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
    182182                        set_user_setting( 'posts_list_mode', $mode );
    183183                } else {
    184184                        $mode = get_user_setting( 'posts_list_mode', 'list' );
    class WP_Posts_List_Table extends WP_List_Table { 
    598598         * @return array
    599599         */
    600600        protected function get_table_classes() {
    601                 return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
     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                 */
     612                $mode = apply_filters( 'table_view_mode', $mode );
     613
     614                $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
     615
     616                return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
    602617        }
    603618
    604619        /**
    class WP_Posts_List_Table extends WP_List_Table { 
    10421057                }
    10431058                echo "</strong>\n";
    10441059
    1045                 if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
     1060                if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'extended' === $mode && current_user_can( 'read_post', $post->ID ) ) {
    10461061                        if ( post_password_required( $post ) ) {
    10471062                                echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
    10481063                        } else {
    class WP_Posts_List_Table extends WP_List_Table { 
    11021117                 * @param string  $status      The status text.
    11031118                 * @param WP_Post $post        Post object.
    11041119                 * @param string  $column_name The column name.
    1105                  * @param string  $mode        The list display mode ('excerpt' or 'list').
     1120                 * @param string  $mode        The list display mode ('extended' or 'list').
    11061121                 */
    11071122                $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
    11081123
    class WP_Posts_List_Table extends WP_List_Table { 
    11211136                 * @param string  $t_time      The published time.
    11221137                 * @param WP_Post $post        Post object.
    11231138                 * @param string  $column_name The column name.
    1124                  * @param string  $mode        The list display mode ('excerpt' or 'list').
     1139                 * @param string  $mode        The list display mode ('extended' or 'list').
    11251140                 */
    11261141                echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
    11271142        }
    class WP_Posts_List_Table extends WP_List_Table { 
    14911506                        }
    14921507                }
    14931508
    1494                 $m            = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
     1509                $m            = ( isset( $mode ) && 'extended' === $mode ) ? 'extended' : 'list';
    14951510                $can_publish  = current_user_can( $post_type_object->cap->publish_posts );
    14961511                $core_columns = array(
    14971512                        'cb'         => true,
  • src/wp-admin/includes/class-wp-screen.php

    diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php
    index e3a2fcd7a6..dace397437 100644
    a b final class WP_Screen { 
    12881288        public function render_view_mode() {
    12891289                $screen = get_current_screen();
    12901290
    1291                 // Currently only enabled for posts lists.
    1292                 if ( 'edit' !== $screen->base ) {
     1291                // Currently only enabled for posts and comments lists.
     1292                if ( 'edit' !== $screen->base && 'edit-comments' !== $screen->base ) {
    12931293                        return;
    12941294                }
    12951295
    1296                 $view_mode_post_types = get_post_types(
    1297                         array(
    1298                                 'hierarchical' => false,
    1299                                 'show_ui'      => true,
    1300                         )
    1301                 );
     1296                $view_mode_post_types = get_post_types( array( 'show_ui' => true ) );
    13021297
    13031298                /**
    13041299                 * Filters the post types that have different view mode options.
    final class WP_Screen { 
    13061301                 * @since 4.4.0
    13071302                 *
    13081303                 * @param string[] $view_mode_post_types Array of post types that can change view modes.
    1309                  *                                       Default non-hierarchical post types with show_ui on.
     1304                 *                                       Default post types with show_ui on.
    13101305                 */
    13111306                $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
    13121307
    1313                 if ( ! in_array( $this->post_type, $view_mode_post_types, true ) ) {
     1308                if ( 'edit' === $screen->base && ! in_array( $this->post_type, $view_mode_post_types, true ) ) {
    13141309                        return;
    13151310                }
    13161311
    1317                 global $mode;
     1312                $mode = get_user_setting( 'posts_list_mode', 'list' );
     1313
     1314                // Set 'list' as default value if $mode is not set.
     1315                $mode = ( isset( $mode ) && 'extended' === $mode ) ? 'extended' : 'list';
     1316
     1317                /**
     1318                 * Filters the current view mode.
     1319                 *
     1320                 * @since 5.5.0
     1321                 *
     1322                 * @param string $mode The current selected mode. Default value of
     1323                 *                     posts_list_mode user setting.
     1324                 */
     1325                $mode = apply_filters( 'table_view_mode', $mode );
    13181326
    13191327                // This needs a submit button.
    13201328                add_filter( 'screen_options_show_submit', '__return_true' );
    final class WP_Screen { 
    13231331                <legend><?php _e( 'View Mode' ); ?></legend>
    13241332                                <label for="list-view-mode">
    13251333                                        <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
    1326                                         <?php _e( 'List View' ); ?>
     1334                                        <?php _e( 'Compact view' ); ?>
    13271335                                </label>
    13281336                                <label for="excerpt-view-mode">
    1329                                         <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
    1330                                         <?php _e( 'Excerpt View' ); ?>
     1337                                        <input id="excerpt-view-mode" type="radio" name="mode" value="extended" <?php checked( 'extended', $mode ); ?> />
     1338                                        <?php _e( 'Extended View' ); ?>
    13311339                                </label>
     1340                                <?php
     1341                                /**
     1342                                 * Fires at the end of the table view modes screen option.
     1343                                 *
     1344                                 * @since 5.5.0
     1345                                 *
     1346                                 * @param string $mode The currently selected mode.
     1347                                 */
     1348                                do_action( 'wp_table_view_modes', $mode );
     1349                                ?>
    13321350                </fieldset>
    13331351                <?php
    13341352        }