List tables: Move the view mode switcher into screen options for posts.

Having a view mode switcher nestled within table navigation makes no sense, especially now that it's a sticky user option. While less convenient for frequent switching, there is no evidence as of yet that there is a large userbase of frequent view mode switchers.

Introduces a filter for `view_mode_post_types`, which by default is all hierarchical post types with edit UI on.

props Oxymoron.
fixes #22222.

Built from https://develop.svn.wordpress.org/trunk@35357


git-svn-id: http://core.svn.wordpress.org/trunk@35323 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2015-10-22 19:25:25 +00:00
parent 677762f6cf
commit 6ca92efe23
5 changed files with 50 additions and 6 deletions

View File

@ -195,7 +195,7 @@ if ( 'post' == $post_type ) {
'<ul>' .
'<li>' . __('You can hide/display columns based on your needs and decide how many posts to list per screen using the Screen Options tab.') . '</li>' .
'<li>' . __('You can filter the list of posts by post status using the text links in the upper left to show All, Published, Draft, or Trashed posts. The default view is to show all posts.') . '</li>' .
'<li>' . __('You can view posts in a simple title list or with an excerpt. Choose the view you prefer by clicking on the icons at the top of the list on the right.') . '</li>' .
'<li>' . __('You can view posts in a simple title list or with an excerpt using the Screen Options tab.') . '</li>' .
'<li>' . __('You can refine the list to show only posts in a specific category or from a specific month by using the dropdown menus above the posts list. Click the Filter button after making your selection. You also can refine the list by clicking on the post author, category or tag in the posts list.') . '</li>' .
'</ul>'
) );

View File

@ -515,9 +515,6 @@ class WP_Posts_List_Table extends WP_List_Table {
global $mode;
parent::pagination( $which );
if ( 'top' === $which && ! is_post_type_hierarchical( $this->screen->post_type ) )
$this->view_switcher( $mode );
}
/**

View File

@ -991,6 +991,7 @@ final class WP_Screen {
$this->render_list_table_columns_preferences();
$this->render_screen_layout();
$this->render_per_page_options();
$this->render_view_mode();
echo $this->_screen_settings;
/**
@ -1187,6 +1188,46 @@ final class WP_Screen {
<?php
}
/**
* Render the list table view mode preferences.
*
* @since 4.4.0
*/
public function render_view_mode() {
/**
* Filter the post types that have different view mode options.
*
* @since 4.4.0
*
* @param array $view_mode_post_types Array of post types that can change view modes.
* Default hierarchical post types with show_ui on.
*/
$view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) );
$view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
if ( ! in_array( $this->post_type, $view_mode_post_types ) ) {
return;
}
global $mode;
// This needs a submit button
add_filter( 'screen_options_show_submit', '__return_true' );
?>
<fieldset class="metabox-prefs view-mode">
<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' ); ?>
</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' ); ?>
</label>
</fieldset>
<?php
}
/**
* Render screen reader text.
*

View File

@ -461,7 +461,13 @@ function set_screen_options() {
}
update_user_meta($user->ID, $option, $value);
wp_safe_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) );
$url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() );
if ( isset( $_POST['mode'] ) ) {
$url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url );
}
wp_safe_redirect( $url );
exit;
}
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35356';
$wp_version = '4.4-alpha-35357';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.