From dcdabb5bb317bd59f0af3d2e3337209cf46b8185 Mon Sep 17 00:00:00 2001 From: whyisjake Date: Tue, 7 Jul 2020 19:12:03 +0000 Subject: [PATCH] Administration: Introduce extensibility to posts and comments list table views, for accessibility purposes. At default, expands the excerpt view to become an extended view. Includes a new `table_view_mode` filter to allow further configuration. Fixes #49715. Props joedolson, audrasjb, afercia, whyisjake. Built from https://develop.svn.wordpress.org/trunk@48398 git-svn-id: http://core.svn.wordpress.org/trunk@48167 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-comments-list-table.php | 15 +++++- wp-admin/includes/class-wp-list-table.php | 26 +++++++++-- .../includes/class-wp-posts-list-table.php | 27 ++++++++--- wp-admin/includes/class-wp-screen.php | 46 +++++++++++++------ wp-includes/version.php | 2 +- 5 files changed, 91 insertions(+), 25 deletions(-) diff --git a/wp-admin/includes/class-wp-comments-list-table.php b/wp-admin/includes/class-wp-comments-list-table.php index 904a2dce47..38d7ed36ee 100644 --- a/wp-admin/includes/class-wp-comments-list-table.php +++ b/wp-admin/includes/class-wp-comments-list-table.php @@ -124,6 +124,13 @@ class WP_Comments_List_Table extends WP_List_Table { $start += $_REQUEST['offset']; } + if ( ! empty( $_REQUEST['mode'] ) ) { + $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list'; + set_user_setting( 'posts_list_mode', $mode ); + } else { + $mode = get_user_setting( 'posts_list_mode', 'list' ); + } + $status_map = array( 'mine' => '', 'moderated' => 'hold', @@ -751,8 +758,14 @@ class WP_Comments_List_Table extends WP_List_Table { /** This filter is documented in wp-admin/includes/dashboard.php */ $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); + $always_visible = false; + $mode = get_user_setting( 'posts_list_mode', 'list' ); + if ( 'extended' === $mode ) { + $always_visible = true; + } + $i = 0; - $out .= '
'; + $out .= '
'; foreach ( $actions as $action => $link ) { ++$i; ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php index e6d829e39f..a2851203e1 100644 --- a/wp-admin/includes/class-wp-list-table.php +++ b/wp-admin/includes/class-wp-list-table.php @@ -166,8 +166,8 @@ class WP_List_Table { if ( empty( $this->modes ) ) { $this->modes = array( - 'list' => __( 'List View' ), - 'excerpt' => __( 'Excerpt View' ), + 'list' => __( 'Compact View' ), + 'extended' => __( 'Extended View' ), ); } } @@ -523,6 +523,11 @@ class WP_List_Table { return ''; } + $mode = get_user_setting( 'posts_list_mode', 'list' ); + if ( 'extended' === $mode ) { + $always_visible = true; + } + $out = '
'; foreach ( $actions as $action => $link ) { ++$i; @@ -1247,7 +1252,22 @@ class WP_List_Table { * @return string[] Array of CSS classes for the table tag. */ protected function get_table_classes() { - return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] ); + $mode = get_user_setting( 'posts_list_mode', 'list' ); + $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-list'; + $mode = get_user_setting( 'posts_list_mode', 'list' ); + /** + * Filters the current view mode. + * + * @since 5.5.0 + * + * @param string $mode The current selected mode. Default value of + * posts_list_mode user setting. + */ + $mode = apply_filters( 'table_view_mode', $mode ); + + $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode; + + return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] ); } /** diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 141ca89a58..b3d9e7da31 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -178,7 +178,7 @@ class WP_Posts_List_Table extends WP_List_Table { } if ( ! empty( $_REQUEST['mode'] ) ) { - $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; + $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list'; set_user_setting( 'posts_list_mode', $mode ); } else { $mode = get_user_setting( 'posts_list_mode', 'list' ); @@ -598,7 +598,22 @@ class WP_Posts_List_Table extends WP_List_Table { * @return array */ protected function get_table_classes() { - return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); + $mode = get_user_setting( 'posts_list_mode', 'list' ); + $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-list'; + $mode = get_user_setting( 'posts_list_mode', 'list' ); + /** + * Filters the current view mode. + * + * @since 5.5.0 + * + * @param string $mode The current selected mode. Default value of + * posts_list_mode user setting. + */ + $mode = apply_filters( 'table_view_mode', $mode ); + + $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode; + + return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); } /** @@ -1042,7 +1057,7 @@ class WP_Posts_List_Table extends WP_List_Table { } echo "\n"; - if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) { + if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'extended' === $mode && current_user_can( 'read_post', $post->ID ) ) { if ( post_password_required( $post ) ) { echo '' . esc_html( get_the_excerpt() ) . ''; } else { @@ -1102,7 +1117,7 @@ class WP_Posts_List_Table extends WP_List_Table { * @param string $status The status text. * @param WP_Post $post Post object. * @param string $column_name The column name. - * @param string $mode The list display mode ('excerpt' or 'list'). + * @param string $mode The list display mode ('extended' or 'list'). */ $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode ); @@ -1121,7 +1136,7 @@ class WP_Posts_List_Table extends WP_List_Table { * @param string $t_time The published time. * @param WP_Post $post Post object. * @param string $column_name The column name. - * @param string $mode The list display mode ('excerpt' or 'list'). + * @param string $mode The list display mode ('extended' or 'list'). */ echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode ); } @@ -1491,7 +1506,7 @@ class WP_Posts_List_Table extends WP_List_Table { } } - $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list'; + $m = ( isset( $mode ) && 'extended' === $mode ) ? 'extended' : 'list'; $can_publish = current_user_can( $post_type_object->cap->publish_posts ); $core_columns = array( 'cb' => true, diff --git a/wp-admin/includes/class-wp-screen.php b/wp-admin/includes/class-wp-screen.php index e3a2fcd7a6..dace397437 100644 --- a/wp-admin/includes/class-wp-screen.php +++ b/wp-admin/includes/class-wp-screen.php @@ -1288,17 +1288,12 @@ final class WP_Screen { public function render_view_mode() { $screen = get_current_screen(); - // Currently only enabled for posts lists. - if ( 'edit' !== $screen->base ) { + // Currently only enabled for posts and comments lists. + if ( 'edit' !== $screen->base && 'edit-comments' !== $screen->base ) { return; } - $view_mode_post_types = get_post_types( - array( - 'hierarchical' => false, - 'show_ui' => true, - ) - ); + $view_mode_post_types = get_post_types( array( 'show_ui' => true ) ); /** * Filters the post types that have different view mode options. @@ -1306,15 +1301,28 @@ final class WP_Screen { * @since 4.4.0 * * @param string[] $view_mode_post_types Array of post types that can change view modes. - * Default non-hierarchical post types with show_ui on. + * Default post types with show_ui on. */ $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types ); - if ( ! in_array( $this->post_type, $view_mode_post_types, true ) ) { + if ( 'edit' === $screen->base && ! in_array( $this->post_type, $view_mode_post_types, true ) ) { return; } - global $mode; + $mode = get_user_setting( 'posts_list_mode', 'list' ); + + // Set 'list' as default value if $mode is not set. + $mode = ( isset( $mode ) && 'extended' === $mode ) ? 'extended' : 'list'; + + /** + * Filters the current view mode. + * + * @since 5.5.0 + * + * @param string $mode The current selected mode. Default value of + * posts_list_mode user setting. + */ + $mode = apply_filters( 'table_view_mode', $mode ); // This needs a submit button. add_filter( 'screen_options_show_submit', '__return_true' ); @@ -1323,12 +1331,22 @@ final class WP_Screen { +