]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/screen.php
Wordpress 3.5
[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 || 'attachment' == $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  */
118 function add_screen_option( $option, $args = array() ) {
119         $current_screen = get_current_screen();
120
121         if ( ! $current_screen )
122                 return;
123
124         $current_screen->add_option( $option, $args );
125 }
126
127 /**
128  * Displays a screen icon.
129  *
130  * @uses get_screen_icon()
131  * @since 2.7.0
132  *
133  * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
134  *      which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
135  */
136 function screen_icon( $screen = '' ) {
137         echo get_screen_icon( $screen );
138 }
139
140 /**
141  * Gets a screen icon.
142  *
143  * @since 3.2.0
144  *
145  * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
146  *      which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
147  * @return string HTML for the screen icon.
148  */
149 function get_screen_icon( $screen = '' ) {
150         if ( empty( $screen ) )
151                 $screen = get_current_screen();
152         elseif ( is_string( $screen ) )
153                 $icon_id = $screen;
154
155         $class = 'icon32';
156
157         if ( empty( $icon_id ) ) {
158                 if ( ! empty( $screen->parent_base ) )
159                         $icon_id = $screen->parent_base;
160                 else
161                         $icon_id = $screen->base;
162
163                 if ( 'page' == $screen->post_type )
164                         $icon_id = 'edit-pages';
165
166                 if ( $screen->post_type )
167                         $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen->post_type );
168         }
169
170         return '<div id="icon-' . esc_attr( $icon_id ) . '" class="' . $class . '"><br /></div>';
171 }
172
173 /**
174  * Get the current screen object
175  *
176  * @since 3.1.0
177  *
178  * @return WP_Screen Current screen object
179  */
180 function get_current_screen() {
181         global $current_screen;
182
183         if ( ! isset( $current_screen ) )
184                 return null;
185
186         return $current_screen;
187 }
188
189 /**
190  * Set the current screen object
191  *
192  * @since 3.0.0
193  * @uses $current_screen
194  *
195  * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
196  *      or an existing screen object.
197  */
198 function set_current_screen( $hook_name = '' ) {
199         WP_Screen::get( $hook_name )->set_current_screen();
200 }
201
202 /**
203  * A class representing the admin screen.
204  *
205  * @since 3.3.0
206  * @access public
207  */
208 final class WP_Screen {
209         /**
210          * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
211          *
212          * @since 3.3.0
213          * @var string
214          * @access public
215          */
216         public $action;
217
218         /**
219          * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
220          * For example, for an $id of 'edit-post' the base is 'edit'.
221          *
222          * @since 3.3.0
223          * @var string
224          * @access public
225          */
226         public $base;
227
228         /**
229          * The number of columns to display. Access with get_columns().
230          *
231          * @since 3.4.0
232          * @var int
233          * @access private
234          */
235         private $columns = 0;
236
237         /**
238          * The unique ID of the screen.
239          *
240          * @since 3.3.0
241          * @var string
242          * @access public
243          */
244         public $id;
245
246         /**
247          * Which admin the screen is in. network | user | site | false
248          *
249          * @since 3.5.0
250          * @var string
251          * @access protected
252          */
253         protected $in_admin;
254
255         /**
256          * Whether the screen is in the network admin.
257          *
258          * Deprecated. Use in_admin() instead.
259          *
260          * @since 3.3.0
261          * @deprecated 3.5.0
262          * @var bool
263          * @access public
264          */
265         public $is_network;
266
267         /**
268          * Whether the screen is in the user admin.
269          *
270          * Deprecated. Use in_admin() instead.
271          *
272          * @since 3.3.0
273          * @deprecated 3.5.0
274          * @var bool
275          * @access public
276          */
277         public $is_user;
278
279         /**
280          * The base menu parent.
281          * This is derived from $parent_file by removing the query string and any .php extension.
282          * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
283          *
284          * @since 3.3.0
285          * @var string
286          * @access public
287          */
288         public $parent_base;
289
290         /**
291          * The parent_file for the screen per the admin menu system.
292          * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
293          *
294          * @since 3.3.0
295          * @var string
296          * @access public
297          */
298         public $parent_file;
299
300         /**
301          * The post type associated with the screen, if any.
302          * The 'edit.php?post_type=page' screen has a post type of 'page'.
303          * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
304          *
305          * @since 3.3.0
306          * @var string
307          * @access public
308          */
309         public $post_type;
310
311         /**
312          * The taxonomy associated with the screen, if any.
313          * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
314          * @since 3.3.0
315          * @var string
316          * @access public
317          */
318         public $taxonomy;
319
320         /**
321          * The help tab data associated with the screen, if any.
322          *
323          * @since 3.3.0
324          * @var array
325          * @access private
326          */
327         private $_help_tabs = array();
328
329         /**
330          * The help sidebar data associated with screen, if any.
331          *
332          * @since 3.3.0
333          * @var string
334          * @access private
335          */
336         private $_help_sidebar = '';
337
338         /**
339          * Stores old string-based help.
340          */
341         private static $_old_compat_help = array();
342
343         /**
344          * The screen options associated with screen, if any.
345          *
346          * @since 3.3.0
347          * @var array
348          * @access private
349          */
350         private $_options = array();
351
352         /**
353          * The screen object registry.
354          *
355          * @since 3.3.0
356          * @var array
357          * @access private
358          */
359         private static $_registry = array();
360
361         /**
362          * Stores the result of the public show_screen_options function.
363          *
364          * @since 3.3.0
365          * @var bool
366          * @access private
367          */
368         private $_show_screen_options;
369
370         /**
371          * Stores the 'screen_settings' section of screen options.
372          *
373          * @since 3.3.0
374          * @var string
375          * @access private
376          */
377         private $_screen_settings;
378
379         /**
380          * Fetches a screen object.
381          *
382          * @since 3.3.0
383          * @access public
384          *
385          * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
386          *      Defaults to the current $hook_suffix global.
387          * @return WP_Screen Screen object.
388          */
389         public static function get( $hook_name = '' ) {
390
391                 if ( is_a( $hook_name, 'WP_Screen' ) )
392                         return $hook_name;
393
394                 $post_type = $taxonomy = null;
395                 $in_admin = false;
396                 $action = '';
397
398                 if ( $hook_name )
399                         $id = $hook_name;
400                 else
401                         $id = $GLOBALS['hook_suffix'];
402
403                 // For those pesky meta boxes.
404                 if ( $hook_name && post_type_exists( $hook_name ) ) {
405                         $post_type = $id;
406                         $id = 'post'; // changes later. ends up being $base.
407                 } else {
408                         if ( '.php' == substr( $id, -4 ) )
409                                 $id = substr( $id, 0, -4 );
410
411                         if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
412                                 $id = substr( $id, 0, -4 );
413                                 $action = 'add';
414                         }
415                 }
416
417                 if ( ! $post_type && $hook_name ) {
418                         if ( '-network' == substr( $id, -8 ) ) {
419                                 $id = substr( $id, 0, -8 );
420                                 $in_admin = 'network';
421                         } elseif ( '-user' == substr( $id, -5 ) ) {
422                                 $id = substr( $id, 0, -5 );
423                                 $in_admin = 'user';
424                         }
425
426                         $id = sanitize_key( $id );
427                         if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
428                                 $maybe = substr( $id, 5 );
429                                 if ( taxonomy_exists( $maybe ) ) {
430                                         $id = 'edit-tags';
431                                         $taxonomy = $maybe;
432                                 } elseif ( post_type_exists( $maybe ) ) {
433                                         $id = 'edit';
434                                         $post_type = $maybe;
435                                 }
436                         }
437
438                         if ( ! $in_admin )
439                                 $in_admin = 'site';
440                 } else {
441                         if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
442                                 $in_admin = 'network';
443                         elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
444                                 $in_admin = 'user';
445                         else
446                                 $in_admin = 'site';
447                 }
448
449                 if ( 'index' == $id )
450                         $id = 'dashboard';
451                 elseif ( 'front' == $id )
452                         $in_admin = false;
453
454                 $base = $id;
455
456                 // If this is the current screen, see if we can be more accurate for post types and taxonomies.
457                 if ( ! $hook_name ) {
458                         if ( isset( $_REQUEST['post_type'] ) )
459                                 $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
460                         if ( isset( $_REQUEST['taxonomy'] ) )
461                                 $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
462
463                         switch ( $base ) {
464                                 case 'post' :
465                                         if ( isset( $_GET['post'] ) )
466                                                 $post_id = (int) $_GET['post'];
467                                         elseif ( isset( $_POST['post_ID'] ) )
468                                                 $post_id = (int) $_POST['post_ID'];
469                                         else
470                                                 $post_id = 0;
471
472                                         if ( $post_id ) {
473                                                 $post = get_post( $post_id );
474                                                 if ( $post )
475                                                         $post_type = $post->post_type;
476                                         }
477                                         break;
478                                 case 'edit-tags' :
479                                         if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
480                                                 $post_type = 'post';
481                                         break;
482                         }
483                 }
484
485                 switch ( $base ) {
486                         case 'post' :
487                                 if ( null === $post_type )
488                                         $post_type = 'post';
489                                 $id = $post_type;
490                                 break;
491                         case 'edit' :
492                                 if ( null === $post_type )
493                                         $post_type = 'post';
494                                 $id .= '-' . $post_type;
495                                 break;
496                         case 'edit-tags' :
497                                 if ( null === $taxonomy )
498                                         $taxonomy = 'post_tag';
499                                 // The edit-tags ID does not contain the post type. Look for it in the request.
500                                 if ( null === $post_type ) {
501                                         $post_type = 'post';
502                                         if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
503                                                 $post_type = $_REQUEST['post_type'];
504                                 }
505
506                                 $id = 'edit-' . $taxonomy;
507                                 break;
508                 }
509
510                 if ( 'network' == $in_admin ) {
511                         $id   .= '-network';
512                         $base .= '-network';
513                 } elseif ( 'user' == $in_admin ) {
514                         $id   .= '-user';
515                         $base .= '-user';
516                 }
517
518                 if ( isset( self::$_registry[ $id ] ) ) {
519                         $screen = self::$_registry[ $id ];
520                         if ( $screen === get_current_screen() )
521                                 return $screen;
522                 } else {
523                         $screen = new WP_Screen();
524                         $screen->id     = $id;
525                 }
526
527                 $screen->base       = $base;
528                 $screen->action     = $action;
529                 $screen->post_type  = (string) $post_type;
530                 $screen->taxonomy   = (string) $taxonomy;
531                 $screen->is_user    = ( 'user' == $in_admin );
532                 $screen->is_network = ( 'network' == $in_admin );
533                 $screen->in_admin   = $in_admin;
534
535                 self::$_registry[ $id ] = $screen;
536
537                 return $screen;
538         }
539
540         /**
541          * Makes the screen object the current screen.
542          *
543          * @see set_current_screen()
544          * @since 3.3.0
545          */
546         function set_current_screen() {
547                 global $current_screen, $taxnow, $typenow;
548                 $current_screen = $this;
549                 $taxnow = $this->taxonomy;
550                 $typenow = $this->post_type;
551                 do_action( 'current_screen', $current_screen );
552         }
553
554         /**
555          * Constructor
556          *
557          * @since 3.3.0
558          * @access private
559          */
560         private function __construct() {}
561
562         /**
563          * Indicates whether the screen is in a particular admin
564          *
565          * @since 3.5.0
566          *
567          * @param string $admin The admin to check against (network | user | site).
568          * If empty any of the three admins will result in true.
569          * @return boolean True if the screen is in the indicated admin, false otherwise.
570          *
571          */
572         public function in_admin( $admin = null ) {
573                 if ( empty( $admin ) )
574                         return (bool) $this->in_admin;
575
576                 return ( $admin == $this->in_admin );
577         }
578
579         /**
580          * Sets the old string-based contextual help for the screen.
581          *
582          * For backwards compatibility.
583          *
584          * @since 3.3.0
585          *
586          * @param WP_Screen $screen A screen object.
587          * @param string $help Help text.
588          */
589         static function add_old_compat_help( $screen, $help ) {
590                 self::$_old_compat_help[ $screen->id ] = $help;
591         }
592
593         /**
594          * Set the parent information for the screen.
595          * This is called in admin-header.php after the menu parent for the screen has been determined.
596          *
597          * @since 3.3.0
598          *
599          * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
600          */
601         function set_parentage( $parent_file ) {
602                 $this->parent_file = $parent_file;
603                 list( $this->parent_base ) = explode( '?', $parent_file );
604                 $this->parent_base = str_replace( '.php', '', $this->parent_base );
605         }
606
607         /**
608          * Adds an option for the screen.
609          * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
610          *
611          * @since 3.3.0
612          *
613          * @param string $option Option ID
614          * @param mixed $args Option-dependent arguments.
615          */
616         public function add_option( $option, $args = array() ) {
617                 $this->_options[ $option ] = $args;
618         }
619
620         /**
621          * Gets the arguments for an option for the screen.
622          *
623          * @since 3.3.0
624          *
625          * @param string $option Option ID.
626          * @param mixed $key Optional. Specific array key for when the option is an array.
627          */
628         public function get_option( $option, $key = false ) {
629                 if ( ! isset( $this->_options[ $option ] ) )
630                         return null;
631                 if ( $key ) {
632                         if ( isset( $this->_options[ $option ][ $key ] ) )
633                                 return $this->_options[ $option ][ $key ];
634                         return null;
635                 }
636                 return $this->_options[ $option ];
637         }
638
639         /**
640          * Gets the help tabs registered for the screen.
641          *
642          * @since 3.4.0
643          *
644          * @return array Help tabs with arguments.
645          */
646         public function get_help_tabs() {
647                 return $this->_help_tabs;
648         }
649
650         /**
651          * Gets the arguments for a help tab.
652          *
653          * @since 3.4.0
654          *
655          * @param string $id Help Tab ID.
656          * @return array Help tab arguments.
657          */
658         public function get_help_tab( $id ) {
659                 if ( ! isset( $this->_help_tabs[ $id ] ) )
660                         return null;
661                 return $this->_help_tabs[ $id ];
662         }
663
664         /**
665          * Add a help tab to the contextual help for the screen.
666          * Call this on the load-$pagenow hook for the relevant screen.
667          *
668          * @since 3.3.0
669          *
670          * @param array $args
671          * - string   - title    - Title for the tab.
672          * - string   - id       - Tab ID. Must be HTML-safe.
673          * - string   - content  - Help tab content in plain text or HTML. Optional.
674          * - callback - callback - A callback to generate the tab content. Optional.
675          *
676          */
677         public function add_help_tab( $args ) {
678                 $defaults = array(
679                         'title'    => false,
680                         'id'       => false,
681                         'content'  => '',
682                         'callback' => false,
683                 );
684                 $args = wp_parse_args( $args, $defaults );
685
686                 $args['id'] = sanitize_html_class( $args['id'] );
687
688                 // Ensure we have an ID and title.
689                 if ( ! $args['id'] || ! $args['title'] )
690                         return;
691
692                 // Allows for overriding an existing tab with that ID.
693                 $this->_help_tabs[ $args['id'] ] = $args;
694         }
695
696         /**
697          * Removes a help tab from the contextual help for the screen.
698          *
699          * @since 3.3.0
700          *
701          * @param string $id The help tab ID.
702          */
703         public function remove_help_tab( $id ) {
704                 unset( $this->_help_tabs[ $id ] );
705         }
706
707         /**
708          * Removes all help tabs from the contextual help for the screen.
709          *
710          * @since 3.3.0
711          */
712         public function remove_help_tabs() {
713                 $this->_help_tabs = array();
714         }
715
716         /**
717          * Gets the content from a contextual help sidebar.
718          *
719          * @since 3.4.0
720          *
721          * @return string Contents of the help sidebar.
722          */
723         public function get_help_sidebar() {
724                 return $this->_help_sidebar;
725         }
726
727         /**
728          * Add a sidebar to the contextual help for the screen.
729          * 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.
730          *
731          * @since 3.3.0
732          *
733          * @param string $content Sidebar content in plain text or HTML.
734          */
735         public function set_help_sidebar( $content ) {
736                 $this->_help_sidebar = $content;
737         }
738
739         /**
740          * Gets the number of layout columns the user has selected.
741          *
742          * The layout_columns option controls the max number and default number of
743          * columns. This method returns the number of columns within that range selected
744          * by the user via Screen Options. If no selection has been made, the default
745          * provisioned in layout_columns is returned. If the screen does not support
746          * selecting the number of layout columns, 0 is returned.
747          *
748          * @since 3.4.0
749          *
750          * @return int Number of columns to display.
751          */
752         public function get_columns() {
753                 return $this->columns;
754         }
755
756         /**
757          * Render the screen's help section.
758          *
759          * This will trigger the deprecated filters for backwards compatibility.
760          *
761          * @since 3.3.0
762          */
763         public function render_screen_meta() {
764
765                 // Call old contextual_help_list filter.
766                 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
767
768                 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
769                 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
770
771                 // Default help only if there is no old-style block of text and no new-style help tabs.
772                 if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
773                         $default_help = apply_filters( 'default_contextual_help', '' );
774                         if ( $default_help )
775                                 $old_help = '<p>' . $default_help . '</p>';
776                 }
777
778                 if ( $old_help ) {
779                         $this->add_help_tab( array(
780                                 'id'      => 'old-contextual-help',
781                                 'title'   => __('Overview'),
782                                 'content' => $old_help,
783                         ) );
784                 }
785
786                 $help_sidebar = $this->get_help_sidebar();
787
788                 $help_class = 'hidden';
789                 if ( ! $help_sidebar )
790                         $help_class .= ' no-sidebar';
791
792                 // Time to render!
793                 ?>
794                 <div id="screen-meta" class="metabox-prefs">
795
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">
800                                                 <ul>
801                                                 <?php
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']}";
806                                                         ?>
807
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'] ); ?>
811                                                                 </a>
812                                                         </li>
813                                                 <?php
814                                                         $class = '';
815                                                 endforeach;
816                                                 ?>
817                                                 </ul>
818                                         </div>
819
820                                         <?php if ( $help_sidebar ) : ?>
821                                         <div class="contextual-help-sidebar">
822                                                 <?php echo $help_sidebar; ?>
823                                         </div>
824                                         <?php endif; ?>
825
826                                         <div class="contextual-help-tabs-wrap">
827                                                 <?php
828                                                 $classes = 'help-tab-content active';
829                                                 foreach ( $this->get_help_tabs() as $tab ):
830                                                         $panel_id = "tab-panel-{$tab['id']}";
831                                                         ?>
832
833                                                         <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
834                                                                 <?php
835                                                                 // Print tab content.
836                                                                 echo $tab['content'];
837
838                                                                 // If it exists, fire tab callback.
839                                                                 if ( ! empty( $tab['callback'] ) )
840                                                                         call_user_func_array( $tab['callback'], array( $this, $tab ) );
841                                                                 ?>
842                                                         </div>
843                                                 <?php
844                                                         $classes = 'help-tab-content';
845                                                 endforeach;
846                                                 ?>
847                                         </div>
848                                 </div>
849                         </div>
850                 <?php
851                 // Setup layout columns
852
853                 // Back compat for plugins using the filter instead of add_screen_option()
854                 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
855
856                 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
857                         $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
858
859                 if ( $this->get_option( 'layout_columns' ) ) {
860                         $this->columns = (int) get_user_option("screen_layout_$this->id");
861
862                         if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
863                                 $this->columns = $this->get_option( 'layout_columns', 'default' );
864                 }
865                 $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
866
867                 // Add screen options
868                 if ( $this->show_screen_options() )
869                         $this->render_screen_options();
870                 ?>
871                 </div>
872                 <?php
873                 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
874                         return;
875                 ?>
876                 <div id="screen-meta-links">
877                 <?php if ( $this->get_help_tabs() ) : ?>
878                         <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
879                         <a href="#contextual-help-wrap" id="contextual-help-link" class="show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></a>
880                         </div>
881                 <?php endif;
882                 if ( $this->show_screen_options() ) : ?>
883                         <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
884                         <a href="#screen-options-wrap" id="show-settings-link" class="show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></a>
885                         </div>
886                 <?php endif; ?>
887                 </div>
888                 <?php
889         }
890
891         public function show_screen_options() {
892                 global $wp_meta_boxes;
893
894                 if ( is_bool( $this->_show_screen_options ) )
895                         return $this->_show_screen_options;
896
897                 $columns = get_column_headers( $this );
898
899                 $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
900
901                 $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
902
903                 switch ( $this->id ) {
904                         case 'widgets':
905                                 $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";
906                                 break;
907                 }
908
909                 if ( $this->_screen_settings || $this->_options )
910                         $show_screen = true;
911
912                 $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
913                 return $this->_show_screen_options;
914         }
915
916         /**
917          * Render the screen options tab.
918          *
919          * @since 3.3.0
920          */
921         public function render_screen_options() {
922                 global $wp_meta_boxes, $wp_list_table;
923
924                 $columns = get_column_headers( $this );
925                 $hidden  = get_hidden_columns( $this );
926
927                 ?>
928                 <div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>">
929                 <form id="adv-settings" action="" method="post">
930                 <?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
931                         <h5><?php _e( 'Show on screen' ); ?></h5>
932                 <?php
933                 endif;
934
935                 if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
936                         <div class="metabox-prefs">
937                                 <?php
938                                         meta_box_prefs( $this );
939
940                                         if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
941                                                 if ( isset( $_GET['welcome'] ) ) {
942                                                         $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
943                                                         update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
944                                                 } else {
945                                                         $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
946                                                         if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) )
947                                                                 $welcome_checked = false;
948                                                 }
949                                                 echo '<label for="wp_welcome_panel-hide">';
950                                                 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
951                                                 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
952                                         }
953                                 ?>
954                                 <br class="clear" />
955                         </div>
956                         <?php endif;
957                         if ( $columns ) :
958                                 if ( ! empty( $columns['_title'] ) ) : ?>
959                         <h5><?php echo $columns['_title']; ?></h5>
960                         <?php endif; ?>
961                         <div class="metabox-prefs">
962                                 <?php
963                                 $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
964
965                                 foreach ( $columns as $column => $title ) {
966                                         // Can't hide these for they are special
967                                         if ( in_array( $column, $special ) )
968                                                 continue;
969                                         if ( empty( $title ) )
970                                                 continue;
971
972                                         if ( 'comments' == $column )
973                                                 $title = __( 'Comments' );
974                                         $id = "$column-hide";
975                                         echo '<label for="' . $id . '">';
976                                         echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
977                                         echo "$title</label>\n";
978                                 }
979                                 ?>
980                                 <br class="clear" />
981                         </div>
982                 <?php endif;
983
984                 $this->render_screen_layout();
985                 $this->render_per_page_options();
986                 echo $this->_screen_settings;
987
988                 ?>
989                 <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
990                 </form>
991                 </div>
992                 <?php
993         }
994
995         /**
996          * Render the option for number of columns on the page
997          *
998          * @since 3.3.0
999          */
1000         function render_screen_layout() {
1001                 if ( ! $this->get_option('layout_columns') )
1002                         return;
1003
1004                 $screen_layout_columns = $this->get_columns();
1005                 $num = $this->get_option( 'layout_columns', 'max' );
1006
1007                 ?>
1008                 <h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>
1009                 <div class='columns-prefs'><?php
1010                         _e('Number of Columns:');
1011                         for ( $i = 1; $i <= $num; ++$i ):
1012                                 ?>
1013                                 <label class="columns-prefs-<?php echo $i; ?>">
1014                                         <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
1015                                                 <?php checked( $screen_layout_columns, $i ); ?> />
1016                                         <?php echo esc_html( $i ); ?>
1017                                 </label>
1018                                 <?php
1019                         endfor; ?>
1020                 </div>
1021                 <?php
1022         }
1023
1024         /**
1025          * Render the items per page option
1026          *
1027          * @since 3.3.0
1028          */
1029         function render_per_page_options() {
1030                 if ( ! $this->get_option( 'per_page' ) )
1031                         return;
1032
1033                 $per_page_label = $this->get_option( 'per_page', 'label' );
1034
1035                 $option = $this->get_option( 'per_page', 'option' );
1036                 if ( ! $option )
1037                         $option = str_replace( '-', '_', "{$this->id}_per_page" );
1038
1039                 $per_page = (int) get_user_option( $option );
1040                 if ( empty( $per_page ) || $per_page < 1 ) {
1041                         $per_page = $this->get_option( 'per_page', 'default' );
1042                         if ( ! $per_page )
1043                                 $per_page = 20;
1044                 }
1045
1046                 if ( 'edit_comments_per_page' == $option ) {
1047                         $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
1048                         $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
1049                 } elseif ( 'categories_per_page' == $option ) {
1050                         $per_page = apply_filters( 'edit_categories_per_page', $per_page );
1051                 } else {
1052                         $per_page = apply_filters( $option, $per_page );
1053                 }
1054
1055                 // Back compat
1056                 if ( isset( $this->post_type ) )
1057                         $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
1058
1059                 ?>
1060                 <div class="screen-options">
1061                         <?php if ( $per_page_label ) : ?>
1062                                 <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
1063                                         id="<?php echo esc_attr( $option ); ?>" maxlength="3"
1064                                         value="<?php echo esc_attr( $per_page ); ?>" />
1065                                 <label for="<?php echo esc_attr( $option ); ?>">
1066                                         <?php echo esc_html( $per_page_label ); ?>
1067                                 </label>
1068                         <?php endif;
1069
1070                         echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
1071                         <input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' />
1072                 </div>
1073                 <?php
1074         }
1075 }