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.

git-svn-id: https://develop.svn.wordpress.org/trunk@48424 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-07-10 16:02:00 +00:00
parent 6c4f6693e5
commit 5e160ea4a9
7 changed files with 83 additions and 71 deletions
+15 -17
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'] );
}