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.
423 * For backwards compatibility.
429 * @param WP_Screen $screen A screen object.
430 * @param string $help Help text.
432 public static function add_old_compat_help( $screen, $help ) {
433 self::$_old_compat_help[ $screen->id ] = $help;
437 * Set the parent information for the screen.
438 * This is called in admin-header.php after the menu parent for the screen has been determined.
442 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
444 public function set_parentage( $parent_file ) {
445 $this->parent_file = $parent_file;
446 list( $this->parent_base ) = explode( '?', $parent_file );
447 $this->parent_base = str_replace( '.php', '', $this->parent_base );
451 * Adds an option for the screen.
452 * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
456 * @param string $option Option ID
457 * @param mixed $args Option-dependent arguments.
459 public function add_option( $option, $args = array() ) {
460 $this->_options[ $option ] = $args;
464 * Remove an option from the screen.
468 * @param string $option Option ID.
470 public function remove_option( $option ) {
471 unset( $this->_options[ $option ] );
475 * Remove all options from the screen.
479 public function remove_options() {
480 $this->_options = array();
484 * Get the options registered for the screen.
488 * @return array Options with arguments.
490 public function get_options() {
491 return $this->_options;
495 * Gets the arguments for an option for the screen.
499 * @param string $option Option name.
500 * @param string $key Optional. Specific array key for when the option is an array.
502 * @return string The option value if set, null otherwise.
504 public function get_option( $option, $key = false ) {
505 if ( ! isset( $this->_options[ $option ] ) )
508 if ( isset( $this->_options[ $option ][ $key ] ) )
509 return $this->_options[ $option ][ $key ];
512 return $this->_options[ $option ];
516 * Gets the help tabs registered for the screen.
519 * @since 4.4.0 Help tabs are ordered by their priority.
521 * @return array Help tabs with arguments.
523 public function get_help_tabs() {
524 $help_tabs = $this->_help_tabs;
526 $priorities = array();
527 foreach ( $help_tabs as $help_tab ) {
528 if ( isset( $priorities[ $help_tab['priority'] ] ) ) {
529 $priorities[ $help_tab['priority'] ][] = $help_tab;
531 $priorities[ $help_tab['priority'] ] = array( $help_tab );
535 ksort( $priorities );
538 foreach ( $priorities as $list ) {
539 foreach ( $list as $tab ) {
540 $sorted[ $tab['id'] ] = $tab;
548 * Gets the arguments for a help tab.
552 * @param string $id Help Tab ID.
553 * @return array Help tab arguments.
555 public function get_help_tab( $id ) {
556 if ( ! isset( $this->_help_tabs[ $id ] ) )
558 return $this->_help_tabs[ $id ];
562 * Add a help tab to the contextual help for the screen.
563 * Call this on the load-$pagenow hook for the relevant screen.
566 * @since 4.4.0 The `$priority` argument was added.
568 * @param array $args {
569 * Array of arguments used to display the help tab.
571 * @type string $title Title for the tab. Default false.
572 * @type string $id Tab ID. Must be HTML-safe. Default false.
573 * @type string $content Optional. Help tab content in plain text or HTML. Default empty string.
574 * @type string $callback Optional. A callback to generate the tab content. Default false.
575 * @type int $priority Optional. The priority of the tab, used for ordering. Default 10.
578 public function add_help_tab( $args ) {
586 $args = wp_parse_args( $args, $defaults );
588 $args['id'] = sanitize_html_class( $args['id'] );
590 // Ensure we have an ID and title.
591 if ( ! $args['id'] || ! $args['title'] )
594 // Allows for overriding an existing tab with that ID.
595 $this->_help_tabs[ $args['id'] ] = $args;
599 * Removes a help tab from the contextual help for the screen.
603 * @param string $id The help tab ID.
605 public function remove_help_tab( $id ) {
606 unset( $this->_help_tabs[ $id ] );
610 * Removes all help tabs from the contextual help for the screen.
614 public function remove_help_tabs() {
615 $this->_help_tabs = array();
619 * Gets the content from a contextual help sidebar.
623 * @return string Contents of the help sidebar.
625 public function get_help_sidebar() {
626 return $this->_help_sidebar;
630 * Add a sidebar to the contextual help for the screen.
631 * 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.
635 * @param string $content Sidebar content in plain text or HTML.
637 public function set_help_sidebar( $content ) {
638 $this->_help_sidebar = $content;
642 * Gets the number of layout columns the user has selected.
644 * The layout_columns option controls the max number and default number of
645 * columns. This method returns the number of columns within that range selected
646 * by the user via Screen Options. If no selection has been made, the default
647 * provisioned in layout_columns is returned. If the screen does not support
648 * selecting the number of layout columns, 0 is returned.
652 * @return int Number of columns to display.
654 public function get_columns() {
655 return $this->columns;
659 * Get the accessible hidden headings and text used in the screen.
663 * @see set_screen_reader_content() For more information on the array format.
665 * @return array An associative array of screen reader text strings.
667 public function get_screen_reader_content() {
668 return $this->_screen_reader_content;
672 * Get a screen reader text string.
676 * @param string $key Screen reader text array named key.
677 * @return string Screen reader text string.
679 public function get_screen_reader_text( $key ) {
680 if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
683 return $this->_screen_reader_content[ $key ];
687 * Add accessible hidden headings and text for the screen.
691 * @param array $content {
692 * An associative array of screen reader text strings.
694 * @type string $heading_views Screen reader text for the filter links heading.
695 * Default 'Filter items list'.
696 * @type string $heading_pagination Screen reader text for the pagination heading.
697 * Default 'Items list navigation'.
698 * @type string $heading_list Screen reader text for the items list heading.
699 * Default 'Items list'.
702 public function set_screen_reader_content( $content = array() ) {
704 'heading_views' => __( 'Filter items list' ),
705 'heading_pagination' => __( 'Items list navigation' ),
706 'heading_list' => __( 'Items list' ),
708 $content = wp_parse_args( $content, $defaults );
710 $this->_screen_reader_content = $content;
714 * Remove all the accessible hidden headings and text for the screen.
718 public function remove_screen_reader_content() {
719 $this->_screen_reader_content = array();
723 * Render the screen's help section.
725 * This will trigger the deprecated filters for backwards compatibility.
729 * @global string $screen_layout_columns
731 public function render_screen_meta() {
734 * Filter the legacy contextual help list.
737 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
738 * get_current_screen()->remove_help_tab() instead.
740 * @param array $old_compat_help Old contextual help.
741 * @param WP_Screen $this Current WP_Screen instance.
743 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
745 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
748 * Filter the legacy contextual help text.
751 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
752 * get_current_screen()->remove_help_tab() instead.
754 * @param string $old_help Help text that appears on the screen.
755 * @param string $screen_id Screen ID.
756 * @param WP_Screen $this Current WP_Screen instance.
759 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
761 // Default help only if there is no old-style block of text and no new-style help tabs.
762 if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
765 * Filter the default legacy contextual help text.
768 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
769 * get_current_screen()->remove_help_tab() instead.
771 * @param string $old_help_default Default contextual help text.
773 $default_help = apply_filters( 'default_contextual_help', '' );
775 $old_help = '<p>' . $default_help . '</p>';
779 $this->add_help_tab( array(
780 'id' => 'old-contextual-help',
781 'title' => __('Overview'),
782 'content' => $old_help,
786 $help_sidebar = $this->get_help_sidebar();
788 $help_class = 'hidden';
789 if ( ! $help_sidebar )
790 $help_class .= ' no-sidebar';
794 <div id="screen-meta" class="metabox-prefs">
796 <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
797 <div id="contextual-help-back"></div>
798 <div id="contextual-help-columns">
799 <div class="contextual-help-tabs">
802 $class = ' class="active"';
803 foreach ( $this->get_help_tabs() as $tab ) :
804 $link_id = "tab-link-{$tab['id']}";
805 $panel_id = "tab-panel-{$tab['id']}";
808 <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
809 <a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">
810 <?php echo esc_html( $tab['title'] ); ?>
820 <?php if ( $help_sidebar ) : ?>
821 <div class="contextual-help-sidebar">
822 <?php echo $help_sidebar; ?>
826 <div class="contextual-help-tabs-wrap">
828 $classes = 'help-tab-content active';
829 foreach ( $this->get_help_tabs() as $tab ):
830 $panel_id = "tab-panel-{$tab['id']}";
833 <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
835 // Print tab content.
836 echo $tab['content'];
838 // If it exists, fire tab callback.
839 if ( ! empty( $tab['callback'] ) )
840 call_user_func_array( $tab['callback'], array( $this, $tab ) );
844 $classes = 'help-tab-content';
851 // Setup layout columns
854 * Filter the array of screen layout columns.
856 * This hook provides back-compat for plugins using the back-compat
857 * filter instead of add_screen_option().
861 * @param array $empty_columns Empty array.
862 * @param string $screen_id Screen ID.
863 * @param WP_Screen $this Current WP_Screen instance.
865 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
867 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
868 $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
870 if ( $this->get_option( 'layout_columns' ) ) {
871 $this->columns = (int) get_user_option("screen_layout_$this->id");
873 if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
874 $this->columns = $this->get_option( 'layout_columns', 'default' );
876 $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
878 // Add screen options
879 if ( $this->show_screen_options() )
880 $this->render_screen_options();
884 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
887 <div id="screen-meta-links">
888 <?php if ( $this->get_help_tabs() ) : ?>
889 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
890 <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
893 if ( $this->show_screen_options() ) : ?>
894 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
895 <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
904 * @global array $wp_meta_boxes
908 public function show_screen_options() {
909 global $wp_meta_boxes;
911 if ( is_bool( $this->_show_screen_options ) )
912 return $this->_show_screen_options;
914 $columns = get_column_headers( $this );
916 $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
918 switch ( $this->base ) {
920 $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";
923 $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
924 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
925 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
926 $this->_screen_settings = $expand;
929 $this->_screen_settings = '';
934 * Filter the screen settings text displayed in the Screen Options tab.
936 * This filter is currently only used on the Widgets screen to enable
937 * accessibility mode.
941 * @param string $screen_settings Screen settings.
942 * @param WP_Screen $this WP_Screen object.
944 $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
946 if ( $this->_screen_settings || $this->_options )
950 * Filter whether to show the Screen Options tab.
954 * @param bool $show_screen Whether to show Screen Options tab.
956 * @param WP_Screen $this Current WP_Screen instance.
958 $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
959 return $this->_show_screen_options;
963 * Render the screen options tab.
967 * @param array $options {
968 * @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true.
971 public function render_screen_options( $options = array() ) {
972 $options = wp_parse_args( $options, array(
976 $wrapper_start = $wrapper_end = $form_start = $form_end = '';
978 // Output optional wrapper.
979 if ( $options['wrap'] ) {
980 $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">';
981 $wrapper_end = '</div>';
984 // Don't output the form and nonce for the widgets accessibility mode links.
985 if ( 'widgets' !== $this->base ) {
986 $form_start = "\n<form id='adv-settings' method='post'>\n";
987 $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
990 echo $wrapper_start . $form_start;
992 $this->render_meta_boxes_preferences();
993 $this->render_list_table_columns_preferences();
994 $this->render_screen_layout();
995 $this->render_per_page_options();
996 $this->render_view_mode();
997 echo $this->_screen_settings;
1000 * Filter whether to show the Screen Options submit button.
1004 * @param bool $show_button Whether to show Screen Options submit button.
1006 * @param WP_Screen $this Current WP_Screen instance.
1008 $show_button = apply_filters( 'screen_options_show_submit', false, $this );
1010 if ( $show_button ) {
1011 submit_button( __( 'Apply' ), 'primary', 'screen-options-apply', true );
1014 echo $form_end . $wrapper_end;
1018 * Render the meta boxes preferences.
1022 * @global array $wp_meta_boxes
1024 public function render_meta_boxes_preferences() {
1025 global $wp_meta_boxes;
1027 if ( ! isset( $wp_meta_boxes[ $this->id ] ) ) {
1031 <fieldset class="metabox-prefs">
1032 <legend><?php _e( 'Boxes' ); ?></legend>
1034 meta_box_prefs( $this );
1036 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
1037 if ( isset( $_GET['welcome'] ) ) {
1038 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
1039 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
1041 $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
1042 if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
1043 $welcome_checked = false;
1046 echo '<label for="wp_welcome_panel-hide">';
1047 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
1048 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
1056 * Render the list table columns preferences.
1060 public function render_list_table_columns_preferences() {
1062 $columns = get_column_headers( $this );
1063 $hidden = get_hidden_columns( $this );
1069 $legend = ! empty( $columns['_title'] ) ? $columns['_title'] : __( 'Columns' );
1071 <fieldset class="metabox-prefs">
1072 <legend><?php echo $legend; ?></legend>
1074 $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' );
1076 foreach ( $columns as $column => $title ) {
1077 // Can't hide these for they are special
1078 if ( in_array( $column, $special ) ) {
1082 if ( empty( $title ) ) {
1086 if ( 'comments' == $column ) {
1087 $title = __( 'Comments' );
1090 $id = "$column-hide";
1092 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( ! in_array( $column, $hidden ), true, false ) . ' />';
1093 echo "$title</label>\n";
1101 * Render the option for number of columns on the page
1105 public function render_screen_layout() {
1106 if ( ! $this->get_option( 'layout_columns' ) ) {
1110 $screen_layout_columns = $this->get_columns();
1111 $num = $this->get_option( 'layout_columns', 'max' );
1114 <fieldset class='columns-prefs'>
1115 <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php
1116 for ( $i = 1; $i <= $num; ++$i ):
1118 <label class="columns-prefs-<?php echo $i; ?>">
1119 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
1120 <?php checked( $screen_layout_columns, $i ); ?> />
1121 <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
1130 * Render the items per page option
1134 public function render_per_page_options() {
1135 if ( null === $this->get_option( 'per_page' ) ) {
1139 $per_page_label = $this->get_option( 'per_page', 'label' );
1140 if ( null === $per_page_label ) {
1141 $per_page_label = __( 'Number of items per page:' );
1144 $option = $this->get_option( 'per_page', 'option' );
1146 $option = str_replace( '-', '_', "{$this->id}_per_page" );
1149 $per_page = (int) get_user_option( $option );
1150 if ( empty( $per_page ) || $per_page < 1 ) {
1151 $per_page = $this->get_option( 'per_page', 'default' );
1152 if ( ! $per_page ) {
1157 if ( 'edit_comments_per_page' == $option ) {
1158 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
1160 /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
1161 $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
1162 } elseif ( 'categories_per_page' == $option ) {
1163 /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
1164 $per_page = apply_filters( 'edit_categories_per_page', $per_page );
1166 /** This filter is documented in wp-admin/includes/class-wp-list-table.php */
1167 $per_page = apply_filters( $option, $per_page );
1171 if ( isset( $this->post_type ) ) {
1172 /** This filter is documented in wp-admin/includes/post.php */
1173 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
1176 // This needs a submit button
1177 add_filter( 'screen_options_show_submit', '__return_true' );
1180 <fieldset class="screen-options">
1181 <legend><?php _e( 'Pagination' ); ?></legend>
1182 <?php if ( $per_page_label ) : ?>
1183 <label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
1184 <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
1185 id="<?php echo esc_attr( $option ); ?>" maxlength="3"
1186 value="<?php echo esc_attr( $per_page ); ?>" />
1188 <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
1194 * Render the list table view mode preferences.
1198 public function render_view_mode() {
1199 $screen = get_current_screen();
1201 // Currently only enabled for posts lists
1202 if ( 'edit' !== $screen->base ) {
1206 $view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) );
1209 * Filter the post types that have different view mode options.
1213 * @param array $view_mode_post_types Array of post types that can change view modes.
1214 * Default hierarchical post types with show_ui on.
1216 $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
1218 if ( ! in_array( $this->post_type, $view_mode_post_types ) ) {
1224 // This needs a submit button
1225 add_filter( 'screen_options_show_submit', '__return_true' );
1227 <fieldset class="metabox-prefs view-mode">
1228 <legend><?php _e( 'View Mode' ); ?></legend>
1229 <label for="list-view-mode">
1230 <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
1231 <?php _e( 'List View' ); ?>
1233 <label for="excerpt-view-mode">
1234 <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
1235 <?php _e( 'Excerpt View' ); ?>
1242 * Render screen reader text.
1246 * @param string $key The screen reader text array named key.
1247 * @param string $tag Optional. The HTML tag to wrap the screen reader text. Default h2.
1249 public function render_screen_reader_content( $key = '', $tag = 'h2' ) {
1251 if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
1254 echo "<$tag class='screen-reader-text'>" . $this->_screen_reader_content[ $key ] . "</$tag>";