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.
Built from https://develop.svn.wordpress.org/trunk@48424


git-svn-id: http://core.svn.wordpress.org/trunk@48193 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-07-10 16:04:05 +00:00
parent 0f92086ca0
commit 51856d435b
8 changed files with 84 additions and 72 deletions

View File

@ -80,11 +80,16 @@ class WP_Comments_List_Table extends WP_List_Table {
/**
* @global int $post_id
* @global string $comment_status
* @global string $search
* @global string $comment_type
* @global string $search
*/
public function prepare_items() {
global $post_id, $comment_status, $search, $comment_type;
global $post_id, $comment_status, $comment_type, $search;
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
set_user_setting( 'posts_list_mode', $mode );
}
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ), true ) ) {
@ -124,13 +129,6 @@ 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',
@ -759,21 +757,34 @@ class WP_Comments_List_Table extends WP_List_Table {
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$always_visible = false;
$mode = get_user_setting( 'posts_list_mode', 'list' );
$mode = get_user_setting( 'posts_list_mode', 'list' );
if ( 'extended' === $mode ) {
$always_visible = true;
}
$i = 0;
$out .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
// Reply and quickedit need a hide-if-no-js span when not added with ajax.
if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
|| 1 === $i
) {
$sep = '';
} else {
$sep = ' | ';
}
// Reply and quickedit need a hide-if-no-js span when not added with Ajax.
if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
$action .= ' hide-if-no-js';
} elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status ) || ( 'unspam' === $action && 'spam' === $the_comment_status ) ) {
} elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status )
|| ( 'unspam' === $action && 'spam' === $the_comment_status )
) {
if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
$action .= ' approve';
} else {
@ -783,6 +794,7 @@ class WP_Comments_List_Table extends WP_List_Table {
$out .= "<span class='$action'>$sep$link</span>";
}
$out .= '</div>';
$out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';

View File

@ -166,8 +166,8 @@ class WP_List_Table {
if ( empty( $this->modes ) ) {
$this->modes = array(
'list' => __( 'Compact View' ),
'extended' => __( 'Extended View' ),
'list' => __( 'Compact view' ),
'extended' => __( 'Extended view' ),
);
}
}
@ -517,23 +517,29 @@ class WP_List_Table {
*/
protected function row_actions( $actions, $always_visible = false ) {
$action_count = count( $actions );
$i = 0;
if ( ! $action_count ) {
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' ) . '">';
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
$out .= "<span class='$action'>$link$sep</span>";
$sep = ( $i < $action_count ) ? ' | ' : '';
$out .= "<span class='$action'>$link$sep</span>";
}
$out .= '</div>';
$out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
@ -1252,20 +1258,12 @@ class WP_List_Table {
* @return string[] Array of CSS classes for the table tag.
*/
protected function get_table_classes() {
$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 = get_user_setting( 'posts_list_mode', 'list' );
/** This filter is documented in wp-admin/includes/class-wp-screen.php */
$mode = apply_filters( 'table_view_mode', $mode );
$mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
$mode_class = esc_attr( 'table-view-' . $mode );
return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
}

View File

@ -61,13 +61,15 @@ class WP_Media_List_Table extends WP_List_Table {
}
/**
* @global string $mode List table view mode.
* @global WP_Query $wp_query WordPress Query object.
* @global array $post_mime_types
* @global array $avail_post_mime_types
* @global string $mode
*/
public function prepare_items() {
global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
global $mode, $wp_query, $post_mime_types, $avail_post_mime_types;
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
// Exclude attachments scheduled for deletion in the next two hours
// if they are for zip packages for interrupted or failed updates.
@ -96,8 +98,6 @@ class WP_Media_List_Table extends WP_List_Table {
$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
$this->set_pagination_args(
array(
'total_items' => $wp_query->found_posts,

View File

@ -62,12 +62,12 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @global string $mode List table view mode.
* @global string $s
* @global string $mode
* @global wpdb $wpdb WordPress database abstraction object.
*/
public function prepare_items() {
global $s, $mode, $wpdb;
global $mode, $s, $wpdb;
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
@ -576,7 +576,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
}
/**
* @global string $mode
* @global string $mode List table view mode.
*/
public function display_rows() {
foreach ( $this->items as $blog ) {

View File

@ -24,12 +24,19 @@ class WP_MS_Users_List_Table extends WP_List_Table {
}
/**
* @global string $mode List table view mode.
* @global string $usersearch
* @global string $role
* @global string $mode
*/
public function prepare_items() {
global $usersearch, $role, $mode;
global $mode, $usersearch, $role;
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
set_user_setting( 'network_users_list_mode', $mode );
} else {
$mode = get_user_setting( 'network_users_list_mode', 'list' );
}
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
@ -83,13 +90,6 @@ class WP_MS_Users_List_Table extends WP_List_Table {
$args['order'] = $_REQUEST['order'];
}
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
set_user_setting( 'network_users_list_mode', $mode );
} else {
$mode = get_user_setting( 'network_users_list_mode', 'list' );
}
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
$args = apply_filters( 'users_list_table_query_args', $args );
@ -422,13 +422,18 @@ class WP_MS_Users_List_Table extends WP_List_Table {
*/
$actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
$i = 0;
$action_count = count( $actions );
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
$sep = ( $i == $action_count ) ? '' : ' | ';
$sep = ( $i < $action_count ) ? ' | ' : '';
echo "<span class='$action'>$link$sep</span>";
}
echo '</small></span><br/>';
}
}

View File

@ -135,13 +135,20 @@ class WP_Posts_List_Table extends WP_List_Table {
}
/**
* @global string $mode List table view mode.
* @global array $avail_post_stati
* @global WP_Query $wp_query WordPress Query object.
* @global int $per_page
* @global string $mode
*/
public function prepare_items() {
global $avail_post_stati, $wp_query, $per_page, $mode;
global $mode, $avail_post_stati, $wp_query, $per_page;
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' );
}
// Is going to call wp().
$avail_post_stati = wp_edit_posts_query();
@ -177,13 +184,6 @@ class WP_Posts_List_Table extends WP_List_Table {
}
}
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' );
}
$this->is_trash = isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'];
$this->set_pagination_args(
@ -595,23 +595,17 @@ class WP_Posts_List_Table extends WP_List_Table {
}
/**
* @global string $mode List table view mode.
*
* @return array
*/
protected function get_table_classes() {
$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.
*/
global $mode;
/** This filter is documented in wp-admin/includes/class-wp-screen.php */
$mode = apply_filters( 'table_view_mode', $mode );
$mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
$mode_class = esc_attr( 'table-view-' . $mode );
return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
}

View File

@ -756,10 +756,13 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) {
if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
|| 1 === $i
) {
$sep = '';
} else {
$sep = ' | ';

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-beta1-48423';
$wp_version = '5.5-beta1-48424';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.