3 * WordPress Administration Screen API.
6 * @subpackage Administration
10 * Get the column headers for a screen
14 * @staticvar array $column_headers
16 * @param string|WP_Screen $screen The screen you want the headers for
17 * @return array Containing the headers in the format id => UI String
19 function get_column_headers( $screen ) {
20 if ( is_string( $screen ) )
21 $screen = convert_to_screen( $screen );
23 static $column_headers = array();
25 if ( ! isset( $column_headers[ $screen->id ] ) ) {
28 * Filter the column headers for a list table on a specific screen.
30 * The dynamic portion of the hook name, `$screen->id`, refers to the
31 * ID of a specific screen. For example, the screen ID for the Posts
32 * list table is edit-post, so the filter for that screen would be
33 * manage_edit-post_columns.
37 * @param array $columns An array of column headers. Default empty.
39 $column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
42 return $column_headers[ $screen->id ];
46 * Get a list of hidden columns.
50 * @param string|WP_Screen $screen The screen you want the hidden columns for
53 function get_hidden_columns( $screen ) {
54 if ( is_string( $screen ) )
55 $screen = convert_to_screen( $screen );
57 return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' );
61 * Prints the meta box preferences for screen meta.
65 * @global array $wp_meta_boxes
67 * @param WP_Screen $screen
69 function meta_box_prefs( $screen ) {
70 global $wp_meta_boxes;
72 if ( is_string( $screen ) )
73 $screen = convert_to_screen( $screen );
75 if ( empty($wp_meta_boxes[$screen->id]) )
78 $hidden = get_hidden_meta_boxes($screen);
80 foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
81 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
82 if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
85 foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
86 if ( false == $box || ! $box['title'] )
88 // Submit box cannot be hidden
89 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
92 echo '<label for="' . $box_id . '-hide">';
93 echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
94 echo "{$box['title']}</label>\n";
101 * Get Hidden Meta Boxes
105 * @param string|WP_Screen $screen Screen identifier
106 * @return array Hidden Meta Boxes
108 function get_hidden_meta_boxes( $screen ) {
109 if ( is_string( $screen ) )
110 $screen = convert_to_screen( $screen );
112 $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
114 $use_defaults = ! is_array( $hidden );
116 // Hide slug boxes by default
117 if ( $use_defaults ) {
119 if ( 'post' == $screen->base ) {
120 if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
121 $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
123 $hidden = array( 'slugdiv' );
127 * Filter the default list of hidden meta boxes.
131 * @param array $hidden An array of meta boxes hidden by default.
132 * @param WP_Screen $screen WP_Screen object of the current screen.
134 $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
138 * Filter the list of hidden meta boxes.
142 * @param array $hidden An array of hidden meta boxes.
143 * @param WP_Screen $screen WP_Screen object of the current screen.
144 * @param bool $use_defaults Whether to show the default meta boxes.
147 return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
151 * Register and configure an admin screen option
155 * @param string $option An option name.
156 * @param mixed $args Option-dependent arguments.
158 function add_screen_option( $option, $args = array() ) {
159 $current_screen = get_current_screen();
161 if ( ! $current_screen )
164 $current_screen->add_option( $option, $args );
168 * Get the current screen object
172 * @global WP_Screen $current_screen
174 * @return WP_Screen Current screen object
176 function get_current_screen() {
177 global $current_screen;
179 if ( ! isset( $current_screen ) )
182 return $current_screen;
186 * Set the current screen object
190 * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
191 * or an existing screen object.
193 function set_current_screen( $hook_name = '' ) {
194 WP_Screen::get( $hook_name )->set_current_screen();
198 * A class representing the admin screen.
203 final class WP_Screen {
205 * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
214 * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
215 * For example, for an $id of 'edit-post' the base is 'edit'.
224 * The number of columns to display. Access with get_columns().
230 private $columns = 0;
233 * The unique ID of the screen.
242 * Which admin the screen is in. network | user | site | false
251 * Whether the screen is in the network admin.
253 * Deprecated. Use in_admin() instead.
263 * Whether the screen is in the user admin.
265 * Deprecated. Use in_admin() instead.
275 * The base menu parent.
276 * This is derived from $parent_file by removing the query string and any .php extension.
277 * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
286 * The parent_file for the screen per the admin menu system.
287 * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
296 * The post type associated with the screen, if any.
297 * The 'edit.php?post_type=page' screen has a post type of 'page'.
298 * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
307 * The taxonomy associated with the screen, if any.
308 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
316 * The help tab data associated with the screen, if any.
322 private $_help_tabs = array();
325 * The help sidebar data associated with screen, if any.
331 private $_help_sidebar = '';
334 * Stores old string-based help.
341 private static $_old_compat_help = array();
344 * The screen options associated with screen, if any.
350 private $_options = array();
353 * The screen object registry.
362 private static $_registry = array();
365 * Stores the result of the public show_screen_options function.
371 private $_show_screen_options;
374 * Stores the 'screen_settings' section of screen options.
380 private $_screen_settings;
383 * Fetches a screen object.
390 * @global string $hook_suffix
392 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
393 * Defaults to the current $hook_suffix global.
394 * @return WP_Screen Screen object.
396 public static function get( $hook_name = '' ) {
397 if ( $hook_name instanceof WP_Screen ) {
401 $post_type = $taxonomy = null;
408 $id = $GLOBALS['hook_suffix'];
410 // For those pesky meta boxes.
411 if ( $hook_name && post_type_exists( $hook_name ) ) {
413 $id = 'post'; // changes later. ends up being $base.
415 if ( '.php' == substr( $id, -4 ) )
416 $id = substr( $id, 0, -4 );
418 if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
419 $id = substr( $id, 0, -4 );
424 if ( ! $post_type && $hook_name ) {
425 if ( '-network' == substr( $id, -8 ) ) {
426 $id = substr( $id, 0, -8 );
427 $in_admin = 'network';
428 } elseif ( '-user' == substr( $id, -5 ) ) {
429 $id = substr( $id, 0, -5 );
433 $id = sanitize_key( $id );
434 if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
435 $maybe = substr( $id, 5 );
436 if ( taxonomy_exists( $maybe ) ) {
439 } elseif ( post_type_exists( $maybe ) ) {
448 if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
449 $in_admin = 'network';
450 elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
456 if ( 'index' == $id )
458 elseif ( 'front' == $id )
463 // If this is the current screen, see if we can be more accurate for post types and taxonomies.
464 if ( ! $hook_name ) {
465 if ( isset( $_REQUEST['post_type'] ) )
466 $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
467 if ( isset( $_REQUEST['taxonomy'] ) )
468 $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
472 if ( isset( $_GET['post'] ) )
473 $post_id = (int) $_GET['post'];
474 elseif ( isset( $_POST['post_ID'] ) )
475 $post_id = (int) $_POST['post_ID'];
480 $post = get_post( $post_id );
482 $post_type = $post->post_type;
486 if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
494 if ( null === $post_type )
499 if ( null === $post_type )
501 $id .= '-' . $post_type;
504 if ( null === $taxonomy )
505 $taxonomy = 'post_tag';
506 // The edit-tags ID does not contain the post type. Look for it in the request.
507 if ( null === $post_type ) {
509 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
510 $post_type = $_REQUEST['post_type'];
513 $id = 'edit-' . $taxonomy;
517 if ( 'network' == $in_admin ) {
520 } elseif ( 'user' == $in_admin ) {
525 if ( isset( self::$_registry[ $id ] ) ) {
526 $screen = self::$_registry[ $id ];
527 if ( $screen === get_current_screen() )
530 $screen = new WP_Screen();
534 $screen->base = $base;
535 $screen->action = $action;
536 $screen->post_type = (string) $post_type;
537 $screen->taxonomy = (string) $taxonomy;
538 $screen->is_user = ( 'user' == $in_admin );
539 $screen->is_network = ( 'network' == $in_admin );
540 $screen->in_admin = $in_admin;
542 self::$_registry[ $id ] = $screen;
548 * Makes the screen object the current screen.
550 * @see set_current_screen()
553 * @global WP_Screen $current_screen
554 * @global string $taxnow
555 * @global string $typenow
557 public function set_current_screen() {
558 global $current_screen, $taxnow, $typenow;
559 $current_screen = $this;
560 $taxnow = $this->taxonomy;
561 $typenow = $this->post_type;
564 * Fires after the current screen has been set.
568 * @param WP_Screen $current_screen Current WP_Screen object.
570 do_action( 'current_screen', $current_screen );
579 private function __construct() {}
582 * Indicates whether the screen is in a particular admin
586 * @param string $admin The admin to check against (network | user | site).
587 * If empty any of the three admins will result in true.
588 * @return bool True if the screen is in the indicated admin, false otherwise.
590 public function in_admin( $admin = null ) {
591 if ( empty( $admin ) )
592 return (bool) $this->in_admin;
594 return ( $admin == $this->in_admin );
598 * Sets the old string-based contextual help for the screen.
600 * For backwards compatibility.
606 * @param WP_Screen $screen A screen object.
607 * @param string $help Help text.
609 public static function add_old_compat_help( $screen, $help ) {
610 self::$_old_compat_help[ $screen->id ] = $help;
614 * Set the parent information for the screen.
615 * This is called in admin-header.php after the menu parent for the screen has been determined.
619 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
621 public function set_parentage( $parent_file ) {
622 $this->parent_file = $parent_file;
623 list( $this->parent_base ) = explode( '?', $parent_file );
624 $this->parent_base = str_replace( '.php', '', $this->parent_base );
628 * Adds an option for the screen.
629 * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
633 * @param string $option Option ID
634 * @param mixed $args Option-dependent arguments.
636 public function add_option( $option, $args = array() ) {
637 $this->_options[ $option ] = $args;
641 * Remove an option from the screen.
645 * @param string $option Option ID.
647 public function remove_option( $option ) {
648 unset( $this->_options[ $option ] );
652 * Remove all options from the screen.
656 public function remove_options() {
657 $this->_options = array();
661 * Get the options registered for the screen.
665 * @return array Options with arguments.
667 public function get_options() {
668 return $this->_options;
672 * Gets the arguments for an option for the screen.
676 * @param string $option Option name.
677 * @param string $key Optional. Specific array key for when the option is an array.
679 * @return string The option value if set, null otherwise.
681 public function get_option( $option, $key = false ) {
682 if ( ! isset( $this->_options[ $option ] ) )
685 if ( isset( $this->_options[ $option ][ $key ] ) )
686 return $this->_options[ $option ][ $key ];
689 return $this->_options[ $option ];
693 * Gets the help tabs registered for the screen.
697 * @return array Help tabs with arguments.
699 public function get_help_tabs() {
700 return $this->_help_tabs;
704 * Gets the arguments for a help tab.
708 * @param string $id Help Tab ID.
709 * @return array Help tab arguments.
711 public function get_help_tab( $id ) {
712 if ( ! isset( $this->_help_tabs[ $id ] ) )
714 return $this->_help_tabs[ $id ];
718 * Add a help tab to the contextual help for the screen.
719 * Call this on the load-$pagenow hook for the relevant screen.
724 * - string - title - Title for the tab.
725 * - string - id - Tab ID. Must be HTML-safe.
726 * - string - content - Help tab content in plain text or HTML. Optional.
727 * - callback - callback - A callback to generate the tab content. Optional.
730 public function add_help_tab( $args ) {
737 $args = wp_parse_args( $args, $defaults );
739 $args['id'] = sanitize_html_class( $args['id'] );
741 // Ensure we have an ID and title.
742 if ( ! $args['id'] || ! $args['title'] )
745 // Allows for overriding an existing tab with that ID.
746 $this->_help_tabs[ $args['id'] ] = $args;
750 * Removes a help tab from the contextual help for the screen.
754 * @param string $id The help tab ID.
756 public function remove_help_tab( $id ) {
757 unset( $this->_help_tabs[ $id ] );
761 * Removes all help tabs from the contextual help for the screen.
765 public function remove_help_tabs() {
766 $this->_help_tabs = array();
770 * Gets the content from a contextual help sidebar.
774 * @return string Contents of the help sidebar.
776 public function get_help_sidebar() {
777 return $this->_help_sidebar;
781 * Add a sidebar to the contextual help for the screen.
782 * 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.
786 * @param string $content Sidebar content in plain text or HTML.
788 public function set_help_sidebar( $content ) {
789 $this->_help_sidebar = $content;
793 * Gets the number of layout columns the user has selected.
795 * The layout_columns option controls the max number and default number of
796 * columns. This method returns the number of columns within that range selected
797 * by the user via Screen Options. If no selection has been made, the default
798 * provisioned in layout_columns is returned. If the screen does not support
799 * selecting the number of layout columns, 0 is returned.
803 * @return int Number of columns to display.
805 public function get_columns() {
806 return $this->columns;
810 * Render the screen's help section.
812 * This will trigger the deprecated filters for backwards compatibility.
816 * @global string $screen_layout_columns
818 public function render_screen_meta() {
821 * Filter the legacy contextual help list.
824 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
825 * get_current_screen()->remove_help_tab() instead.
827 * @param array $old_compat_help Old contextual help.
828 * @param WP_Screen $this Current WP_Screen instance.
830 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
832 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
835 * Filter the legacy contextual help text.
838 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
839 * get_current_screen()->remove_help_tab() instead.
841 * @param string $old_help Help text that appears on the screen.
842 * @param string $screen_id Screen ID.
843 * @param WP_Screen $this Current WP_Screen instance.
846 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
848 // Default help only if there is no old-style block of text and no new-style help tabs.
849 if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
852 * Filter the default legacy contextual help text.
855 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
856 * get_current_screen()->remove_help_tab() instead.
858 * @param string $old_help_default Default contextual help text.
860 $default_help = apply_filters( 'default_contextual_help', '' );
862 $old_help = '<p>' . $default_help . '</p>';
866 $this->add_help_tab( array(
867 'id' => 'old-contextual-help',
868 'title' => __('Overview'),
869 'content' => $old_help,
873 $help_sidebar = $this->get_help_sidebar();
875 $help_class = 'hidden';
876 if ( ! $help_sidebar )
877 $help_class .= ' no-sidebar';
881 <div id="screen-meta" class="metabox-prefs">
883 <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
884 <div id="contextual-help-back"></div>
885 <div id="contextual-help-columns">
886 <div class="contextual-help-tabs">
889 $class = ' class="active"';
890 foreach ( $this->get_help_tabs() as $tab ) :
891 $link_id = "tab-link-{$tab['id']}";
892 $panel_id = "tab-panel-{$tab['id']}";
895 <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
896 <a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">
897 <?php echo esc_html( $tab['title'] ); ?>
907 <?php if ( $help_sidebar ) : ?>
908 <div class="contextual-help-sidebar">
909 <?php echo $help_sidebar; ?>
913 <div class="contextual-help-tabs-wrap">
915 $classes = 'help-tab-content active';
916 foreach ( $this->get_help_tabs() as $tab ):
917 $panel_id = "tab-panel-{$tab['id']}";
920 <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
922 // Print tab content.
923 echo $tab['content'];
925 // If it exists, fire tab callback.
926 if ( ! empty( $tab['callback'] ) )
927 call_user_func_array( $tab['callback'], array( $this, $tab ) );
931 $classes = 'help-tab-content';
938 // Setup layout columns
941 * Filter the array of screen layout columns.
943 * This hook provides back-compat for plugins using the back-compat
944 * filter instead of add_screen_option().
948 * @param array $empty_columns Empty array.
949 * @param string $screen_id Screen ID.
950 * @param WP_Screen $this Current WP_Screen instance.
952 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
954 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
955 $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
957 if ( $this->get_option( 'layout_columns' ) ) {
958 $this->columns = (int) get_user_option("screen_layout_$this->id");
960 if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
961 $this->columns = $this->get_option( 'layout_columns', 'default' );
963 $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
965 // Add screen options
966 if ( $this->show_screen_options() )
967 $this->render_screen_options();
971 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
974 <div id="screen-meta-links">
975 <?php if ( $this->get_help_tabs() ) : ?>
976 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
977 <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
980 if ( $this->show_screen_options() ) : ?>
981 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
982 <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
991 * @global array $wp_meta_boxes
995 public function show_screen_options() {
996 global $wp_meta_boxes;
998 if ( is_bool( $this->_show_screen_options ) )
999 return $this->_show_screen_options;
1001 $columns = get_column_headers( $this );
1003 $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
1005 switch ( $this->base ) {
1007 $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";
1010 $expand = '<div class="editor-expand hidden"><label for="editor-expand-toggle">';
1011 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
1012 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></div>';
1013 $this->_screen_settings = $expand;
1016 $this->_screen_settings = '';
1021 * Filter the screen settings text displayed in the Screen Options tab.
1023 * This filter is currently only used on the Widgets screen to enable
1024 * accessibility mode.
1028 * @param string $screen_settings Screen settings.
1029 * @param WP_Screen $this WP_Screen object.
1031 $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
1033 if ( $this->_screen_settings || $this->_options )
1034 $show_screen = true;
1037 * Filter whether to show the Screen Options tab.
1041 * @param bool $show_screen Whether to show Screen Options tab.
1043 * @param WP_Screen $this Current WP_Screen instance.
1045 $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
1046 return $this->_show_screen_options;
1050 * Render the screen options tab.
1054 * @global array $wp_meta_boxes
1056 public function render_screen_options() {
1057 global $wp_meta_boxes;
1059 $columns = get_column_headers( $this );
1060 $hidden = get_hidden_columns( $this );
1063 <div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>">
1064 <form id="adv-settings" method="post">
1065 <?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
1066 <h5><?php _e( 'Show on screen' ); ?></h5>
1070 if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
1071 <div class="metabox-prefs">
1073 meta_box_prefs( $this );
1075 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
1076 if ( isset( $_GET['welcome'] ) ) {
1077 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
1078 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
1080 $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
1081 if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) )
1082 $welcome_checked = false;
1084 echo '<label for="wp_welcome_panel-hide">';
1085 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
1086 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
1089 <br class="clear" />
1093 if ( ! empty( $columns['_title'] ) ) : ?>
1094 <h5><?php echo $columns['_title']; ?></h5>
1096 <div class="metabox-prefs">
1098 $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
1100 foreach ( $columns as $column => $title ) {
1101 // Can't hide these for they are special
1102 if ( in_array( $column, $special ) )
1104 if ( empty( $title ) )
1107 if ( 'comments' == $column )
1108 $title = __( 'Comments' );
1109 $id = "$column-hide";
1110 echo '<label for="' . $id . '">';
1111 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
1112 echo "$title</label>\n";
1115 <br class="clear" />
1119 $this->render_screen_layout();
1120 $this->render_per_page_options();
1121 echo $this->_screen_settings;
1124 <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
1131 * Render the option for number of columns on the page
1135 public function render_screen_layout() {
1136 if ( ! $this->get_option('layout_columns') )
1139 $screen_layout_columns = $this->get_columns();
1140 $num = $this->get_option( 'layout_columns', 'max' );
1143 <h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>
1144 <div class='columns-prefs'><?php
1145 _e('Number of Columns:');
1146 for ( $i = 1; $i <= $num; ++$i ):
1148 <label class="columns-prefs-<?php echo $i; ?>">
1149 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
1150 <?php checked( $screen_layout_columns, $i ); ?> />
1151 <?php echo esc_html( $i ); ?>
1160 * Render the items per page option
1164 public function render_per_page_options() {
1165 if ( null === $this->get_option( 'per_page' ) ) {
1169 $per_page_label = $this->get_option( 'per_page', 'label' );
1170 if ( null === $per_page_label ) {
1171 $per_page_label = __( 'Number of items per page:' );
1174 $option = $this->get_option( 'per_page', 'option' );
1176 $option = str_replace( '-', '_', "{$this->id}_per_page" );
1179 $per_page = (int) get_user_option( $option );
1180 if ( empty( $per_page ) || $per_page < 1 ) {
1181 $per_page = $this->get_option( 'per_page', 'default' );
1182 if ( ! $per_page ) {
1187 if ( 'edit_comments_per_page' == $option ) {
1188 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
1190 /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
1191 $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
1192 } elseif ( 'categories_per_page' == $option ) {
1193 /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
1194 $per_page = apply_filters( 'edit_categories_per_page', $per_page );
1196 /** This filter is documented in wp-admin/includes/class-wp-list-table.php */
1197 $per_page = apply_filters( $option, $per_page );
1201 if ( isset( $this->post_type ) ) {
1202 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
1203 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
1207 <div class="screen-options">
1208 <?php if ( $per_page_label ) : ?>
1209 <label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
1210 <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
1211 id="<?php echo esc_attr( $option ); ?>" maxlength="3"
1212 value="<?php echo esc_attr( $per_page ); ?>" />
1215 echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
1216 <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />