3 * Screen API: WP_Screen class
6 * @subpackage Administration
11 * Core class used to implement an admin screen API.
15 final class WP_Screen {
17 * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
26 * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
27 * For example, for an $id of 'edit-post' the base is 'edit'.
36 * The number of columns to display. Access with get_columns().
45 * The unique ID of the screen.
54 * Which admin the screen is in. network | user | site | false
63 * Whether the screen is in the network admin.
65 * Deprecated. Use in_admin() instead.
75 * Whether the screen is in the user admin.
77 * Deprecated. Use in_admin() instead.
87 * The base menu parent.
88 * This is derived from $parent_file by removing the query string and any .php extension.
89 * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
98 * The parent_file for the screen per the admin menu system.
99 * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
108 * The post type associated with the screen, if any.
109 * The 'edit.php?post_type=page' screen has a post type of 'page'.
110 * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
119 * The taxonomy associated with the screen, if any.
120 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
128 * The help tab data associated with the screen, if any.
134 private $_help_tabs = array();
137 * The help sidebar data associated with screen, if any.
143 private $_help_sidebar = '';
146 * The accessible hidden headings and text associated with the screen, if any.
152 private $_screen_reader_content = array();
155 * Stores old string-based help.
162 private static $_old_compat_help = array();
165 * The screen options associated with screen, if any.
171 private $_options = array();
174 * The screen object registry.
183 private static $_registry = array();
186 * Stores the result of the public show_screen_options function.
192 private $_show_screen_options;
195 * Stores the 'screen_settings' section of screen options.
201 private $_screen_settings;
204 * Fetches a screen object.
211 * @global string $hook_suffix
213 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
214 * Defaults to the current $hook_suffix global.
215 * @return WP_Screen Screen object.
217 public static function get( $hook_name = '' ) {
218 if ( $hook_name instanceof WP_Screen ) {
222 $post_type = $taxonomy = null;
229 $id = $GLOBALS['hook_suffix'];
231 // For those pesky meta boxes.
232 if ( $hook_name && post_type_exists( $hook_name ) ) {
234 $id = 'post'; // changes later. ends up being $base.
236 if ( '.php' == substr( $id, -4 ) )
237 $id = substr( $id, 0, -4 );
239 if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
240 $id = substr( $id, 0, -4 );
245 if ( ! $post_type && $hook_name ) {
246 if ( '-network' == substr( $id, -8 ) ) {
247 $id = substr( $id, 0, -8 );
248 $in_admin = 'network';
249 } elseif ( '-user' == substr( $id, -5 ) ) {
250 $id = substr( $id, 0, -5 );
254 $id = sanitize_key( $id );
255 if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
256 $maybe = substr( $id, 5 );
257 if ( taxonomy_exists( $maybe ) ) {
260 } elseif ( post_type_exists( $maybe ) ) {
269 if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
270 $in_admin = 'network';
271 elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
277 if ( 'index' == $id )
279 elseif ( 'front' == $id )
284 // If this is the current screen, see if we can be more accurate for post types and taxonomies.
285 if ( ! $hook_name ) {
286 if ( isset( $_REQUEST['post_type'] ) )
287 $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
288 if ( isset( $_REQUEST['taxonomy'] ) )
289 $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
293 if ( isset( $_GET['post'] ) )
294 $post_id = (int) $_GET['post'];
295 elseif ( isset( $_POST['post_ID'] ) )
296 $post_id = (int) $_POST['post_ID'];
301 $post = get_post( $post_id );
303 $post_type = $post->post_type;
308 if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
316 if ( null === $post_type )
321 if ( null === $post_type )
323 $id .= '-' . $post_type;
327 if ( null === $taxonomy )
328 $taxonomy = 'post_tag';
329 // The edit-tags ID does not contain the post type. Look for it in the request.
330 if ( null === $post_type ) {
332 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
333 $post_type = $_REQUEST['post_type'];
336 $id = 'edit-' . $taxonomy;
340 if ( 'network' == $in_admin ) {
343 } elseif ( 'user' == $in_admin ) {
348 if ( isset( self::$_registry[ $id ] ) ) {
349 $screen = self::$_registry[ $id ];
350 if ( $screen === get_current_screen() )
353 $screen = new WP_Screen();
357 $screen->base = $base;
358 $screen->action = $action;
359 $screen->post_type = (string) $post_type;
360 $screen->taxonomy = (string) $taxonomy;
361 $screen->is_user = ( 'user' == $in_admin );
362 $screen->is_network = ( 'network' == $in_admin );
363 $screen->in_admin = $in_admin;
365 self::$_registry[ $id ] = $screen;
371 * Makes the screen object the current screen.
373 * @see set_current_screen()
376 * @global WP_Screen $current_screen
377 * @global string $taxnow
378 * @global string $typenow
380 public function set_current_screen() {
381 global $current_screen, $taxnow, $typenow;
382 $current_screen = $this;
383 $taxnow = $this->taxonomy;
384 $typenow = $this->post_type;
387 * Fires after the current screen has been set.
391 * @param WP_Screen $current_screen Current WP_Screen object.
393 do_action( 'current_screen', $current_screen );
402 private function __construct() {}
405 * Indicates whether the screen is in a particular admin
409 * @param string $admin The admin to check against (network | user | site).
410 * If empty any of the three admins will result in true.
411 * @return bool True if the screen is in the indicated admin, false otherwise.
413 public function in_admin( $admin = null ) {
414 if ( empty( $admin ) )
415 return (bool) $this->in_admin;
417 return ( $admin == $this->in_admin );
421 * Sets the old string-based contextual help for the screen for backward compatibility.
427 * @param WP_Screen $screen A screen object.
428 * @param string $help Help text.
430 public static function add_old_compat_help( $screen, $help ) {
431 self::$_old_compat_help[ $screen->id ] = $help;
435 * Set the parent information for the screen.
436 * This is called in admin-header.php after the menu parent for the screen has been determined.
440 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
442 public function set_parentage( $parent_file ) {
443 $this->parent_file = $parent_file;
444 list( $this->parent_base ) = explode( '?', $parent_file );
445 $this->parent_base = str_replace( '.php', '', $this->parent_base );
449 * Adds an option for the screen.
450 * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
454 * @param string $option Option ID
455 * @param mixed $args Option-dependent arguments.
457 public function add_option( $option, $args = array() ) {
458 $this->_options[ $option ] = $args;
462 * Remove an option from the screen.
466 * @param string $option Option ID.
468 public function remove_option( $option ) {
469 unset( $this->_options[ $option ] );
473 * Remove all options from the screen.
477 public function remove_options() {
478 $this->_options = array();
482 * Get the options registered for the screen.
486 * @return array Options with arguments.
488 public function get_options() {
489 return $this->_options;
493 * Gets the arguments for an option for the screen.
497 * @param string $option Option name.
498 * @param string $key Optional. Specific array key for when the option is an array.
500 * @return string The option value if set, null otherwise.
502 public function get_option( $option, $key = false ) {
503 if ( ! isset( $this->_options[ $option ] ) )
506 if ( isset( $this->_options[ $option ][ $key ] ) )
507 return $this->_options[ $option ][ $key ];
510 return $this->_options[ $option ];
514 * Gets the help tabs registered for the screen.
517 * @since 4.4.0 Help tabs are ordered by their priority.
519 * @return array Help tabs with arguments.
521 public function get_help_tabs() {
522 $help_tabs = $this->_help_tabs;
524 $priorities = array();
525 foreach ( $help_tabs as $help_tab ) {
526 if ( isset( $priorities[ $help_tab['priority'] ] ) ) {
527 $priorities[ $help_tab['priority'] ][] = $help_tab;
529 $priorities[ $help_tab['priority'] ] = array( $help_tab );
533 ksort( $priorities );
536 foreach ( $priorities as $list ) {
537 foreach ( $list as $tab ) {
538 $sorted[ $tab['id'] ] = $tab;
546 * Gets the arguments for a help tab.
550 * @param string $id Help Tab ID.
551 * @return array Help tab arguments.
553 public function get_help_tab( $id ) {
554 if ( ! isset( $this->_help_tabs[ $id ] ) )
556 return $this->_help_tabs[ $id ];
560 * Add a help tab to the contextual help for the screen.
561 * Call this on the load-$pagenow hook for the relevant screen.
564 * @since 4.4.0 The `$priority` argument was added.
566 * @param array $args {
567 * Array of arguments used to display the help tab.
569 * @type string $title Title for the tab. Default false.
570 * @type string $id Tab ID. Must be HTML-safe. Default false.
571 * @type string $content Optional. Help tab content in plain text or HTML. Default empty string.
572 * @type string $callback Optional. A callback to generate the tab content. Default false.
573 * @type int $priority Optional. The priority of the tab, used for ordering. Default 10.
576 public function add_help_tab( $args ) {
584 $args = wp_parse_args( $args, $defaults );
586 $args['id'] = sanitize_html_class( $args['id'] );
588 // Ensure we have an ID and title.
589 if ( ! $args['id'] || ! $args['title'] )
592 // Allows for overriding an existing tab with that ID.
593 $this->_help_tabs[ $args['id'] ] = $args;
597 * Removes a help tab from the contextual help for the screen.
601 * @param string $id The help tab ID.
603 public function remove_help_tab( $id ) {
604 unset( $this->_help_tabs[ $id ] );
608 * Removes all help tabs from the contextual help for the screen.
612 public function remove_help_tabs() {
613 $this->_help_tabs = array();
617 * Gets the content from a contextual help sidebar.
621 * @return string Contents of the help sidebar.
623 public function get_help_sidebar() {
624 return $this->_help_sidebar;
628 * Add a sidebar to the contextual help for the screen.
629 * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add a sidebar to the contextual help.
633 * @param string $content Sidebar content in plain text or HTML.
635 public function set_help_sidebar( $content ) {
636 $this->_help_sidebar = $content;
640 * Gets the number of layout columns the user has selected.
642 * The layout_columns option controls the max number and default number of
643 * columns. This method returns the number of columns within that range selected
644 * by the user via Screen Options. If no selection has been made, the default
645 * provisioned in layout_columns is returned. If the screen does not support
646 * selecting the number of layout columns, 0 is returned.
650 * @return int Number of columns to display.
652 public function get_columns() {
653 return $this->columns;
657 * Get the accessible hidden headings and text used in the screen.
661 * @see set_screen_reader_content() For more information on the array format.
663 * @return array An associative array of screen reader text strings.
665 public function get_screen_reader_content() {
666 return $this->_screen_reader_content;
670 * Get a screen reader text string.
674 * @param string $key Screen reader text array named key.
675 * @return string Screen reader text string.
677 public function get_screen_reader_text( $key ) {
678 if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
681 return $this->_screen_reader_content[ $key ];
685 * Add accessible hidden headings and text for the screen.
689 * @param array $content {
690 * An associative array of screen reader text strings.
692 * @type string $heading_views Screen reader text for the filter links heading.
693 * Default 'Filter items list'.
694 * @type string $heading_pagination Screen reader text for the pagination heading.
695 * Default 'Items list navigation'.
696 * @type string $heading_list Screen reader text for the items list heading.
697 * Default 'Items list'.
700 public function set_screen_reader_content( $content = array() ) {
702 'heading_views' => __( 'Filter items list' ),
703 'heading_pagination' => __( 'Items list navigation' ),
704 'heading_list' => __( 'Items list' ),
706 $content = wp_parse_args( $content, $defaults );
708 $this->_screen_reader_content = $content;
712 * Remove all the accessible hidden headings and text for the screen.
716 public function remove_screen_reader_content() {
717 $this->_screen_reader_content = array();
721 * Render the screen's help section.
723 * This will trigger the deprecated filters for backward compatibility.
727 * @global string $screen_layout_columns
729 public function render_screen_meta() {
732 * Filters the legacy contextual help list.
735 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
736 * get_current_screen()->remove_help_tab() instead.
738 * @param array $old_compat_help Old contextual help.
739 * @param WP_Screen $this Current WP_Screen instance.
741 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
743 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
746 * Filters the legacy contextual help text.
749 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
750 * get_current_screen()->remove_help_tab() instead.
752 * @param string $old_help Help text that appears on the screen.
753 * @param string $screen_id Screen ID.
754 * @param WP_Screen $this Current WP_Screen instance.
757 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
759 // Default help only if there is no old-style block of text and no new-style help tabs.
760 if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
763 * Filters the default legacy contextual help text.
766 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
767 * get_current_screen()->remove_help_tab() instead.
769 * @param string $old_help_default Default contextual help text.
771 $default_help = apply_filters( 'default_contextual_help', '' );
773 $old_help = '<p>' . $default_help . '</p>';
777 $this->add_help_tab( array(
778 'id' => 'old-contextual-help',
779 'title' => __('Overview'),
780 'content' => $old_help,
784 $help_sidebar = $this->get_help_sidebar();
786 $help_class = 'hidden';
787 if ( ! $help_sidebar )
788 $help_class .= ' no-sidebar';
792 <div id="screen-meta" class="metabox-prefs">
794 <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
795 <div id="contextual-help-back"></div>
796 <div id="contextual-help-columns">
797 <div class="contextual-help-tabs">
800 $class = ' class="active"';
801 foreach ( $this->get_help_tabs() as $tab ) :
802 $link_id = "tab-link-{$tab['id']}";
803 $panel_id = "tab-panel-{$tab['id']}";
806 <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
807 <a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">
808 <?php echo esc_html( $tab['title'] ); ?>
818 <?php if ( $help_sidebar ) : ?>
819 <div class="contextual-help-sidebar">
820 <?php echo $help_sidebar; ?>
824 <div class="contextual-help-tabs-wrap">
826 $classes = 'help-tab-content active';
827 foreach ( $this->get_help_tabs() as $tab ):
828 $panel_id = "tab-panel-{$tab['id']}";
831 <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
833 // Print tab content.
834 echo $tab['content'];
836 // If it exists, fire tab callback.
837 if ( ! empty( $tab['callback'] ) )
838 call_user_func_array( $tab['callback'], array( $this, $tab ) );
842 $classes = 'help-tab-content';
849 // Setup layout columns
852 * Filters the array of screen layout columns.
854 * This hook provides back-compat for plugins using the back-compat
855 * Filters instead of add_screen_option().
859 * @param array $empty_columns Empty array.
860 * @param string $screen_id Screen ID.
861 * @param WP_Screen $this Current WP_Screen instance.
863 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
865 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
866 $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
868 if ( $this->get_option( 'layout_columns' ) ) {
869 $this->columns = (int) get_user_option("screen_layout_$this->id");
871 if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
872 $this->columns = $this->get_option( 'layout_columns', 'default' );
874 $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
876 // Add screen options
877 if ( $this->show_screen_options() )
878 $this->render_screen_options();
882 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
885 <div id="screen-meta-links">
886 <?php if ( $this->get_help_tabs() ) : ?>
887 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
888 <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
891 if ( $this->show_screen_options() ) : ?>
892 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
893 <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
902 * @global array $wp_meta_boxes
906 public function show_screen_options() {
907 global $wp_meta_boxes;
909 if ( is_bool( $this->_show_screen_options ) )
910 return $this->_show_screen_options;
912 $columns = get_column_headers( $this );
914 $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
916 switch ( $this->base ) {
918 $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
921 $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
922 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
923 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
924 $this->_screen_settings = $expand;
927 $this->_screen_settings = '';
932 * Filters the screen settings text displayed in the Screen Options tab.
934 * This filter is currently only used on the Widgets screen to enable
935 * accessibility mode.
939 * @param string $screen_settings Screen settings.
940 * @param WP_Screen $this WP_Screen object.
942 $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
944 if ( $this->_screen_settings || $this->_options )
948 * Filters whether to show the Screen Options tab.
952 * @param bool $show_screen Whether to show Screen Options tab.
954 * @param WP_Screen $this Current WP_Screen instance.
956 $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
957 return $this->_show_screen_options;
961 * Render the screen options tab.
965 * @param array $options {
966 * @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true.
969 public function render_screen_options( $options = array() ) {
970 $options = wp_parse_args( $options, array(
974 $wrapper_start = $wrapper_end = $form_start = $form_end = '';
976 // Output optional wrapper.
977 if ( $options['wrap'] ) {
978 $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">';
979 $wrapper_end = '</div>';
982 // Don't output the form and nonce for the widgets accessibility mode links.
983 if ( 'widgets' !== $this->base ) {
984 $form_start = "\n<form id='adv-settings' method='post'>\n";
985 $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
988 echo $wrapper_start . $form_start;
990 $this->render_meta_boxes_preferences();
991 $this->render_list_table_columns_preferences();
992 $this->render_screen_layout();
993 $this->render_per_page_options();
994 $this->render_view_mode();
995 echo $this->_screen_settings;
998 * Filters whether to show the Screen Options submit button.
1002 * @param bool $show_button Whether to show Screen Options submit button.
1004 * @param WP_Screen $this Current WP_Screen instance.
1006 $show_button = apply_filters( 'screen_options_show_submit', false, $this );
1008 if ( $show_button ) {
1009 submit_button( __( 'Apply' ), 'primary', 'screen-options-apply', true );
1012 echo $form_end . $wrapper_end;
1016 * Render the meta boxes preferences.
1020 * @global array $wp_meta_boxes
1022 public function render_meta_boxes_preferences() {
1023 global $wp_meta_boxes;
1025 if ( ! isset( $wp_meta_boxes[ $this->id ] ) ) {
1029 <fieldset class="metabox-prefs">
1030 <legend><?php _e( 'Boxes' ); ?></legend>
1032 meta_box_prefs( $this );
1034 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
1035 if ( isset( $_GET['welcome'] ) ) {
1036 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
1037 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
1039 $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
1040 if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
1041 $welcome_checked = false;
1044 echo '<label for="wp_welcome_panel-hide">';
1045 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
1046 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
1054 * Render the list table columns preferences.
1058 public function render_list_table_columns_preferences() {
1060 $columns = get_column_headers( $this );
1061 $hidden = get_hidden_columns( $this );
1067 $legend = ! empty( $columns['_title'] ) ? $columns['_title'] : __( 'Columns' );
1069 <fieldset class="metabox-prefs">
1070 <legend><?php echo $legend; ?></legend>
1072 $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' );
1074 foreach ( $columns as $column => $title ) {
1075 // Can't hide these for they are special
1076 if ( in_array( $column, $special ) ) {
1080 if ( empty( $title ) ) {
1084 if ( 'comments' == $column ) {
1085 $title = __( 'Comments' );
1088 $id = "$column-hide";
1090 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( ! in_array( $column, $hidden ), true, false ) . ' />';
1091 echo "$title</label>\n";
1099 * Render the option for number of columns on the page
1103 public function render_screen_layout() {
1104 if ( ! $this->get_option( 'layout_columns' ) ) {
1108 $screen_layout_columns = $this->get_columns();
1109 $num = $this->get_option( 'layout_columns', 'max' );
1112 <fieldset class='columns-prefs'>
1113 <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php
1114 for ( $i = 1; $i <= $num; ++$i ):
1116 <label class="columns-prefs-<?php echo $i; ?>">
1117 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
1118 <?php checked( $screen_layout_columns, $i ); ?> />
1119 <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
1128 * Render the items per page option
1132 public function render_per_page_options() {
1133 if ( null === $this->get_option( 'per_page' ) ) {
1137 $per_page_label = $this->get_option( 'per_page', 'label' );
1138 if ( null === $per_page_label ) {
1139 $per_page_label = __( 'Number of items per page:' );
1142 $option = $this->get_option( 'per_page', 'option' );
1144 $option = str_replace( '-', '_', "{$this->id}_per_page" );
1147 $per_page = (int) get_user_option( $option );
1148 if ( empty( $per_page ) || $per_page < 1 ) {
1149 $per_page = $this->get_option( 'per_page', 'default' );
1150 if ( ! $per_page ) {
1155 if ( 'edit_comments_per_page' == $option ) {
1156 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
1158 /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
1159 $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
1160 } elseif ( 'categories_per_page' == $option ) {
1161 /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
1162 $per_page = apply_filters( 'edit_categories_per_page', $per_page );
1164 /** This filter is documented in wp-admin/includes/class-wp-list-table.php */
1165 $per_page = apply_filters( $option, $per_page );
1169 if ( isset( $this->post_type ) ) {
1170 /** This filter is documented in wp-admin/includes/post.php */
1171 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
1174 // This needs a submit button
1175 add_filter( 'screen_options_show_submit', '__return_true' );
1178 <fieldset class="screen-options">
1179 <legend><?php _e( 'Pagination' ); ?></legend>
1180 <?php if ( $per_page_label ) : ?>
1181 <label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
1182 <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
1183 id="<?php echo esc_attr( $option ); ?>" maxlength="3"
1184 value="<?php echo esc_attr( $per_page ); ?>" />
1186 <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
1192 * Render the list table view mode preferences.
1196 public function render_view_mode() {
1197 $screen = get_current_screen();
1199 // Currently only enabled for posts lists
1200 if ( 'edit' !== $screen->base ) {
1204 $view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) );
1207 * Filters the post types that have different view mode options.
1211 * @param array $view_mode_post_types Array of post types that can change view modes.
1212 * Default hierarchical post types with show_ui on.
1214 $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
1216 if ( ! in_array( $this->post_type, $view_mode_post_types ) ) {
1222 // This needs a submit button
1223 add_filter( 'screen_options_show_submit', '__return_true' );
1225 <fieldset class="metabox-prefs view-mode">
1226 <legend><?php _e( 'View Mode' ); ?></legend>
1227 <label for="list-view-mode">
1228 <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
1229 <?php _e( 'List View' ); ?>
1231 <label for="excerpt-view-mode">
1232 <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
1233 <?php _e( 'Excerpt View' ); ?>
1240 * Render screen reader text.
1244 * @param string $key The screen reader text array named key.
1245 * @param string $tag Optional. The HTML tag to wrap the screen reader text. Default h2.
1247 public function render_screen_reader_content( $key = '', $tag = 'h2' ) {
1249 if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
1252 echo "<$tag class='screen-reader-text'>" . $this->_screen_reader_content[ $key ] . "</$tag>";