On this page
WP_Screen::render_view_mode()
Renders the list table view mode preferences.
Source
File: wp-admin/includes/class-wp-screen.php. View all references
public function render_view_mode() {
global $mode;
$screen = get_current_screen();
// 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( 'show_ui' => true ) );
/**
* Filters the post types that have different view mode options.
*
* @since 4.4.0
*
* @param string[] $view_mode_post_types Array of post types that can change view modes.
* Default post types with show_ui on.
*/
$view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
if ( 'edit' === $screen->base && ! in_array( $this->post_type, $view_mode_post_types, true ) ) {
return;
}
if ( ! isset( $mode ) ) {
$mode = get_user_setting( 'posts_list_mode', 'list' );
}
// 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( '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( 'Extended view' ); ?>
</label>
</fieldset>
<?php
}
Hooks
- apply_filters( 'view_mode_post_types',
string[] $view_mode_post_types ) -
Filters the post types that have different view mode options.
Related
Uses
| Uses | Description |
|---|---|
| get_current_screen() wp-admin/includes/screen.php | Get the current screen object |
| checked() wp-includes/general-template.php | Outputs the HTML checked attribute. |
| get_user_setting() wp-includes/option.php | Retrieves user interface setting value based on setting name. |
| _e() wp-includes/l10n.php | Displays translated text. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| add_filter() wp-includes/plugin.php | Adds a callback function to a filter hook. |
| get_post_types() wp-includes/post.php | Gets a list of all registered post type objects. |
Used By
| Used By | Description |
|---|---|
| WP_Screen::render_screen_options() wp-admin/includes/class-wp-screen.php | Renders the screen options tab. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_screen/render_view_mode