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
This commit is contained in:
parent
48da753ff0
commit
dcdabb5bb3
|
@ -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 .= '<div class="row-actions">';
|
||||
$out .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
|
||||
foreach ( $actions as $action => $link ) {
|
||||
++$i;
|
||||
( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
|
||||
|
|
|
@ -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 = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
|
||||
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'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 "</strong>\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 '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
|
||||
} 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,
|
||||
|
|
|
@ -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 {
|
|||
<legend><?php _e( 'View Mode' ); ?></legend>
|
||||
<label for="list-view-mode">
|
||||
<input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
|
||||
<?php _e( 'List View' ); ?>
|
||||
<?php _e( 'Compact view' ); ?>
|
||||
</label>
|
||||
<label for="excerpt-view-mode">
|
||||
<input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
|
||||
<?php _e( 'Excerpt View' ); ?>
|
||||
<input id="excerpt-view-mode" type="radio" name="mode" value="extended" <?php checked( 'extended', $mode ); ?> />
|
||||
<?php _e( 'Extended View' ); ?>
|
||||
</label>
|
||||
<?php
|
||||
/**
|
||||
* Fires at the end of the table view modes screen option.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param string $mode The currently selected mode.
|
||||
*/
|
||||
do_action( 'wp_table_view_modes', $mode );
|
||||
?>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-48397';
|
||||
$wp_version = '5.5-alpha-48398';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue