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:
@@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user