~canonical-sysadmins/wordpress/4.5.2

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-screen.php

  • Committer: Manuel Seelaus
  • Date: 2015-12-09 17:47:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: manuel.seelaus@canonical.com-20151209174718-coxethm2swbeqksy
Merge WP4.4 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Screen API: WP_Screen class
 
4
 *
 
5
 * @package WordPress
 
6
 * @subpackage Administration
 
7
 * @since 4.4.0
 
8
 */
 
9
 
 
10
/**
 
11
 * Core class used to implement an admin screen API.
 
12
 *
 
13
 * @since 3.3.0
 
14
 */
 
15
final class WP_Screen {
 
16
        /**
 
17
         * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
 
18
         *
 
19
         * @since 3.3.0
 
20
         * @var string
 
21
         * @access public
 
22
         */
 
23
        public $action;
 
24
 
 
25
        /**
 
26
         * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
 
27
         * For example, for an $id of 'edit-post' the base is 'edit'.
 
28
         *
 
29
         * @since 3.3.0
 
30
         * @var string
 
31
         * @access public
 
32
         */
 
33
        public $base;
 
34
 
 
35
        /**
 
36
         * The number of columns to display. Access with get_columns().
 
37
         *
 
38
         * @since 3.4.0
 
39
         * @var int
 
40
         * @access private
 
41
         */
 
42
        private $columns = 0;
 
43
 
 
44
        /**
 
45
         * The unique ID of the screen.
 
46
         *
 
47
         * @since 3.3.0
 
48
         * @var string
 
49
         * @access public
 
50
         */
 
51
        public $id;
 
52
 
 
53
        /**
 
54
         * Which admin the screen is in. network | user | site | false
 
55
         *
 
56
         * @since 3.5.0
 
57
         * @var string
 
58
         * @access protected
 
59
         */
 
60
        protected $in_admin;
 
61
 
 
62
        /**
 
63
         * Whether the screen is in the network admin.
 
64
         *
 
65
         * Deprecated. Use in_admin() instead.
 
66
         *
 
67
         * @since 3.3.0
 
68
         * @deprecated 3.5.0
 
69
         * @var bool
 
70
         * @access public
 
71
         */
 
72
        public $is_network;
 
73
 
 
74
        /**
 
75
         * Whether the screen is in the user admin.
 
76
         *
 
77
         * Deprecated. Use in_admin() instead.
 
78
         *
 
79
         * @since 3.3.0
 
80
         * @deprecated 3.5.0
 
81
         * @var bool
 
82
         * @access public
 
83
         */
 
84
        public $is_user;
 
85
 
 
86
        /**
 
87
         * The base menu parent.
 
88
         * This is derived from $parent_file by removing the query string and any .php extension.
 
89
         * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
 
90
         *
 
91
         * @since 3.3.0
 
92
         * @var string
 
93
         * @access public
 
94
         */
 
95
        public $parent_base;
 
96
 
 
97
        /**
 
98
         * The parent_file for the screen per the admin menu system.
 
99
         * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
 
100
         *
 
101
         * @since 3.3.0
 
102
         * @var string
 
103
         * @access public
 
104
         */
 
105
        public $parent_file;
 
106
 
 
107
        /**
 
108
         * The post type associated with the screen, if any.
 
109
         * The 'edit.php?post_type=page' screen has a post type of 'page'.
 
110
         * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
 
111
         *
 
112
         * @since 3.3.0
 
113
         * @var string
 
114
         * @access public
 
115
         */
 
116
        public $post_type;
 
117
 
 
118
        /**
 
119
         * The taxonomy associated with the screen, if any.
 
120
         * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
 
121
         * @since 3.3.0
 
122
         * @var string
 
123
         * @access public
 
124
         */
 
125
        public $taxonomy;
 
126
 
 
127
        /**
 
128
         * The help tab data associated with the screen, if any.
 
129
         *
 
130
         * @since 3.3.0
 
131
         * @var array
 
132
         * @access private
 
133
         */
 
134
        private $_help_tabs = array();
 
135
 
 
136
        /**
 
137
         * The help sidebar data associated with screen, if any.
 
138
         *
 
139
         * @since 3.3.0
 
140
         * @var string
 
141
         * @access private
 
142
         */
 
143
        private $_help_sidebar = '';
 
144
 
 
145
        /**
 
146
         * The accessible hidden headings and text associated with the screen, if any.
 
147
         *
 
148
         * @since 4.4.0
 
149
         * @access private
 
150
         * @var array
 
151
         */
 
152
        private $_screen_reader_content = array();
 
153
 
 
154
        /**
 
155
         * Stores old string-based help.
 
156
         *
 
157
         * @static
 
158
         * @access private
 
159
         *
 
160
         * @var array
 
161
         */
 
162
        private static $_old_compat_help = array();
 
163
 
 
164
        /**
 
165
         * The screen options associated with screen, if any.
 
166
         *
 
167
         * @since 3.3.0
 
168
         * @var array
 
169
         * @access private
 
170
         */
 
171
        private $_options = array();
 
172
 
 
173
        /**
 
174
         * The screen object registry.
 
175
         *
 
176
         * @since 3.3.0
 
177
         *
 
178
         * @static
 
179
         * @access private
 
180
         *
 
181
         * @var array
 
182
         */
 
183
        private static $_registry = array();
 
184
 
 
185
        /**
 
186
         * Stores the result of the public show_screen_options function.
 
187
         *
 
188
         * @since 3.3.0
 
189
         * @var bool
 
190
         * @access private
 
191
         */
 
192
        private $_show_screen_options;
 
193
 
 
194
        /**
 
195
         * Stores the 'screen_settings' section of screen options.
 
196
         *
 
197
         * @since 3.3.0
 
198
         * @var string
 
199
         * @access private
 
200
         */
 
201
        private $_screen_settings;
 
202
 
 
203
        /**
 
204
         * Fetches a screen object.
 
205
         *
 
206
         * @since 3.3.0
 
207
         * @access public
 
208
         *
 
209
         * @static
 
210
         *
 
211
         * @global string $hook_suffix
 
212
         *
 
213
         * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
 
214
         *                                        Defaults to the current $hook_suffix global.
 
215
         * @return WP_Screen Screen object.
 
216
         */
 
217
        public static function get( $hook_name = '' ) {
 
218
                if ( $hook_name instanceof WP_Screen ) {
 
219
                        return $hook_name;
 
220
                }
 
221
 
 
222
                $post_type = $taxonomy = null;
 
223
                $in_admin = false;
 
224
                $action = '';
 
225
 
 
226
                if ( $hook_name )
 
227
                        $id = $hook_name;
 
228
                else
 
229
                        $id = $GLOBALS['hook_suffix'];
 
230
 
 
231
                // For those pesky meta boxes.
 
232
                if ( $hook_name && post_type_exists( $hook_name ) ) {
 
233
                        $post_type = $id;
 
234
                        $id = 'post'; // changes later. ends up being $base.
 
235
                } else {
 
236
                        if ( '.php' == substr( $id, -4 ) )
 
237
                                $id = substr( $id, 0, -4 );
 
238
 
 
239
                        if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
 
240
                                $id = substr( $id, 0, -4 );
 
241
                                $action = 'add';
 
242
                        }
 
243
                }
 
244
 
 
245
                if ( ! $post_type && $hook_name ) {
 
246
                        if ( '-network' == substr( $id, -8 ) ) {
 
247
                                $id = substr( $id, 0, -8 );
 
248
                                $in_admin = 'network';
 
249
                        } elseif ( '-user' == substr( $id, -5 ) ) {
 
250
                                $id = substr( $id, 0, -5 );
 
251
                                $in_admin = 'user';
 
252
                        }
 
253
 
 
254
                        $id = sanitize_key( $id );
 
255
                        if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
 
256
                                $maybe = substr( $id, 5 );
 
257
                                if ( taxonomy_exists( $maybe ) ) {
 
258
                                        $id = 'edit-tags';
 
259
                                        $taxonomy = $maybe;
 
260
                                } elseif ( post_type_exists( $maybe ) ) {
 
261
                                        $id = 'edit';
 
262
                                        $post_type = $maybe;
 
263
                                }
 
264
                        }
 
265
 
 
266
                        if ( ! $in_admin )
 
267
                                $in_admin = 'site';
 
268
                } else {
 
269
                        if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
 
270
                                $in_admin = 'network';
 
271
                        elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
 
272
                                $in_admin = 'user';
 
273
                        else
 
274
                                $in_admin = 'site';
 
275
                }
 
276
 
 
277
                if ( 'index' == $id )
 
278
                        $id = 'dashboard';
 
279
                elseif ( 'front' == $id )
 
280
                        $in_admin = false;
 
281
 
 
282
                $base = $id;
 
283
 
 
284
                // If this is the current screen, see if we can be more accurate for post types and taxonomies.
 
285
                if ( ! $hook_name ) {
 
286
                        if ( isset( $_REQUEST['post_type'] ) )
 
287
                                $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
 
288
                        if ( isset( $_REQUEST['taxonomy'] ) )
 
289
                                $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
 
290
 
 
291
                        switch ( $base ) {
 
292
                                case 'post' :
 
293
                                        if ( isset( $_GET['post'] ) )
 
294
                                                $post_id = (int) $_GET['post'];
 
295
                                        elseif ( isset( $_POST['post_ID'] ) )
 
296
                                                $post_id = (int) $_POST['post_ID'];
 
297
                                        else
 
298
                                                $post_id = 0;
 
299
 
 
300
                                        if ( $post_id ) {
 
301
                                                $post = get_post( $post_id );
 
302
                                                if ( $post )
 
303
                                                        $post_type = $post->post_type;
 
304
                                        }
 
305
                                        break;
 
306
                                case 'edit-tags' :
 
307
                                        if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
 
308
                                                $post_type = 'post';
 
309
                                        break;
 
310
                        }
 
311
                }
 
312
 
 
313
                switch ( $base ) {
 
314
                        case 'post' :
 
315
                                if ( null === $post_type )
 
316
                                        $post_type = 'post';
 
317
                                $id = $post_type;
 
318
                                break;
 
319
                        case 'edit' :
 
320
                                if ( null === $post_type )
 
321
                                        $post_type = 'post';
 
322
                                $id .= '-' . $post_type;
 
323
                                break;
 
324
                        case 'edit-tags' :
 
325
                                if ( null === $taxonomy )
 
326
                                        $taxonomy = 'post_tag';
 
327
                                // The edit-tags ID does not contain the post type. Look for it in the request.
 
328
                                if ( null === $post_type ) {
 
329
                                        $post_type = 'post';
 
330
                                        if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
 
331
                                                $post_type = $_REQUEST['post_type'];
 
332
                                }
 
333
 
 
334
                                $id = 'edit-' . $taxonomy;
 
335
                                break;
 
336
                }
 
337
 
 
338
                if ( 'network' == $in_admin ) {
 
339
                        $id   .= '-network';
 
340
                        $base .= '-network';
 
341
                } elseif ( 'user' == $in_admin ) {
 
342
                        $id   .= '-user';
 
343
                        $base .= '-user';
 
344
                }
 
345
 
 
346
                if ( isset( self::$_registry[ $id ] ) ) {
 
347
                        $screen = self::$_registry[ $id ];
 
348
                        if ( $screen === get_current_screen() )
 
349
                                return $screen;
 
350
                } else {
 
351
                        $screen = new WP_Screen();
 
352
                        $screen->id     = $id;
 
353
                }
 
354
 
 
355
                $screen->base       = $base;
 
356
                $screen->action     = $action;
 
357
                $screen->post_type  = (string) $post_type;
 
358
                $screen->taxonomy   = (string) $taxonomy;
 
359
                $screen->is_user    = ( 'user' == $in_admin );
 
360
                $screen->is_network = ( 'network' == $in_admin );
 
361
                $screen->in_admin   = $in_admin;
 
362
 
 
363
                self::$_registry[ $id ] = $screen;
 
364
 
 
365
                return $screen;
 
366
        }
 
367
 
 
368
        /**
 
369
         * Makes the screen object the current screen.
 
370
         *
 
371
         * @see set_current_screen()
 
372
         * @since 3.3.0
 
373
         *
 
374
         * @global WP_Screen $current_screen
 
375
         * @global string    $taxnow
 
376
         * @global string    $typenow
 
377
         */
 
378
        public function set_current_screen() {
 
379
                global $current_screen, $taxnow, $typenow;
 
380
                $current_screen = $this;
 
381
                $taxnow = $this->taxonomy;
 
382
                $typenow = $this->post_type;
 
383
 
 
384
                /**
 
385
                 * Fires after the current screen has been set.
 
386
                 *
 
387
                 * @since 3.0.0
 
388
                 *
 
389
                 * @param WP_Screen $current_screen Current WP_Screen object.
 
390
                 */
 
391
                do_action( 'current_screen', $current_screen );
 
392
        }
 
393
 
 
394
        /**
 
395
         * Constructor
 
396
         *
 
397
         * @since 3.3.0
 
398
         * @access private
 
399
         */
 
400
        private function __construct() {}
 
401
 
 
402
        /**
 
403
         * Indicates whether the screen is in a particular admin
 
404
         *
 
405
         * @since 3.5.0
 
406
         *
 
407
         * @param string $admin The admin to check against (network | user | site).
 
408
         *                      If empty any of the three admins will result in true.
 
409
         * @return bool True if the screen is in the indicated admin, false otherwise.
 
410
         */
 
411
        public function in_admin( $admin = null ) {
 
412
                if ( empty( $admin ) )
 
413
                        return (bool) $this->in_admin;
 
414
 
 
415
                return ( $admin == $this->in_admin );
 
416
        }
 
417
 
 
418
        /**
 
419
         * Sets the old string-based contextual help for the screen.
 
420
         *
 
421
         * For backwards compatibility.
 
422
         *
 
423
         * @since 3.3.0
 
424
         *
 
425
         * @static
 
426
         *
 
427
         * @param WP_Screen $screen A screen object.
 
428
         * @param string $help Help text.
 
429
         */
 
430
        public static function add_old_compat_help( $screen, $help ) {
 
431
                self::$_old_compat_help[ $screen->id ] = $help;
 
432
        }
 
433
 
 
434
        /**
 
435
         * Set the parent information for the screen.
 
436
         * This is called in admin-header.php after the menu parent for the screen has been determined.
 
437
         *
 
438
         * @since 3.3.0
 
439
         *
 
440
         * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
 
441
         */
 
442
        public function set_parentage( $parent_file ) {
 
443
                $this->parent_file = $parent_file;
 
444
                list( $this->parent_base ) = explode( '?', $parent_file );
 
445
                $this->parent_base = str_replace( '.php', '', $this->parent_base );
 
446
        }
 
447
 
 
448
        /**
 
449
         * Adds an option for the screen.
 
450
         * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
 
451
         *
 
452
         * @since 3.3.0
 
453
         *
 
454
         * @param string $option Option ID
 
455
         * @param mixed $args Option-dependent arguments.
 
456
         */
 
457
        public function add_option( $option, $args = array() ) {
 
458
                $this->_options[ $option ] = $args;
 
459
        }
 
460
 
 
461
        /**
 
462
         * Remove an option from the screen.
 
463
         *
 
464
         * @since 3.8.0
 
465
         *
 
466
         * @param string $option Option ID.
 
467
         */
 
468
        public function remove_option( $option ) {
 
469
                unset( $this->_options[ $option ] );
 
470
        }
 
471
 
 
472
        /**
 
473
         * Remove all options from the screen.
 
474
         *
 
475
         * @since 3.8.0
 
476
         */
 
477
        public function remove_options() {
 
478
                $this->_options = array();
 
479
        }
 
480
 
 
481
        /**
 
482
         * Get the options registered for the screen.
 
483
         *
 
484
         * @since 3.8.0
 
485
         *
 
486
         * @return array Options with arguments.
 
487
         */
 
488
        public function get_options() {
 
489
                return $this->_options;
 
490
        }
 
491
 
 
492
        /**
 
493
         * Gets the arguments for an option for the screen.
 
494
         *
 
495
         * @since 3.3.0
 
496
         *
 
497
         * @param string $option Option name.
 
498
         * @param string $key    Optional. Specific array key for when the option is an array.
 
499
         *                       Default false.
 
500
         * @return string The option value if set, null otherwise.
 
501
         */
 
502
        public function get_option( $option, $key = false ) {
 
503
                if ( ! isset( $this->_options[ $option ] ) )
 
504
                        return null;
 
505
                if ( $key ) {
 
506
                        if ( isset( $this->_options[ $option ][ $key ] ) )
 
507
                                return $this->_options[ $option ][ $key ];
 
508
                        return null;
 
509
                }
 
510
                return $this->_options[ $option ];
 
511
        }
 
512
 
 
513
        /**
 
514
         * Gets the help tabs registered for the screen.
 
515
         *
 
516
         * @since 3.4.0
 
517
         * @since 4.4.0 Help tabs are ordered by their priority.
 
518
         *
 
519
         * @return array Help tabs with arguments.
 
520
         */
 
521
        public function get_help_tabs() {
 
522
                $help_tabs = $this->_help_tabs;
 
523
 
 
524
                $priorities = array();
 
525
                foreach ( $help_tabs as $help_tab ) {
 
526
                        if ( isset( $priorities[ $help_tab['priority'] ] ) ) {
 
527
                                $priorities[ $help_tab['priority'] ][] = $help_tab;
 
528
                        } else {
 
529
                                $priorities[ $help_tab['priority'] ] = array( $help_tab );
 
530
                        }
 
531
                }
 
532
 
 
533
                sort( $priorities );
 
534
 
 
535
                $sorted = array();
 
536
                foreach ( $priorities as $list ) {
 
537
                        foreach ( $list as $tab ) {
 
538
                                $sorted[ $tab['id'] ] = $tab;
 
539
                        }
 
540
                }
 
541
 
 
542
                return $sorted;
 
543
        }
 
544
 
 
545
        /**
 
546
         * Gets the arguments for a help tab.
 
547
         *
 
548
         * @since 3.4.0
 
549
         *
 
550
         * @param string $id Help Tab ID.
 
551
         * @return array Help tab arguments.
 
552
         */
 
553
        public function get_help_tab( $id ) {
 
554
                if ( ! isset( $this->_help_tabs[ $id ] ) )
 
555
                        return null;
 
556
                return $this->_help_tabs[ $id ];
 
557
        }
 
558
 
 
559
        /**
 
560
         * Add a help tab to the contextual help for the screen.
 
561
         * Call this on the load-$pagenow hook for the relevant screen.
 
562
         *
 
563
         * @since 3.3.0
 
564
         * @since 4.4.0 The `$priority` argument was added.
 
565
         *
 
566
         * @param array $args {
 
567
         *     Array of arguments used to display the help tab.
 
568
         *
 
569
         *     @type string $title    Title for the tab. Default false.
 
570
         *     @type string $id       Tab ID. Must be HTML-safe. Default false.
 
571
         *     @type string $content  Optional. Help tab content in plain text or HTML. Default empty string.
 
572
         *     @type string $callback Optional. A callback to generate the tab content. Default false.
 
573
         *     @type int    $priority Optional. The priority of the tab, used for ordering. Default 10.
 
574
         * }
 
575
         */
 
576
        public function add_help_tab( $args ) {
 
577
                $defaults = array(
 
578
                        'title'    => false,
 
579
                        'id'       => false,
 
580
                        'content'  => '',
 
581
                        'callback' => false,
 
582
                        'priority' => 10,
 
583
                );
 
584
                $args = wp_parse_args( $args, $defaults );
 
585
 
 
586
                $args['id'] = sanitize_html_class( $args['id'] );
 
587
 
 
588
                // Ensure we have an ID and title.
 
589
                if ( ! $args['id'] || ! $args['title'] )
 
590
                        return;
 
591
 
 
592
                // Allows for overriding an existing tab with that ID.
 
593
                $this->_help_tabs[ $args['id'] ] = $args;
 
594
        }
 
595
 
 
596
        /**
 
597
         * Removes a help tab from the contextual help for the screen.
 
598
         *
 
599
         * @since 3.3.0
 
600
         *
 
601
         * @param string $id The help tab ID.
 
602
         */
 
603
        public function remove_help_tab( $id ) {
 
604
                unset( $this->_help_tabs[ $id ] );
 
605
        }
 
606
 
 
607
        /**
 
608
         * Removes all help tabs from the contextual help for the screen.
 
609
         *
 
610
         * @since 3.3.0
 
611
         */
 
612
        public function remove_help_tabs() {
 
613
                $this->_help_tabs = array();
 
614
        }
 
615
 
 
616
        /**
 
617
         * Gets the content from a contextual help sidebar.
 
618
         *
 
619
         * @since 3.4.0
 
620
         *
 
621
         * @return string Contents of the help sidebar.
 
622
         */
 
623
        public function get_help_sidebar() {
 
624
                return $this->_help_sidebar;
 
625
        }
 
626
 
 
627
        /**
 
628
         * Add a sidebar to the contextual help for the screen.
 
629
         * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add a sidebar to the contextual help.
 
630
         *
 
631
         * @since 3.3.0
 
632
         *
 
633
         * @param string $content Sidebar content in plain text or HTML.
 
634
         */
 
635
        public function set_help_sidebar( $content ) {
 
636
                $this->_help_sidebar = $content;
 
637
        }
 
638
 
 
639
        /**
 
640
         * Gets the number of layout columns the user has selected.
 
641
         *
 
642
         * The layout_columns option controls the max number and default number of
 
643
         * columns. This method returns the number of columns within that range selected
 
644
         * by the user via Screen Options. If no selection has been made, the default
 
645
         * provisioned in layout_columns is returned. If the screen does not support
 
646
         * selecting the number of layout columns, 0 is returned.
 
647
         *
 
648
         * @since 3.4.0
 
649
         *
 
650
         * @return int Number of columns to display.
 
651
         */
 
652
        public function get_columns() {
 
653
                return $this->columns;
 
654
        }
 
655
 
 
656
        /**
 
657
         * Get the accessible hidden headings and text used in the screen.
 
658
         *
 
659
         * @since 4.4.0
 
660
         *
 
661
         * @see set_screen_reader_content() For more information on the array format.
 
662
         *
 
663
         * @return array An associative array of screen reader text strings.
 
664
         */
 
665
        public function get_screen_reader_content() {
 
666
                return $this->_screen_reader_content;
 
667
        }
 
668
 
 
669
        /**
 
670
         * Get a screen reader text string.
 
671
         *
 
672
         * @since 4.4.0
 
673
         *
 
674
         * @param string $key Screen reader text array named key.
 
675
         * @return string Screen reader text string.
 
676
         */
 
677
        public function get_screen_reader_text( $key ) {
 
678
                if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
 
679
                        return null;
 
680
                }
 
681
                return $this->_screen_reader_content[ $key ];
 
682
        }
 
683
 
 
684
        /**
 
685
         * Add accessible hidden headings and text for the screen.
 
686
         *
 
687
         * @since 4.4.0
 
688
         *
 
689
         * @param array $content {
 
690
         *     An associative array of screen reader text strings.
 
691
         *
 
692
         *     @type string $heading_views      Screen reader text for the filter links heading.
 
693
         *                                      Default 'Filter items list'.
 
694
         *     @type string $heading_pagination Screen reader text for the pagination heading.
 
695
         *                                      Default 'Items list navigation'.
 
696
         *     @type string heading_list        Screen reader text for the items list heading.
 
697
         *                                      Default 'Items list'.
 
698
         * }
 
699
         */
 
700
        public function set_screen_reader_content( $content = array() ) {
 
701
                $defaults = array(
 
702
                        'heading_views'      => __( 'Filter items list' ),
 
703
                        'heading_pagination' => __( 'Items list navigation' ),
 
704
                        'heading_list'       => __( 'Items list' ),
 
705
                );
 
706
                $content = wp_parse_args( $content, $defaults );
 
707
 
 
708
                $this->_screen_reader_content = $content;
 
709
        }
 
710
 
 
711
        /**
 
712
         * Remove all the accessible hidden headings and text for the screen.
 
713
         *
 
714
         * @since 4.4.0
 
715
         */
 
716
        public function remove_screen_reader_content() {
 
717
                $this->_screen_reader_content = array();
 
718
        }
 
719
 
 
720
        /**
 
721
         * Render the screen's help section.
 
722
         *
 
723
         * This will trigger the deprecated filters for backwards compatibility.
 
724
         *
 
725
         * @since 3.3.0
 
726
         *
 
727
         * @global string $screen_layout_columns
 
728
         */
 
729
        public function render_screen_meta() {
 
730
 
 
731
                /**
 
732
                 * Filter the legacy contextual help list.
 
733
                 *
 
734
                 * @since 2.7.0
 
735
                 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
 
736
                 *                   get_current_screen()->remove_help_tab() instead.
 
737
                 *
 
738
                 * @param array     $old_compat_help Old contextual help.
 
739
                 * @param WP_Screen $this            Current WP_Screen instance.
 
740
                 */
 
741
                self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
 
742
 
 
743
                $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
 
744
 
 
745
                /**
 
746
                 * Filter the legacy contextual help text.
 
747
                 *
 
748
                 * @since 2.7.0
 
749
                 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
 
750
                 *                   get_current_screen()->remove_help_tab() instead.
 
751
                 *
 
752
                 * @param string    $old_help  Help text that appears on the screen.
 
753
                 * @param string    $screen_id Screen ID.
 
754
                 * @param WP_Screen $this      Current WP_Screen instance.
 
755
                 *
 
756
                 */
 
757
                $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
 
758
 
 
759
                // Default help only if there is no old-style block of text and no new-style help tabs.
 
760
                if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
 
761
 
 
762
                        /**
 
763
                         * Filter the default legacy contextual help text.
 
764
                         *
 
765
                         * @since 2.8.0
 
766
                         * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
 
767
                         *                   get_current_screen()->remove_help_tab() instead.
 
768
                         *
 
769
                         * @param string $old_help_default Default contextual help text.
 
770
                         */
 
771
                        $default_help = apply_filters( 'default_contextual_help', '' );
 
772
                        if ( $default_help )
 
773
                                $old_help = '<p>' . $default_help . '</p>';
 
774
                }
 
775
 
 
776
                if ( $old_help ) {
 
777
                        $this->add_help_tab( array(
 
778
                                'id'      => 'old-contextual-help',
 
779
                                'title'   => __('Overview'),
 
780
                                'content' => $old_help,
 
781
                        ) );
 
782
                }
 
783
 
 
784
                $help_sidebar = $this->get_help_sidebar();
 
785
 
 
786
                $help_class = 'hidden';
 
787
                if ( ! $help_sidebar )
 
788
                        $help_class .= ' no-sidebar';
 
789
 
 
790
                // Time to render!
 
791
                ?>
 
792
                <div id="screen-meta" class="metabox-prefs">
 
793
 
 
794
                        <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
 
795
                                <div id="contextual-help-back"></div>
 
796
                                <div id="contextual-help-columns">
 
797
                                        <div class="contextual-help-tabs">
 
798
                                                <ul>
 
799
                                                <?php
 
800
                                                $class = ' class="active"';
 
801
                                                foreach ( $this->get_help_tabs() as $tab ) :
 
802
                                                        $link_id  = "tab-link-{$tab['id']}";
 
803
                                                        $panel_id = "tab-panel-{$tab['id']}";
 
804
                                                        ?>
 
805
 
 
806
                                                        <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
 
807
                                                                <a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">
 
808
                                                                        <?php echo esc_html( $tab['title'] ); ?>
 
809
                                                                </a>
 
810
                                                        </li>
 
811
                                                <?php
 
812
                                                        $class = '';
 
813
                                                endforeach;
 
814
                                                ?>
 
815
                                                </ul>
 
816
                                        </div>
 
817
 
 
818
                                        <?php if ( $help_sidebar ) : ?>
 
819
                                        <div class="contextual-help-sidebar">
 
820
                                                <?php echo $help_sidebar; ?>
 
821
                                        </div>
 
822
                                        <?php endif; ?>
 
823
 
 
824
                                        <div class="contextual-help-tabs-wrap">
 
825
                                                <?php
 
826
                                                $classes = 'help-tab-content active';
 
827
                                                foreach ( $this->get_help_tabs() as $tab ):
 
828
                                                        $panel_id = "tab-panel-{$tab['id']}";
 
829
                                                        ?>
 
830
 
 
831
                                                        <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
 
832
                                                                <?php
 
833
                                                                // Print tab content.
 
834
                                                                echo $tab['content'];
 
835
 
 
836
                                                                // If it exists, fire tab callback.
 
837
                                                                if ( ! empty( $tab['callback'] ) )
 
838
                                                                        call_user_func_array( $tab['callback'], array( $this, $tab ) );
 
839
                                                                ?>
 
840
                                                        </div>
 
841
                                                <?php
 
842
                                                        $classes = 'help-tab-content';
 
843
                                                endforeach;
 
844
                                                ?>
 
845
                                        </div>
 
846
                                </div>
 
847
                        </div>
 
848
                <?php
 
849
                // Setup layout columns
 
850
 
 
851
                /**
 
852
                 * Filter the array of screen layout columns.
 
853
                 *
 
854
                 * This hook provides back-compat for plugins using the back-compat
 
855
                 * filter instead of add_screen_option().
 
856
                 *
 
857
                 * @since 2.8.0
 
858
                 *
 
859
                 * @param array     $empty_columns Empty array.
 
860
                 * @param string    $screen_id     Screen ID.
 
861
                 * @param WP_Screen $this          Current WP_Screen instance.
 
862
                 */
 
863
                $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
 
864
 
 
865
                if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
 
866
                        $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
 
867
 
 
868
                if ( $this->get_option( 'layout_columns' ) ) {
 
869
                        $this->columns = (int) get_user_option("screen_layout_$this->id");
 
870
 
 
871
                        if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
 
872
                                $this->columns = $this->get_option( 'layout_columns', 'default' );
 
873
                }
 
874
                $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
 
875
 
 
876
                // Add screen options
 
877
                if ( $this->show_screen_options() )
 
878
                        $this->render_screen_options();
 
879
                ?>
 
880
                </div>
 
881
                <?php
 
882
                if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
 
883
                        return;
 
884
                ?>
 
885
                <div id="screen-meta-links">
 
886
                <?php if ( $this->get_help_tabs() ) : ?>
 
887
                        <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
 
888
                        <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
 
889
                        </div>
 
890
                <?php endif;
 
891
                if ( $this->show_screen_options() ) : ?>
 
892
                        <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
 
893
                        <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
 
894
                        </div>
 
895
                <?php endif; ?>
 
896
                </div>
 
897
                <?php
 
898
        }
 
899
 
 
900
        /**
 
901
         *
 
902
         * @global array $wp_meta_boxes
 
903
         *
 
904
         * @return bool
 
905
         */
 
906
        public function show_screen_options() {
 
907
                global $wp_meta_boxes;
 
908
 
 
909
                if ( is_bool( $this->_show_screen_options ) )
 
910
                        return $this->_show_screen_options;
 
911
 
 
912
                $columns = get_column_headers( $this );
 
913
 
 
914
                $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
 
915
 
 
916
                switch ( $this->base ) {
 
917
                        case 'widgets':
 
918
                                $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
 
919
                                break;
 
920
                        case 'post' :
 
921
                                $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
 
922
                                $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
 
923
                                $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
 
924
                                $this->_screen_settings = $expand;
 
925
                                break;
 
926
                        default:
 
927
                                $this->_screen_settings = '';
 
928
                                break;
 
929
                }
 
930
 
 
931
                /**
 
932
                 * Filter the screen settings text displayed in the Screen Options tab.
 
933
                 *
 
934
                 * This filter is currently only used on the Widgets screen to enable
 
935
                 * accessibility mode.
 
936
                 *
 
937
                 * @since 3.0.0
 
938
                 *
 
939
                 * @param string    $screen_settings Screen settings.
 
940
                 * @param WP_Screen $this            WP_Screen object.
 
941
                 */
 
942
                $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
 
943
 
 
944
                if ( $this->_screen_settings || $this->_options )
 
945
                        $show_screen = true;
 
946
 
 
947
                /**
 
948
                 * Filter whether to show the Screen Options tab.
 
949
                 *
 
950
                 * @since 3.2.0
 
951
                 *
 
952
                 * @param bool      $show_screen Whether to show Screen Options tab.
 
953
                 *                               Default true.
 
954
                 * @param WP_Screen $this        Current WP_Screen instance.
 
955
                 */
 
956
                $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
 
957
                return $this->_show_screen_options;
 
958
        }
 
959
 
 
960
        /**
 
961
         * Render the screen options tab.
 
962
         *
 
963
         * @since 3.3.0
 
964
         *
 
965
         * @param array $options {
 
966
         *     @type bool $wrap  Whether the screen-options-wrap div will be included. Defaults to true.
 
967
         * }
 
968
         */
 
969
        public function render_screen_options( $options = array() ) {
 
970
                $options = wp_parse_args( $options, array(
 
971
                        'wrap' => true,
 
972
                ) );
 
973
 
 
974
                $wrapper_start = $wrapper_end = $form_start = $form_end = '';
 
975
 
 
976
                // Output optional wrapper.
 
977
                if ( $options['wrap'] ) {
 
978
                        $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">';
 
979
                        $wrapper_end = '</div>';
 
980
                }
 
981
 
 
982
                // Don't output the form and nonce for the widgets accessibility mode links.
 
983
                if ( 'widgets' !== $this->base ) {
 
984
                        $form_start = "\n<form id='adv-settings' method='post'>\n";
 
985
                        $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
 
986
                }
 
987
 
 
988
                echo $wrapper_start . $form_start;
 
989
 
 
990
                $this->render_meta_boxes_preferences();
 
991
                $this->render_list_table_columns_preferences();
 
992
                $this->render_screen_layout();
 
993
                $this->render_per_page_options();
 
994
                $this->render_view_mode();
 
995
                echo $this->_screen_settings;
 
996
 
 
997
                /**
 
998
                 * Filter whether to show the Screen Options submit button.
 
999
                 *
 
1000
                 * @since 4.4.0
 
1001
                 * 
 
1002
                 * @param bool      $show_button Whether to show Screen Options submit button.
 
1003
                 *                               Default false.
 
1004
                 * @param WP_Screen $this        Current WP_Screen instance.
 
1005
                 */
 
1006
                $show_button = apply_filters( 'screen_options_show_submit', false, $this );
 
1007
 
 
1008
                if ( $show_button ) {
 
1009
                        submit_button( __( 'Apply' ), 'primary', 'screen-options-apply', true );
 
1010
                }
 
1011
 
 
1012
                echo $form_end . $wrapper_end;
 
1013
        }
 
1014
 
 
1015
        /**
 
1016
         * Render the meta boxes preferences.
 
1017
         *
 
1018
         * @since 4.4.0
 
1019
         *
 
1020
         * @global array $wp_meta_boxes
 
1021
         */
 
1022
        public function render_meta_boxes_preferences() {
 
1023
                global $wp_meta_boxes;
 
1024
 
 
1025
                if ( ! isset( $wp_meta_boxes[ $this->id ] ) ) {
 
1026
                        return;
 
1027
                }
 
1028
                ?>
 
1029
                <fieldset class="metabox-prefs">
 
1030
                <legend><?php _e( 'Boxes' ); ?></legend>
 
1031
                <?php
 
1032
                        meta_box_prefs( $this );
 
1033
 
 
1034
                        if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
 
1035
                                if ( isset( $_GET['welcome'] ) ) {
 
1036
                                        $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
 
1037
                                        update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
 
1038
                                } else {
 
1039
                                        $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
 
1040
                                        if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
 
1041
                                                $welcome_checked = false;
 
1042
                                        }
 
1043
                                }
 
1044
                                echo '<label for="wp_welcome_panel-hide">';
 
1045
                                echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
 
1046
                                echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
 
1047
                        }
 
1048
                ?>
 
1049
                </fieldset>
 
1050
                <?php
 
1051
        }
 
1052
 
 
1053
        /**
 
1054
         * Render the list table columns preferences.
 
1055
         *
 
1056
         * @since 4.4.0
 
1057
         */
 
1058
        public function render_list_table_columns_preferences() {
 
1059
 
 
1060
                $columns = get_column_headers( $this );
 
1061
                $hidden  = get_hidden_columns( $this );
 
1062
 
 
1063
                if ( ! $columns ) {
 
1064
                        return;
 
1065
                }
 
1066
 
 
1067
                $legend = ! empty( $columns['_title'] ) ? $columns['_title'] : __( 'Columns' );
 
1068
                ?>
 
1069
                <fieldset class="metabox-prefs">
 
1070
                <legend><?php echo $legend; ?></legend>
 
1071
                <?php
 
1072
                $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' );
 
1073
 
 
1074
                foreach ( $columns as $column => $title ) {
 
1075
                        // Can't hide these for they are special
 
1076
                        if ( in_array( $column, $special ) ) {
 
1077
                                continue;
 
1078
                        }
 
1079
 
 
1080
                        if ( empty( $title ) ) {
 
1081
                                continue;
 
1082
                        }
 
1083
 
 
1084
                        if ( 'comments' == $column ) {
 
1085
                                $title = __( 'Comments' );
 
1086
                        }
 
1087
 
 
1088
                        $id = "$column-hide";
 
1089
                        echo '<label>';
 
1090
                        echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" value="' . $column . '"' . checked( ! in_array( $column, $hidden ), true, false ) . ' />';
 
1091
                        echo "$title</label>\n";
 
1092
                }
 
1093
                ?>
 
1094
                </fieldset>
 
1095
                <?php
 
1096
        }
 
1097
 
 
1098
        /**
 
1099
         * Render the option for number of columns on the page
 
1100
         *
 
1101
         * @since 3.3.0
 
1102
         */
 
1103
        public function render_screen_layout() {
 
1104
                if ( ! $this->get_option( 'layout_columns' ) ) {
 
1105
                        return;
 
1106
                }
 
1107
 
 
1108
                $screen_layout_columns = $this->get_columns();
 
1109
                $num = $this->get_option( 'layout_columns', 'max' );
 
1110
 
 
1111
                ?>
 
1112
                <fieldset class='columns-prefs'>
 
1113
                <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php
 
1114
                        for ( $i = 1; $i <= $num; ++$i ):
 
1115
                                ?>
 
1116
                                <label class="columns-prefs-<?php echo $i; ?>">
 
1117
                                        <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
 
1118
                                                <?php checked( $screen_layout_columns, $i ); ?> />
 
1119
                                        <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
 
1120
                                </label>
 
1121
                                <?php
 
1122
                        endfor; ?>
 
1123
                </fieldset>
 
1124
                <?php
 
1125
        }
 
1126
 
 
1127
        /**
 
1128
         * Render the items per page option
 
1129
         *
 
1130
         * @since 3.3.0
 
1131
         */
 
1132
        public function render_per_page_options() {
 
1133
                if ( null === $this->get_option( 'per_page' ) ) {
 
1134
                        return;
 
1135
                }
 
1136
 
 
1137
                $per_page_label = $this->get_option( 'per_page', 'label' );
 
1138
                if ( null === $per_page_label ) {
 
1139
                        $per_page_label = __( 'Number of items per page:' );
 
1140
                }
 
1141
 
 
1142
                $option = $this->get_option( 'per_page', 'option' );
 
1143
                if ( ! $option ) {
 
1144
                        $option = str_replace( '-', '_', "{$this->id}_per_page" );
 
1145
                }
 
1146
 
 
1147
                $per_page = (int) get_user_option( $option );
 
1148
                if ( empty( $per_page ) || $per_page < 1 ) {
 
1149
                        $per_page = $this->get_option( 'per_page', 'default' );
 
1150
                        if ( ! $per_page ) {
 
1151
                                $per_page = 20;
 
1152
                        }
 
1153
                }
 
1154
 
 
1155
                if ( 'edit_comments_per_page' == $option ) {
 
1156
                        $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
 
1157
 
 
1158
                        /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
 
1159
                        $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
 
1160
                } elseif ( 'categories_per_page' == $option ) {
 
1161
                        /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
 
1162
                        $per_page = apply_filters( 'edit_categories_per_page', $per_page );
 
1163
                } else {
 
1164
                        /** This filter is documented in wp-admin/includes/class-wp-list-table.php */
 
1165
                        $per_page = apply_filters( $option, $per_page );
 
1166
                }
 
1167
 
 
1168
                // Back compat
 
1169
                if ( isset( $this->post_type ) ) {
 
1170
                        /** This filter is documented in wp-admin/includes/post.php */
 
1171
                        $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
 
1172
                }
 
1173
 
 
1174
                // This needs a submit button
 
1175
                add_filter( 'screen_options_show_submit', '__return_true' );
 
1176
 
 
1177
                ?>
 
1178
                <fieldset class="screen-options">
 
1179
                <legend><?php _e( 'Pagination' ); ?></legend>
 
1180
                        <?php if ( $per_page_label ) : ?>
 
1181
                                <label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
 
1182
                                <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
 
1183
                                        id="<?php echo esc_attr( $option ); ?>" maxlength="3"
 
1184
                                        value="<?php echo esc_attr( $per_page ); ?>" />
 
1185
                        <?php endif; ?>
 
1186
                                <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
 
1187
                </fieldset>
 
1188
                <?php
 
1189
        }
 
1190
 
 
1191
        /**
 
1192
         * Render the list table view mode preferences.
 
1193
         *
 
1194
         * @since 4.4.0
 
1195
         */
 
1196
        public function render_view_mode() {
 
1197
                $screen = get_current_screen();
 
1198
 
 
1199
                // Currently only enabled for posts lists
 
1200
                if ( 'edit' !== $screen->base ) {
 
1201
                        return;
 
1202
                }
 
1203
 
 
1204
                /**
 
1205
                 * Filter the post types that have different view mode options.
 
1206
                 *
 
1207
                 * @since 4.4.0
 
1208
                 *
 
1209
                 * @param array $view_mode_post_types Array of post types that can change view modes.
 
1210
                 *                                    Default hierarchical post types with show_ui on.
 
1211
                 */
 
1212
                $view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) );
 
1213
                $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
 
1214
 
 
1215
                if ( ! in_array( $this->post_type, $view_mode_post_types ) ) {
 
1216
                        return;
 
1217
                }
 
1218
 
 
1219
                global $mode;
 
1220
 
 
1221
                // This needs a submit button
 
1222
                add_filter( 'screen_options_show_submit', '__return_true' );
 
1223
?>
 
1224
                <fieldset class="metabox-prefs view-mode">
 
1225
                <legend><?php _e( 'View Mode' ); ?></legend>
 
1226
                                <label for="list-view-mode">
 
1227
                                        <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
 
1228
                                        <?php _e( 'List View' ); ?>
 
1229
                                </label>
 
1230
                                <label for="excerpt-view-mode">
 
1231
                                        <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
 
1232
                                        <?php _e( 'Excerpt View' ); ?>
 
1233
                                </label>
 
1234
                </fieldset>
 
1235
<?php
 
1236
        }
 
1237
 
 
1238
        /**
 
1239
         * Render screen reader text.
 
1240
         *
 
1241
         * @since 4.4.0
 
1242
         *
 
1243
         * @param string $key The screen reader text array named key.
 
1244
         * @param string $tag Optional. The HTML tag to wrap the screen reader text. Default h2.
 
1245
         */
 
1246
        public function render_screen_reader_content( $key = '', $tag = 'h2' ) {
 
1247
 
 
1248
                if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
 
1249
                        return;
 
1250
                }
 
1251
                echo "<$tag class='screen-reader-text'>" . $this->_screen_reader_content[ $key ] . "</$tag>";
 
1252
        }
 
1253
}