]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/screen.php
Wordpress 3.3.1-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / screen.php
1 <?php
2 /**
3  * WordPress Administration Screen API.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /**
10  * Get the column headers for a screen
11  *
12  * @since 2.7.0
13  *
14  * @param string|WP_Screen $screen The screen you want the headers for
15  * @return array Containing the headers in the format id => UI String
16  */
17 function get_column_headers( $screen ) {
18         if ( is_string( $screen ) )
19                 $screen = convert_to_screen( $screen );
20
21         static $column_headers = array();
22
23         if ( ! isset( $column_headers[ $screen->id ] ) )
24                 $column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
25
26         return $column_headers[ $screen->id ];
27 }
28
29 /**
30  * Get a list of hidden columns.
31  *
32  * @since 2.7.0
33  *
34  * @param string|WP_Screen $screen The screen you want the hidden columns for
35  * @return array
36  */
37 function get_hidden_columns( $screen ) {
38         if ( is_string( $screen ) )
39                 $screen = convert_to_screen( $screen );
40
41         return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' );
42 }
43
44 /**
45  * Prints the meta box preferences for screen meta.
46  *
47  * @since 2.7.0
48  *
49  * @param string|WP_Screen $screen
50  */
51 function meta_box_prefs( $screen ) {
52         global $wp_meta_boxes;
53
54         if ( is_string( $screen ) )
55                 $screen = convert_to_screen( $screen );
56
57         if ( empty($wp_meta_boxes[$screen->id]) )
58                 return;
59
60         $hidden = get_hidden_meta_boxes($screen);
61
62         foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
63                 foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
64                         foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
65                                 if ( false == $box || ! $box['title'] )
66                                         continue;
67                                 // Submit box cannot be hidden
68                                 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
69                                         continue;
70                                 $box_id = $box['id'];
71                                 echo '<label for="' . $box_id . '-hide">';
72                                 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"' : '') . ' />';
73                                 echo "{$box['title']}</label>\n";
74                         }
75                 }
76         }
77 }
78
79 /**
80  * Get Hidden Meta Boxes
81  *
82  * @since 2.7.0
83  *
84  * @param string|WP_Screen $screen Screen identifier
85  * @return array Hidden Meta Boxes
86  */
87 function get_hidden_meta_boxes( $screen ) {
88         if ( is_string( $screen ) )
89                 $screen = convert_to_screen( $screen );
90
91         $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
92
93         $use_defaults = ! is_array( $hidden );
94
95         // Hide slug boxes by default
96         if ( $use_defaults ) {
97                 $hidden = array();
98                 if ( 'post' == $screen->base ) {
99                         if ( 'post' == $screen->post_type || 'page' == $screen->post_type )
100                                 $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
101                         else
102                                 $hidden = array( 'slugdiv' );
103                 }
104                 $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
105         }
106
107         return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
108 }
109
110 /**
111  * Register and configure an admin screen option
112  *
113  * @since 3.1.0
114  *
115  * @param string $option An option name.
116  * @param mixed $args Option-dependent arguments.
117  * @return void
118  */
119 function add_screen_option( $option, $args = array() ) {
120         $current_screen = get_current_screen();
121
122         if ( ! $current_screen )
123                 return;
124
125         $current_screen->add_option( $option, $args );
126 }
127
128 /**
129  * Displays a screen icon.
130  *
131  * @uses get_screen_icon()
132  * @since 2.7.0
133  *
134  * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
135  *      which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
136  */
137 function screen_icon( $screen = '' ) {
138         echo get_screen_icon( $screen );
139 }
140
141 /**
142  * Gets a screen icon.
143  *
144  * @since 3.2.0
145  *
146  * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
147  *      which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
148  * @return string HTML for the screen icon.
149  */
150 function get_screen_icon( $screen = '' ) {
151         if ( empty( $screen ) )
152                 $screen = get_current_screen();
153         elseif ( is_string( $screen ) )
154                 $icon_id = $screen;
155
156         $class = 'icon32';
157
158         if ( empty( $icon_id ) ) {
159                 if ( ! empty( $screen->parent_base ) )
160                         $icon_id = $screen->parent_base;
161                 else
162                         $icon_id = $screen->base;
163
164                 if ( 'page' == $screen->post_type )
165                         $icon_id = 'edit-pages';
166
167                 if ( $screen->post_type )
168                         $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen->post_type );
169         }
170
171         return '<div id="icon-' . esc_attr( $icon_id ) . '" class="' . $class . '"><br /></div>';
172 }
173
174 /**
175  * Get the current screen object
176  *
177  * @since 3.1.0
178  *
179  * @return object Current screen object
180  */
181 function get_current_screen() {
182         global $current_screen;
183
184         if ( ! isset( $current_screen ) )
185                 return null;
186
187         return $current_screen;
188 }
189
190 /**
191  * Set the current screen object
192  *
193  * @since 3.0.0
194  * @uses $current_screen
195  *
196  * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
197  *      or an existing screen object.
198  */
199 function set_current_screen( $hook_name =  '' ) {
200         WP_Screen::get( $hook_name )->set_current_screen();
201 }
202
203 /**
204  * A class representing the admin screen.
205  *
206  * @since 3.3.0
207  * @access public
208  */
209 final class WP_Screen {
210         /**
211          * Any action associated with the screen. 'add' for *-add.php and *-new.php screens.  Empty otherwise.
212          *
213          * @since 3.3.0
214          * @var string
215          * @access public
216          */
217         public $action;
218
219         /**
220          * The base type of the screen.  This is typically the same as $id but with any post types and taxonomies stripped.
221          * For example, for an $id of 'edit-post' the base is 'edit'.
222          *
223          * @since 3.3.0
224          * @var string
225          * @access public
226          */
227         public $base;
228
229         /**
230          * The unique ID of the screen.
231          *
232          * @since 3.3.0
233          * @var string
234          * @access public
235          */
236         public $id;
237
238         /**
239          * Whether the screen is in the network admin.
240          *
241          * @since 3.3.0
242          * @var bool
243          * @access public
244          */
245         public $is_network;
246
247         /**
248          * Whether the screen is in the user admin.
249          *
250          * @since 3.3.0
251          * @var bool
252          * @access public
253          */
254         public $is_user;
255
256         /**
257          * The base menu parent.
258          * This is derived from $parent_file by removing the query string and any .php extension.
259          * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
260          *
261          * @since 3.3.0
262          * @var string
263          * @access public
264          */
265         public $parent_base;
266
267         /**
268          * The parent_file for the screen per the admin menu system.
269          * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
270          *
271          * @since 3.3.0
272          * @var string
273          * @access public
274          */
275         public $parent_file;
276
277         /**
278          * The post type associated with the screen, if any.
279          * The 'edit.php?post_type=page' screen has a post type of 'page'.
280          * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
281          *
282          * @since 3.3.0
283          * @var string
284          * @access public
285          */
286         public $post_type;
287
288         /**
289          * The taxonomy associated with the screen, if any.
290          * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
291          * @since 3.3.0
292          * @var string
293          * @access public
294          */
295         public $taxonomy;
296
297         /**
298          * The help tab data associated with the screen, if any.
299          *
300          * @since 3.3.0
301          * @var array
302          * @access private
303          */
304         private $_help_tabs = array();
305
306         /**
307          * The help sidebar data associated with screen, if any.
308          *
309          * @since 3.3.0
310          * @var string
311          * @access private
312          */
313         private $_help_sidebar = '';
314
315         /**
316          * Stores old string-based help.
317          */
318         private static $_old_compat_help = array();
319
320         /**
321          * The screen options associated with screen, if any.
322          *
323          * @since 3.3.0
324          * @var array
325          * @access private
326          */
327         private $_options = array();
328
329         /**
330          * The screen object registry.
331          *
332          * @since 3.3.0
333          * @var array
334          * @access private
335          */
336         private static $_registry = array();
337
338         /**
339          * Stores the result of the public show_screen_options function.
340          *
341          * @since 3.3.0
342          * @var bool
343          * @access private
344          */
345         private $_show_screen_options;
346
347         /**
348          * Stores the 'screen_settings' section of screen options.
349          *
350          * @since 3.3.0
351          * @var string
352          * @access private
353          */
354         private $_screen_settings;
355
356         /**
357          * Fetches a screen object.
358          *
359          * @since 3.3.0
360          * @access public
361          *
362          * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
363          *      Defaults to the current $hook_suffix global.
364          * @return WP_Screen Screen object.
365          */
366         public static function get( $hook_name = '' ) {
367
368                 if ( is_a( $hook_name, 'WP_Screen' ) )
369                         return $hook_name;
370
371                 $post_type = $taxonomy = null;
372                 $is_network = $is_user = false;
373                 $action = '';
374
375                 if ( $hook_name )
376                         $id = $hook_name;
377                 else
378                         $id = $GLOBALS['hook_suffix'];
379
380                 // For those pesky meta boxes.
381                 if ( $hook_name && post_type_exists( $hook_name ) ) {
382                         $post_type = $id;
383                         $id = 'post'; // changes later. ends up being $base.
384                 } else {
385                         if ( '.php' == substr( $id, -4 ) )
386                                 $id = substr( $id, 0, -4 );
387
388                         if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
389                                 $id = substr( $id, 0, -4 );
390                                 $action = 'add';
391                         }
392                 }
393
394                 if ( ! $post_type && $hook_name ) {
395                         if ( '-network' == substr( $id, -8 ) ) {
396                                 $id = substr( $id, 0, -8 );
397                                 $is_network = true;
398                         } elseif ( '-user' == substr( $id, -5 ) ) {
399                                 $id = substr( $id, 0, -5 );
400                                 $is_user = true;
401                         }
402
403                         $id = sanitize_key( $id );
404                         if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
405                                 $maybe = substr( $id, 5 );
406                                 if ( taxonomy_exists( $maybe ) ) {
407                                         $id = 'edit-tags';
408                                         $taxonomy = $maybe;
409                                 } elseif ( post_type_exists( $maybe ) ) {
410                                         $id = 'edit';
411                                         $post_type = $maybe;
412                                 }
413                         }
414                 } else {
415                         $is_network = is_network_admin();
416                         $is_user = is_user_admin();
417                 }
418
419                 if ( 'index' == $id )
420                         $id = 'dashboard';
421
422                 $base = $id;
423
424                 // If this is the current screen, see if we can be more accurate for post types and taxonomies.
425                 if ( ! $hook_name ) {
426                         if ( isset( $_REQUEST['post_type'] ) )
427                                 $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
428                         if ( isset( $_REQUEST['taxonomy'] ) )
429                                 $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
430
431                         switch ( $base ) {
432                                 case 'post' :
433                                         if ( isset( $_GET['post'] ) )
434                                                 $post_id = (int) $_GET['post'];
435                                         elseif ( isset( $_POST['post_ID'] ) )
436                                                 $post_id = (int) $_POST['post_ID'];
437                                         else
438                                                 $post_id = 0;
439
440                                         if ( $post_id ) {
441                                                 $post = get_post( $post_id );
442                                                 if ( $post )
443                                                         $post_type = $post->post_type;
444                                         }
445                                         break;
446                                 case 'edit-tags' :
447                                         if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
448                                                 $post_type = 'post';
449                                         break;
450                         }
451                 }
452
453                 switch ( $base ) {
454                         case 'post' :
455                                 if ( null === $post_type )
456                                         $post_type = 'post';
457                                 $id = $post_type;
458                                 break;
459                         case 'edit' :
460                                 if ( null === $post_type )
461                                         $post_type = 'post';
462                                 $id .= '-' . $post_type;
463                                 break;
464                         case 'edit-tags' :
465                                 if ( null === $taxonomy )
466                                         $taxonomy = 'post_tag';
467                                 $id = 'edit-' . $taxonomy;
468                                 break;
469                 }
470
471                 if ( $is_network ) {
472                         $id   .= '-network';
473                         $base .= '-network';
474                 } elseif ( $is_user ) {
475                         $id   .= '-user';
476                         $base .= '-user';
477                 }
478
479                 if ( isset( self::$_registry[ $id ] ) ) {
480                         $screen = self::$_registry[ $id ];
481                         if ( $screen === get_current_screen() )
482                                 return $screen;
483                 } else {
484                         $screen = new WP_Screen();
485                         $screen->id     = $id;
486                 }
487
488                 $screen->base       = $base;
489                 $screen->action     = $action;
490                 $screen->post_type  = (string) $post_type;
491                 $screen->taxonomy   = (string) $taxonomy;
492                 $screen->is_user    = $is_user;
493                 $screen->is_network = $is_network;
494
495                 self::$_registry[ $id ] = $screen;
496
497                 return $screen;
498         }
499
500         /**
501          * Makes the screen object the current screen.
502          *
503          * @see set_current_screen()
504          * @since 3.3.0
505          */
506         function set_current_screen() {
507                 global $current_screen, $taxnow, $typenow;
508                 $current_screen = $this;
509                 $taxnow = $this->taxonomy;
510                 $typenow = $this->post_type;
511                 do_action( 'current_screen', $current_screen );
512         }
513
514         /**
515          * Constructor
516          *
517          * @since 3.3.0
518          * @access private
519          */
520         private function __construct() {}
521
522         /**
523          * Sets the old string-based contextual help for the screen.
524          *
525          * For backwards compatibility.
526          *
527          * @since 3.3.0
528          *
529          * @param WP_Screen $screen A screen object.
530          * @param string $help Help text.
531          */
532         static function add_old_compat_help( $screen, $help ) {
533                 self::$_old_compat_help[ $screen->id ] = $help;
534         }
535
536         /**
537          * Set the parent information for the screen.
538          * This is called in admin-header.php after the menu parent for the screen has been determined.
539          *
540          * @since 3.3.0
541          *
542          * @param string $parent_file The parent file of the screen.  Typically the $parent_file global.
543          */
544         function set_parentage( $parent_file ) {
545                 $this->parent_file = $parent_file;
546                 list( $this->parent_base ) = explode( '?', $parent_file );
547                 $this->parent_base = str_replace( '.php', '', $this->parent_base );
548         }
549
550         /**
551          * Adds an option for the screen.
552          * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
553          *
554          * @since 3.3.0
555          *
556          * @param string $option Option ID
557          * @param mixed $args Option-dependent arguments.
558          */
559         public function add_option( $option, $args = array() ) {
560                 $this->_options[ $option ] = $args;
561         }
562
563         /**
564          * Gets the arguments for an option for the screen.
565          *
566          * @since 3.3.0
567          *
568          * @param string
569          */
570         public function get_option( $option, $key = false ) {
571                 if ( ! isset( $this->_options[ $option ] ) )
572                         return null;
573                 if ( $key ) {
574                         if ( isset( $this->_options[ $option ][ $key ] ) )
575                                 return $this->_options[ $option ][ $key ];
576                         return null;
577                 }
578                 return $this->_options[ $option ];
579         }
580
581         /**
582          * Add a help tab to the contextual help for the screen.
583          * Call this on the load-$pagenow hook for the relevant screen.
584          *
585          * @since 3.3.0
586          *
587          * @param array $args
588          * - string   - title    - Title for the tab.
589          * - string   - id       - Tab ID. Must be HTML-safe.
590          * - string   - content  - Help tab content in plain text or HTML. Optional.
591          * - callback - callback - A callback to generate the tab content. Optional.
592          *
593          */
594         public function add_help_tab( $args ) {
595                 $defaults = array(
596                         'title'    => false,
597                         'id'       => false,
598                         'content'  => '',
599                         'callback' => false,
600                 );
601                 $args = wp_parse_args( $args, $defaults );
602
603                 $args['id'] = sanitize_html_class( $args['id'] );
604
605                 // Ensure we have an ID and title.
606                 if ( ! $args['id'] || ! $args['title'] )
607                         return;
608
609                 $this->_help_tabs[] = $args;
610         }
611
612         /**
613          * Removes a help tab from the contextual help for the screen.
614          *
615          * @since 3.3.0
616          *
617          * @param string $id The help tab ID.
618          */
619         public function remove_help_tab( $id ) {
620                 unset( $this->_help_tabs[ $id ] );
621         }
622
623         /**
624          * Removes all help tabs from the contextual help for the screen.
625          *
626          * @since 3.3.0
627          */
628         public function remove_help_tabs() {
629                 $this->_help_tabs = array();
630         }
631
632         /**
633          * Add a sidebar to the contextual help for the screen.
634          * 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          *
636          * @since 3.3.0
637          *
638          * @param string $content Sidebar content in plain text or HTML.
639          */
640         public function set_help_sidebar( $content ) {
641                 $this->_help_sidebar = $content;
642         }
643
644         /**
645          * Render the screen's help section.
646          *
647          * This will trigger the deprecated filters for backwards compatibility.
648          *
649          * @since 3.3.0
650          */
651         public function render_screen_meta() {
652
653                 // Call old contextual_help_list filter.
654                 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
655
656                 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
657                 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
658
659                 // Default help only if there is no old-style block of text and no new-style help tabs.
660                 if ( empty( $old_help ) && empty( $this->_help_tabs ) ) {
661                         $default_help = apply_filters( 'default_contextual_help', '' );
662                         if ( $default_help )
663                                 $old_help = '<p>' . $default_help . '</p>';
664                 }
665
666                 if ( $old_help ) {
667                         $this->add_help_tab( array(
668                                 'id'      => 'old-contextual-help',
669                                 'title'   => __('Overview'),
670                                 'content' => $old_help,
671                         ) );
672                 }
673
674                 $has_sidebar = ! empty( $this->_help_sidebar );
675
676                 $help_class = 'hidden';
677                 if ( ! $has_sidebar )
678                         $help_class .= ' no-sidebar';
679
680                 // Time to render!
681                 ?>
682                 <div id="screen-meta" class="metabox-prefs">
683
684                         <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>">
685                                 <div id="contextual-help-back"></div>
686                                 <div id="contextual-help-columns">
687                                         <div class="contextual-help-tabs">
688                                                 <ul>
689                                                 <?php foreach ( $this->_help_tabs as $i => $tab ):
690                                                         $link_id  = "tab-link-{$tab['id']}";
691                                                         $panel_id = "tab-panel-{$tab['id']}";
692                                                         $classes  = ( $i == 0 ) ? 'active' : '';
693                                                         ?>
694
695                                                         <li id="<?php echo esc_attr( $link_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
696                                                                 <a href="<?php echo esc_url( "#$panel_id" ); ?>">
697                                                                         <?php echo esc_html( $tab['title'] ); ?>
698                                                                 </a>
699                                                         </li>
700                                                 <?php endforeach; ?>
701                                                 </ul>
702                                         </div>
703
704                                         <?php if ( $has_sidebar ) : ?>
705                                         <div class="contextual-help-sidebar">
706                                                 <?php echo self::$this->_help_sidebar; ?>
707                                         </div>
708                                         <?php endif; ?>
709
710                                         <div class="contextual-help-tabs-wrap">
711                                                 <?php foreach ( $this->_help_tabs as $i => $tab ):
712                                                         $panel_id = "tab-panel-{$tab['id']}";
713                                                         $classes  = ( $i == 0 ) ? 'active' : '';
714                                                         $classes .= ' help-tab-content';
715                                                         ?>
716
717                                                         <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
718                                                                 <?php
719                                                                 // Print tab content.
720                                                                 echo $tab['content'];
721
722                                                                 // If it exists, fire tab callback.
723                                                                 if ( ! empty( $tab['callback'] ) )
724                                                                         call_user_func_array( $tab['callback'], array( $this, $tab ) );
725                                                                 ?>
726                                                         </div>
727                                                 <?php endforeach; ?>
728                                         </div>
729                                 </div>
730                         </div>
731                 <?php
732                 // Add screen options
733                 if ( $this->show_screen_options() )
734                         $this->render_screen_options();
735                 ?>
736                 </div>
737                 <?php
738                 if ( ! $this->_help_tabs && ! $this->show_screen_options() )
739                         return;
740                 ?>
741                 <div id="screen-meta-links">
742                 <?php if ( $this->_help_tabs ) : ?>
743                         <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
744                         <a href="#contextual-help-wrap" id="contextual-help-link" class="show-settings"><?php _e( 'Help' ); ?></a>
745                         </div>
746                 <?php endif;
747                 if ( $this->show_screen_options() ) : ?>
748                         <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
749                         <a href="#screen-options-wrap" id="show-settings-link" class="show-settings"><?php _e( 'Screen Options' ); ?></a>
750                         </div>
751                 <?php endif; ?>
752                 </div>
753                 <?php
754         }
755
756         public function show_screen_options() {
757                 global $wp_meta_boxes;
758
759                 if ( is_bool( $this->_show_screen_options ) )
760                         return $this->_show_screen_options;
761
762                 $columns = get_column_headers( $this );
763
764                 $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
765
766                 $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
767
768                 switch ( $this->id ) {
769                         case 'widgets':
770                                 $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";
771                                 break;
772                 }
773
774                 if ( $this->_screen_settings || $this->_options )
775                         $show_screen = true;
776
777                 $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
778                 return $this->_show_screen_options;
779         }
780
781         /**
782          * Render the screen options tab.
783          *
784          * @since 3.3.0
785          */
786         public function render_screen_options() {
787                 global $wp_meta_boxes, $wp_list_table;
788
789                 $columns = get_column_headers( $this );
790                 $hidden  = get_hidden_columns( $this );
791
792                 ?>
793                 <div id="screen-options-wrap" class="hidden">
794                 <form id="adv-settings" action="" method="post">
795                 <?php
796                 if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
797                         <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
798                         <div class="metabox-prefs">
799                                 <?php
800                                         meta_box_prefs( $this );
801
802                                         if ( 'dashboard' === $this->id && current_user_can( 'edit_theme_options' ) ) {
803                                                 if ( isset( $_GET['welcome'] ) ) {
804                                                         $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
805                                                         update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
806                                                 } else {
807                                                         $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
808                                                         if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) )
809                                                                 $welcome_checked = false;
810                                                 }
811                                                 echo '<label for="wp_welcome_panel-hide">';
812                                                 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false )  . ' />';
813                                                 echo __( 'Welcome' ) . "</label>\n";
814                                         }
815                                 ?>
816                                 <br class="clear" />
817                         </div>
818                         <?php endif;
819                         if ( ! empty( $columns ) ) : ?>
820                         <h5><?php echo ( isset( $columns['_title'] ) ?  $columns['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
821                         <div class="metabox-prefs">
822                                 <?php
823                                 $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
824
825                                 foreach ( $columns as $column => $title ) {
826                                         // Can't hide these for they are special
827                                         if ( in_array( $column, $special ) )
828                                                 continue;
829                                         if ( empty( $title ) )
830                                                 continue;
831
832                                         if ( 'comments' == $column )
833                                                 $title = __( 'Comments' );
834                                         $id = "$column-hide";
835                                         echo '<label for="' . $id . '">';
836                                         echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
837                                         echo "$title</label>\n";
838                                 }
839                                 ?>
840                                 <br class="clear" />
841                         </div>
842                 <?php endif;
843
844                 $this->render_screen_layout();
845                 $this->render_per_page_options();
846                 echo $this->_screen_settings;
847
848                 ?>
849                 <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
850                 </form>
851                 </div>
852                 <?php
853         }
854
855         /**
856          * Render the option for number of columns on the page
857          *
858          * @since 3.3.0
859          */
860         function render_screen_layout() {
861                 global $screen_layout_columns;
862
863                 // Back compat for plugins using the filter instead of add_screen_option()
864                 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
865
866                 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
867                         $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
868
869                 if ( ! $this->get_option('layout_columns') ) {
870                         $screen_layout_columns = 0;
871                         return;
872                 }
873
874                 $screen_layout_columns = get_user_option("screen_layout_$this->id");
875                 $num = $this->get_option( 'layout_columns', 'max' );
876
877                 if ( ! $screen_layout_columns || 'auto' == $screen_layout_columns ) {
878                         if ( $this->get_option( 'layout_columns', 'default' ) )
879                                 $screen_layout_columns = $this->get_option( 'layout_columns', 'default' );
880                 }
881
882                 ?>
883                 <h5><?php _e('Screen Layout'); ?></h5>
884                 <div class='columns-prefs'><?php
885                         _e('Number of Columns:');
886                         for ( $i = 1; $i <= $num; ++$i ):
887                                 ?>
888                                 <label>
889                                         <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
890                                                 <?php checked( $screen_layout_columns, $i ); ?> />
891                                         <?php echo esc_html( $i ); ?>
892                                 </label>
893                                 <?php
894                         endfor; ?>
895                 </div>
896                 <?php
897         }
898
899         /**
900          * Render the items per page option
901          *
902          * @since 3.3.0
903          */
904         function render_per_page_options() {
905                 if ( ! $this->get_option( 'per_page' ) )
906                         return;
907
908                 $per_page_label = $this->get_option( 'per_page', 'label' );
909
910                 $option = $this->get_option( 'per_page', 'option' );
911                 if ( ! $option )
912                         $option = str_replace( '-', '_', "{$this->id}_per_page" );
913
914                 $per_page = (int) get_user_option( $option );
915                 if ( empty( $per_page ) || $per_page < 1 ) {
916                         $per_page = $this->get_option( 'per_page', 'default' );
917                         if ( ! $per_page )
918                                 $per_page = 20;
919                 }
920
921                 if ( 'edit_comments_per_page' == $option ) {
922                         $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
923                         $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
924                 } elseif ( 'categories_per_page' == $option ) {
925                         $per_page = apply_filters( 'edit_categories_per_page', $per_page );
926                 } else {
927                         $per_page = apply_filters( $option, $per_page );
928                 }
929
930                 // Back compat
931                 if ( isset( $this->post_type ) )
932                         $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
933
934                 ?>
935                 <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
936                 <div class='screen-options'>
937                         <?php if ( !empty($per_page_label) ): ?>
938                                 <input type='text' class='screen-per-page' name='wp_screen_options[value]'
939                                         id='<?php echo esc_attr( $option ); ?>' maxlength='3'
940                                         value='<?php echo esc_attr( $per_page ); ?>' />
941                                 <label for='<?php echo esc_attr( $option ); ?>'>
942                                         <?php echo esc_html( $per_page_label ); ?>
943                                 </label>
944                         <?php endif;
945
946                         echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
947                         <input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' />
948                 </div>
949                 <?php
950         }
951 }