|
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
|
|
View Code Duplication |
if ( isset( $_REQUEST['post_type'] ) ) |
|
287
|
|
|
$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false; |
|
288
|
|
View Code Duplication |
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
|
|
|
case 'term' : |
|
308
|
|
|
if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) |
|
309
|
|
|
$post_type = 'post'; |
|
310
|
|
|
break; |
|
311
|
|
|
case 'upload': |
|
312
|
|
|
$post_type = 'attachment'; |
|
313
|
|
|
break; |
|
314
|
|
|
} |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
switch ( $base ) { |
|
318
|
|
|
case 'post' : |
|
319
|
|
|
if ( null === $post_type ) |
|
320
|
|
|
$post_type = 'post'; |
|
321
|
|
|
$id = $post_type; |
|
322
|
|
|
break; |
|
323
|
|
|
case 'edit' : |
|
324
|
|
|
if ( null === $post_type ) |
|
325
|
|
|
$post_type = 'post'; |
|
326
|
|
|
$id .= '-' . $post_type; |
|
327
|
|
|
break; |
|
328
|
|
|
case 'edit-tags' : |
|
329
|
|
|
case 'term' : |
|
330
|
|
|
if ( null === $taxonomy ) |
|
331
|
|
|
$taxonomy = 'post_tag'; |
|
332
|
|
|
// The edit-tags ID does not contain the post type. Look for it in the request. |
|
333
|
|
View Code Duplication |
if ( null === $post_type ) { |
|
334
|
|
|
$post_type = 'post'; |
|
335
|
|
|
if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) |
|
336
|
|
|
$post_type = $_REQUEST['post_type']; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
$id = 'edit-' . $taxonomy; |
|
340
|
|
|
break; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
if ( 'network' == $in_admin ) { |
|
344
|
|
|
$id .= '-network'; |
|
345
|
|
|
$base .= '-network'; |
|
346
|
|
|
} elseif ( 'user' == $in_admin ) { |
|
347
|
|
|
$id .= '-user'; |
|
348
|
|
|
$base .= '-user'; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
if ( isset( self::$_registry[ $id ] ) ) { |
|
352
|
|
|
$screen = self::$_registry[ $id ]; |
|
353
|
|
|
if ( $screen === get_current_screen() ) |
|
354
|
|
|
return $screen; |
|
355
|
|
|
} else { |
|
356
|
|
|
$screen = new WP_Screen(); |
|
357
|
|
|
$screen->id = $id; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
$screen->base = $base; |
|
361
|
|
|
$screen->action = $action; |
|
362
|
|
|
$screen->post_type = (string) $post_type; |
|
363
|
|
|
$screen->taxonomy = (string) $taxonomy; |
|
364
|
|
|
$screen->is_user = ( 'user' == $in_admin ); |
|
365
|
|
|
$screen->is_network = ( 'network' == $in_admin ); |
|
366
|
|
|
$screen->in_admin = $in_admin; |
|
367
|
|
|
|
|
368
|
|
|
self::$_registry[ $id ] = $screen; |
|
369
|
|
|
|
|
370
|
|
|
return $screen; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* Makes the screen object the current screen. |
|
375
|
|
|
* |
|
376
|
|
|
* @see set_current_screen() |
|
377
|
|
|
* @since 3.3.0 |
|
378
|
|
|
* |
|
379
|
|
|
* @global WP_Screen $current_screen |
|
380
|
|
|
* @global string $taxnow |
|
381
|
|
|
* @global string $typenow |
|
382
|
|
|
*/ |
|
383
|
|
|
public function set_current_screen() { |
|
384
|
|
|
global $current_screen, $taxnow, $typenow; |
|
385
|
|
|
$current_screen = $this; |
|
386
|
|
|
$taxnow = $this->taxonomy; |
|
387
|
|
|
$typenow = $this->post_type; |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* Fires after the current screen has been set. |
|
391
|
|
|
* |
|
392
|
|
|
* @since 3.0.0 |
|
393
|
|
|
* |
|
394
|
|
|
* @param WP_Screen $current_screen Current WP_Screen object. |
|
395
|
|
|
*/ |
|
396
|
|
|
do_action( 'current_screen', $current_screen ); |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Constructor |
|
401
|
|
|
* |
|
402
|
|
|
* @since 3.3.0 |
|
403
|
|
|
* @access private |
|
404
|
|
|
*/ |
|
405
|
|
|
private function __construct() {} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* Indicates whether the screen is in a particular admin |
|
409
|
|
|
* |
|
410
|
|
|
* @since 3.5.0 |
|
411
|
|
|
* |
|
412
|
|
|
* @param string $admin The admin to check against (network | user | site). |
|
413
|
|
|
* If empty any of the three admins will result in true. |
|
414
|
|
|
* @return bool True if the screen is in the indicated admin, false otherwise. |
|
415
|
|
|
*/ |
|
416
|
|
|
public function in_admin( $admin = null ) { |
|
417
|
|
|
if ( empty( $admin ) ) |
|
418
|
|
|
return (bool) $this->in_admin; |
|
419
|
|
|
|
|
420
|
|
|
return ( $admin == $this->in_admin ); |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
/** |
|
424
|
|
|
* Sets the old string-based contextual help for the screen for backward compatibility. |
|
425
|
|
|
* |
|
426
|
|
|
* @since 3.3.0 |
|
427
|
|
|
* |
|
428
|
|
|
* @static |
|
429
|
|
|
* |
|
430
|
|
|
* @param WP_Screen $screen A screen object. |
|
431
|
|
|
* @param string $help Help text. |
|
432
|
|
|
*/ |
|
433
|
|
|
public static function add_old_compat_help( $screen, $help ) { |
|
434
|
|
|
self::$_old_compat_help[ $screen->id ] = $help; |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
/** |
|
438
|
|
|
* Set the parent information for the screen. |
|
439
|
|
|
* This is called in admin-header.php after the menu parent for the screen has been determined. |
|
440
|
|
|
* |
|
441
|
|
|
* @since 3.3.0 |
|
442
|
|
|
* |
|
443
|
|
|
* @param string $parent_file The parent file of the screen. Typically the $parent_file global. |
|
444
|
|
|
*/ |
|
445
|
|
|
public function set_parentage( $parent_file ) { |
|
446
|
|
|
$this->parent_file = $parent_file; |
|
447
|
|
|
list( $this->parent_base ) = explode( '?', $parent_file ); |
|
448
|
|
|
$this->parent_base = str_replace( '.php', '', $this->parent_base ); |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* Adds an option for the screen. |
|
453
|
|
|
* Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options. |
|
454
|
|
|
* |
|
455
|
|
|
* @since 3.3.0 |
|
456
|
|
|
* |
|
457
|
|
|
* @param string $option Option ID |
|
458
|
|
|
* @param mixed $args Option-dependent arguments. |
|
459
|
|
|
*/ |
|
460
|
|
|
public function add_option( $option, $args = array() ) { |
|
461
|
|
|
$this->_options[ $option ] = $args; |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
/** |
|
465
|
|
|
* Remove an option from the screen. |
|
466
|
|
|
* |
|
467
|
|
|
* @since 3.8.0 |
|
468
|
|
|
* |
|
469
|
|
|
* @param string $option Option ID. |
|
470
|
|
|
*/ |
|
471
|
|
|
public function remove_option( $option ) { |
|
472
|
|
|
unset( $this->_options[ $option ] ); |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* Remove all options from the screen. |
|
477
|
|
|
* |
|
478
|
|
|
* @since 3.8.0 |
|
479
|
|
|
*/ |
|
480
|
|
|
public function remove_options() { |
|
481
|
|
|
$this->_options = array(); |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
/** |
|
485
|
|
|
* Get the options registered for the screen. |
|
486
|
|
|
* |
|
487
|
|
|
* @since 3.8.0 |
|
488
|
|
|
* |
|
489
|
|
|
* @return array Options with arguments. |
|
490
|
|
|
*/ |
|
491
|
|
|
public function get_options() { |
|
492
|
|
|
return $this->_options; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
/** |
|
496
|
|
|
* Gets the arguments for an option for the screen. |
|
497
|
|
|
* |
|
498
|
|
|
* @since 3.3.0 |
|
499
|
|
|
* |
|
500
|
|
|
* @param string $option Option name. |
|
501
|
|
|
* @param string $key Optional. Specific array key for when the option is an array. |
|
502
|
|
|
* Default false. |
|
503
|
|
|
* @return string The option value if set, null otherwise. |
|
504
|
|
|
*/ |
|
505
|
|
|
public function get_option( $option, $key = false ) { |
|
506
|
|
|
if ( ! isset( $this->_options[ $option ] ) ) |
|
507
|
|
|
return null; |
|
508
|
|
|
if ( $key ) { |
|
|
|
|
|
|
509
|
|
|
if ( isset( $this->_options[ $option ][ $key ] ) ) |
|
510
|
|
|
return $this->_options[ $option ][ $key ]; |
|
511
|
|
|
return null; |
|
512
|
|
|
} |
|
513
|
|
|
return $this->_options[ $option ]; |
|
514
|
|
|
} |
|
515
|
|
|
|
|
516
|
|
|
/** |
|
517
|
|
|
* Gets the help tabs registered for the screen. |
|
518
|
|
|
* |
|
519
|
|
|
* @since 3.4.0 |
|
520
|
|
|
* @since 4.4.0 Help tabs are ordered by their priority. |
|
521
|
|
|
* |
|
522
|
|
|
* @return array Help tabs with arguments. |
|
523
|
|
|
*/ |
|
524
|
|
|
public function get_help_tabs() { |
|
525
|
|
|
$help_tabs = $this->_help_tabs; |
|
526
|
|
|
|
|
527
|
|
|
$priorities = array(); |
|
528
|
|
|
foreach ( $help_tabs as $help_tab ) { |
|
529
|
|
|
if ( isset( $priorities[ $help_tab['priority'] ] ) ) { |
|
530
|
|
|
$priorities[ $help_tab['priority'] ][] = $help_tab; |
|
531
|
|
|
} else { |
|
532
|
|
|
$priorities[ $help_tab['priority'] ] = array( $help_tab ); |
|
533
|
|
|
} |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
ksort( $priorities ); |
|
537
|
|
|
|
|
538
|
|
|
$sorted = array(); |
|
539
|
|
|
foreach ( $priorities as $list ) { |
|
540
|
|
|
foreach ( $list as $tab ) { |
|
541
|
|
|
$sorted[ $tab['id'] ] = $tab; |
|
542
|
|
|
} |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
return $sorted; |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
/** |
|
549
|
|
|
* Gets the arguments for a help tab. |
|
550
|
|
|
* |
|
551
|
|
|
* @since 3.4.0 |
|
552
|
|
|
* |
|
553
|
|
|
* @param string $id Help Tab ID. |
|
554
|
|
|
* @return array Help tab arguments. |
|
555
|
|
|
*/ |
|
556
|
|
|
public function get_help_tab( $id ) { |
|
557
|
|
|
if ( ! isset( $this->_help_tabs[ $id ] ) ) |
|
558
|
|
|
return null; |
|
559
|
|
|
return $this->_help_tabs[ $id ]; |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
/** |
|
563
|
|
|
* Add a help tab to the contextual help for the screen. |
|
564
|
|
|
* Call this on the load-$pagenow hook for the relevant screen. |
|
565
|
|
|
* |
|
566
|
|
|
* @since 3.3.0 |
|
567
|
|
|
* @since 4.4.0 The `$priority` argument was added. |
|
568
|
|
|
* |
|
569
|
|
|
* @param array $args { |
|
570
|
|
|
* Array of arguments used to display the help tab. |
|
571
|
|
|
* |
|
572
|
|
|
* @type string $title Title for the tab. Default false. |
|
573
|
|
|
* @type string $id Tab ID. Must be HTML-safe. Default false. |
|
574
|
|
|
* @type string $content Optional. Help tab content in plain text or HTML. Default empty string. |
|
575
|
|
|
* @type string $callback Optional. A callback to generate the tab content. Default false. |
|
576
|
|
|
* @type int $priority Optional. The priority of the tab, used for ordering. Default 10. |
|
577
|
|
|
* } |
|
578
|
|
|
*/ |
|
579
|
|
|
public function add_help_tab( $args ) { |
|
580
|
|
|
$defaults = array( |
|
581
|
|
|
'title' => false, |
|
582
|
|
|
'id' => false, |
|
583
|
|
|
'content' => '', |
|
584
|
|
|
'callback' => false, |
|
585
|
|
|
'priority' => 10, |
|
586
|
|
|
); |
|
587
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
588
|
|
|
|
|
589
|
|
|
$args['id'] = sanitize_html_class( $args['id'] ); |
|
590
|
|
|
|
|
591
|
|
|
// Ensure we have an ID and title. |
|
592
|
|
|
if ( ! $args['id'] || ! $args['title'] ) |
|
593
|
|
|
return; |
|
594
|
|
|
|
|
595
|
|
|
// Allows for overriding an existing tab with that ID. |
|
596
|
|
|
$this->_help_tabs[ $args['id'] ] = $args; |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
/** |
|
600
|
|
|
* Removes a help tab from the contextual help for the screen. |
|
601
|
|
|
* |
|
602
|
|
|
* @since 3.3.0 |
|
603
|
|
|
* |
|
604
|
|
|
* @param string $id The help tab ID. |
|
605
|
|
|
*/ |
|
606
|
|
|
public function remove_help_tab( $id ) { |
|
607
|
|
|
unset( $this->_help_tabs[ $id ] ); |
|
608
|
|
|
} |
|
609
|
|
|
|
|
610
|
|
|
/** |
|
611
|
|
|
* Removes all help tabs from the contextual help for the screen. |
|
612
|
|
|
* |
|
613
|
|
|
* @since 3.3.0 |
|
614
|
|
|
*/ |
|
615
|
|
|
public function remove_help_tabs() { |
|
616
|
|
|
$this->_help_tabs = array(); |
|
617
|
|
|
} |
|
618
|
|
|
|
|
619
|
|
|
/** |
|
620
|
|
|
* Gets the content from a contextual help sidebar. |
|
621
|
|
|
* |
|
622
|
|
|
* @since 3.4.0 |
|
623
|
|
|
* |
|
624
|
|
|
* @return string Contents of the help sidebar. |
|
625
|
|
|
*/ |
|
626
|
|
|
public function get_help_sidebar() { |
|
627
|
|
|
return $this->_help_sidebar; |
|
628
|
|
|
} |
|
629
|
|
|
|
|
630
|
|
|
/** |
|
631
|
|
|
* Add a sidebar to the contextual help for the screen. |
|
632
|
|
|
* 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. |
|
633
|
|
|
* |
|
634
|
|
|
* @since 3.3.0 |
|
635
|
|
|
* |
|
636
|
|
|
* @param string $content Sidebar content in plain text or HTML. |
|
637
|
|
|
*/ |
|
638
|
|
|
public function set_help_sidebar( $content ) { |
|
639
|
|
|
$this->_help_sidebar = $content; |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
/** |
|
643
|
|
|
* Gets the number of layout columns the user has selected. |
|
644
|
|
|
* |
|
645
|
|
|
* The layout_columns option controls the max number and default number of |
|
646
|
|
|
* columns. This method returns the number of columns within that range selected |
|
647
|
|
|
* by the user via Screen Options. If no selection has been made, the default |
|
648
|
|
|
* provisioned in layout_columns is returned. If the screen does not support |
|
649
|
|
|
* selecting the number of layout columns, 0 is returned. |
|
650
|
|
|
* |
|
651
|
|
|
* @since 3.4.0 |
|
652
|
|
|
* |
|
653
|
|
|
* @return int Number of columns to display. |
|
654
|
|
|
*/ |
|
655
|
|
|
public function get_columns() { |
|
656
|
|
|
return $this->columns; |
|
657
|
|
|
} |
|
658
|
|
|
|
|
659
|
|
|
/** |
|
|
|
|
|
|
660
|
|
|
* Get the accessible hidden headings and text used in the screen. |
|
661
|
|
|
* |
|
662
|
|
|
* @since 4.4.0 |
|
663
|
|
|
* |
|
664
|
|
|
* @see set_screen_reader_content() For more information on the array format. |
|
665
|
|
|
* |
|
666
|
|
|
* @return array An associative array of screen reader text strings. |
|
667
|
|
|
*/ |
|
668
|
|
|
public function get_screen_reader_content() { |
|
669
|
|
|
return $this->_screen_reader_content; |
|
670
|
|
|
} |
|
671
|
|
|
|
|
672
|
|
|
/** |
|
673
|
|
|
* Get a screen reader text string. |
|
674
|
|
|
* |
|
675
|
|
|
* @since 4.4.0 |
|
676
|
|
|
* |
|
677
|
|
|
* @param string $key Screen reader text array named key. |
|
678
|
|
|
* @return string Screen reader text string. |
|
679
|
|
|
*/ |
|
680
|
|
|
public function get_screen_reader_text( $key ) { |
|
681
|
|
|
if ( ! isset( $this->_screen_reader_content[ $key ] ) ) { |
|
682
|
|
|
return null; |
|
683
|
|
|
} |
|
684
|
|
|
return $this->_screen_reader_content[ $key ]; |
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
/** |
|
688
|
|
|
* Add accessible hidden headings and text for the screen. |
|
689
|
|
|
* |
|
690
|
|
|
* @since 4.4.0 |
|
691
|
|
|
* |
|
692
|
|
|
* @param array $content { |
|
693
|
|
|
* An associative array of screen reader text strings. |
|
694
|
|
|
* |
|
695
|
|
|
* @type string $heading_views Screen reader text for the filter links heading. |
|
696
|
|
|
* Default 'Filter items list'. |
|
697
|
|
|
* @type string $heading_pagination Screen reader text for the pagination heading. |
|
698
|
|
|
* Default 'Items list navigation'. |
|
699
|
|
|
* @type string $heading_list Screen reader text for the items list heading. |
|
700
|
|
|
* Default 'Items list'. |
|
701
|
|
|
* } |
|
702
|
|
|
*/ |
|
703
|
|
|
public function set_screen_reader_content( $content = array() ) { |
|
704
|
|
|
$defaults = array( |
|
705
|
|
|
'heading_views' => __( 'Filter items list' ), |
|
706
|
|
|
'heading_pagination' => __( 'Items list navigation' ), |
|
707
|
|
|
'heading_list' => __( 'Items list' ), |
|
708
|
|
|
); |
|
709
|
|
|
$content = wp_parse_args( $content, $defaults ); |
|
710
|
|
|
|
|
711
|
|
|
$this->_screen_reader_content = $content; |
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
/** |
|
715
|
|
|
* Remove all the accessible hidden headings and text for the screen. |
|
716
|
|
|
* |
|
717
|
|
|
* @since 4.4.0 |
|
718
|
|
|
*/ |
|
719
|
|
|
public function remove_screen_reader_content() { |
|
720
|
|
|
$this->_screen_reader_content = array(); |
|
721
|
|
|
} |
|
722
|
|
|
|
|
723
|
|
|
/** |
|
724
|
|
|
* Render the screen's help section. |
|
725
|
|
|
* |
|
726
|
|
|
* This will trigger the deprecated filters for backward compatibility. |
|
727
|
|
|
* |
|
728
|
|
|
* @since 3.3.0 |
|
729
|
|
|
* |
|
730
|
|
|
* @global string $screen_layout_columns |
|
731
|
|
|
*/ |
|
732
|
|
|
public function render_screen_meta() { |
|
733
|
|
|
|
|
734
|
|
|
/** |
|
735
|
|
|
* Filters the legacy contextual help list. |
|
736
|
|
|
* |
|
737
|
|
|
* @since 2.7.0 |
|
738
|
|
|
* @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or |
|
739
|
|
|
* get_current_screen()->remove_help_tab() instead. |
|
740
|
|
|
* |
|
741
|
|
|
* @param array $old_compat_help Old contextual help. |
|
742
|
|
|
* @param WP_Screen $this Current WP_Screen instance. |
|
743
|
|
|
*/ |
|
744
|
|
|
self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this ); |
|
|
|
|
|
|
745
|
|
|
|
|
746
|
|
|
$old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : ''; |
|
747
|
|
|
|
|
748
|
|
|
/** |
|
749
|
|
|
* Filters the legacy contextual help text. |
|
750
|
|
|
* |
|
751
|
|
|
* @since 2.7.0 |
|
752
|
|
|
* @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or |
|
753
|
|
|
* get_current_screen()->remove_help_tab() instead. |
|
754
|
|
|
* |
|
755
|
|
|
* @param string $old_help Help text that appears on the screen. |
|
756
|
|
|
* @param string $screen_id Screen ID. |
|
757
|
|
|
* @param WP_Screen $this Current WP_Screen instance. |
|
758
|
|
|
* |
|
759
|
|
|
*/ |
|
760
|
|
|
$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this ); |
|
761
|
|
|
|
|
762
|
|
|
// Default help only if there is no old-style block of text and no new-style help tabs. |
|
763
|
|
|
if ( empty( $old_help ) && ! $this->get_help_tabs() ) { |
|
764
|
|
|
|
|
765
|
|
|
/** |
|
766
|
|
|
* Filters the default legacy contextual help text. |
|
767
|
|
|
* |
|
768
|
|
|
* @since 2.8.0 |
|
769
|
|
|
* @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or |
|
770
|
|
|
* get_current_screen()->remove_help_tab() instead. |
|
771
|
|
|
* |
|
772
|
|
|
* @param string $old_help_default Default contextual help text. |
|
773
|
|
|
*/ |
|
774
|
|
|
$default_help = apply_filters( 'default_contextual_help', '' ); |
|
775
|
|
|
if ( $default_help ) |
|
776
|
|
|
$old_help = '<p>' . $default_help . '</p>'; |
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
if ( $old_help ) { |
|
780
|
|
|
$this->add_help_tab( array( |
|
781
|
|
|
'id' => 'old-contextual-help', |
|
782
|
|
|
'title' => __('Overview'), |
|
783
|
|
|
'content' => $old_help, |
|
784
|
|
|
) ); |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
$help_sidebar = $this->get_help_sidebar(); |
|
788
|
|
|
|
|
789
|
|
|
$help_class = 'hidden'; |
|
790
|
|
|
if ( ! $help_sidebar ) |
|
791
|
|
|
$help_class .= ' no-sidebar'; |
|
792
|
|
|
|
|
793
|
|
|
// Time to render! |
|
794
|
|
|
?> |
|
795
|
|
|
<div id="screen-meta" class="metabox-prefs"> |
|
796
|
|
|
|
|
797
|
|
|
<div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>"> |
|
798
|
|
|
<div id="contextual-help-back"></div> |
|
799
|
|
|
<div id="contextual-help-columns"> |
|
800
|
|
|
<div class="contextual-help-tabs"> |
|
801
|
|
|
<ul> |
|
802
|
|
|
<?php |
|
803
|
|
|
$class = ' class="active"'; |
|
804
|
|
|
foreach ( $this->get_help_tabs() as $tab ) : |
|
805
|
|
|
$link_id = "tab-link-{$tab['id']}"; |
|
806
|
|
|
$panel_id = "tab-panel-{$tab['id']}"; |
|
807
|
|
|
?> |
|
808
|
|
|
|
|
809
|
|
|
<li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>> |
|
810
|
|
|
<a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>"> |
|
811
|
|
|
<?php echo esc_html( $tab['title'] ); ?> |
|
812
|
|
|
</a> |
|
813
|
|
|
</li> |
|
814
|
|
|
<?php |
|
815
|
|
|
$class = ''; |
|
816
|
|
|
endforeach; |
|
817
|
|
|
?> |
|
818
|
|
|
</ul> |
|
819
|
|
|
</div> |
|
820
|
|
|
|
|
821
|
|
|
<?php if ( $help_sidebar ) : ?> |
|
822
|
|
|
<div class="contextual-help-sidebar"> |
|
823
|
|
|
<?php echo $help_sidebar; ?> |
|
824
|
|
|
</div> |
|
825
|
|
|
<?php endif; ?> |
|
826
|
|
|
|
|
827
|
|
|
<div class="contextual-help-tabs-wrap"> |
|
828
|
|
|
<?php |
|
829
|
|
|
$classes = 'help-tab-content active'; |
|
830
|
|
|
foreach ( $this->get_help_tabs() as $tab ): |
|
831
|
|
|
$panel_id = "tab-panel-{$tab['id']}"; |
|
832
|
|
|
?> |
|
833
|
|
|
|
|
834
|
|
|
<div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>"> |
|
835
|
|
|
<?php |
|
836
|
|
|
// Print tab content. |
|
837
|
|
|
echo $tab['content']; |
|
838
|
|
|
|
|
839
|
|
|
// If it exists, fire tab callback. |
|
840
|
|
|
if ( ! empty( $tab['callback'] ) ) |
|
841
|
|
|
call_user_func_array( $tab['callback'], array( $this, $tab ) ); |
|
842
|
|
|
?> |
|
843
|
|
|
</div> |
|
844
|
|
|
<?php |
|
845
|
|
|
$classes = 'help-tab-content'; |
|
846
|
|
|
endforeach; |
|
847
|
|
|
?> |
|
848
|
|
|
</div> |
|
849
|
|
|
</div> |
|
850
|
|
|
</div> |
|
851
|
|
|
<?php |
|
852
|
|
|
// Setup layout columns |
|
853
|
|
|
|
|
854
|
|
|
/** |
|
855
|
|
|
* Filters the array of screen layout columns. |
|
856
|
|
|
* |
|
857
|
|
|
* This hook provides back-compat for plugins using the back-compat |
|
858
|
|
|
* Filters instead of add_screen_option(). |
|
859
|
|
|
* |
|
860
|
|
|
* @since 2.8.0 |
|
861
|
|
|
* |
|
862
|
|
|
* @param array $empty_columns Empty array. |
|
863
|
|
|
* @param string $screen_id Screen ID. |
|
864
|
|
|
* @param WP_Screen $this Current WP_Screen instance. |
|
865
|
|
|
*/ |
|
866
|
|
|
$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this ); |
|
867
|
|
|
|
|
868
|
|
|
if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) |
|
869
|
|
|
$this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); |
|
870
|
|
|
|
|
871
|
|
|
if ( $this->get_option( 'layout_columns' ) ) { |
|
872
|
|
|
$this->columns = (int) get_user_option("screen_layout_$this->id"); |
|
873
|
|
|
|
|
874
|
|
|
if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) |
|
875
|
|
|
$this->columns = $this->get_option( 'layout_columns', 'default' ); |
|
|
|
|
|
|
876
|
|
|
} |
|
877
|
|
|
$GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat. |
|
878
|
|
|
|
|
879
|
|
|
// Add screen options |
|
880
|
|
|
if ( $this->show_screen_options() ) |
|
881
|
|
|
$this->render_screen_options(); |
|
882
|
|
|
?> |
|
883
|
|
|
</div> |
|
884
|
|
|
<?php |
|
885
|
|
|
if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) |
|
886
|
|
|
return; |
|
887
|
|
|
?> |
|
888
|
|
|
<div id="screen-meta-links"> |
|
889
|
|
|
<?php if ( $this->get_help_tabs() ) : ?> |
|
890
|
|
|
<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle"> |
|
891
|
|
|
<button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button> |
|
892
|
|
|
</div> |
|
893
|
|
|
<?php endif; |
|
894
|
|
|
if ( $this->show_screen_options() ) : ?> |
|
895
|
|
|
<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle"> |
|
896
|
|
|
<button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button> |
|
897
|
|
|
</div> |
|
898
|
|
|
<?php endif; ?> |
|
899
|
|
|
</div> |
|
900
|
|
|
<?php |
|
901
|
|
|
} |
|
902
|
|
|
|
|
903
|
|
|
/** |
|
904
|
|
|
* |
|
905
|
|
|
* @global array $wp_meta_boxes |
|
906
|
|
|
* |
|
907
|
|
|
* @return bool |
|
908
|
|
|
*/ |
|
909
|
|
|
public function show_screen_options() { |
|
910
|
|
|
global $wp_meta_boxes; |
|
911
|
|
|
|
|
912
|
|
|
if ( is_bool( $this->_show_screen_options ) ) |
|
913
|
|
|
return $this->_show_screen_options; |
|
914
|
|
|
|
|
915
|
|
|
$columns = get_column_headers( $this ); |
|
916
|
|
|
|
|
917
|
|
|
$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' ); |
|
|
|
|
|
|
918
|
|
|
|
|
919
|
|
|
switch ( $this->base ) { |
|
920
|
|
|
case 'widgets': |
|
921
|
|
|
$nonce = wp_create_nonce( 'widgets-access' ); |
|
922
|
|
|
$this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=' . urlencode( $nonce ) . '">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=' . urlencode( $nonce ) . '">' . __('Disable accessibility mode') . "</a></p>\n"; |
|
923
|
|
|
break; |
|
924
|
|
|
case 'post' : |
|
925
|
|
|
$expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">'; |
|
926
|
|
|
$expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />'; |
|
927
|
|
|
$expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>'; |
|
928
|
|
|
$this->_screen_settings = $expand; |
|
929
|
|
|
break; |
|
930
|
|
|
default: |
|
931
|
|
|
$this->_screen_settings = ''; |
|
932
|
|
|
break; |
|
933
|
|
|
} |
|
934
|
|
|
|
|
935
|
|
|
/** |
|
936
|
|
|
* Filters the screen settings text displayed in the Screen Options tab. |
|
937
|
|
|
* |
|
938
|
|
|
* This filter is currently only used on the Widgets screen to enable |
|
939
|
|
|
* accessibility mode. |
|
940
|
|
|
* |
|
941
|
|
|
* @since 3.0.0 |
|
942
|
|
|
* |
|
943
|
|
|
* @param string $screen_settings Screen settings. |
|
944
|
|
|
* @param WP_Screen $this WP_Screen object. |
|
945
|
|
|
*/ |
|
946
|
|
|
$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this ); |
|
947
|
|
|
|
|
948
|
|
|
if ( $this->_screen_settings || $this->_options ) |
|
|
|
|
|
|
949
|
|
|
$show_screen = true; |
|
950
|
|
|
|
|
951
|
|
|
/** |
|
952
|
|
|
* Filters whether to show the Screen Options tab. |
|
953
|
|
|
* |
|
954
|
|
|
* @since 3.2.0 |
|
955
|
|
|
* |
|
956
|
|
|
* @param bool $show_screen Whether to show Screen Options tab. |
|
957
|
|
|
* Default true. |
|
958
|
|
|
* @param WP_Screen $this Current WP_Screen instance. |
|
959
|
|
|
*/ |
|
960
|
|
|
$this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this ); |
|
961
|
|
|
return $this->_show_screen_options; |
|
962
|
|
|
} |
|
963
|
|
|
|
|
964
|
|
|
/** |
|
965
|
|
|
* Render the screen options tab. |
|
966
|
|
|
* |
|
967
|
|
|
* @since 3.3.0 |
|
968
|
|
|
* |
|
969
|
|
|
* @param array $options { |
|
970
|
|
|
* @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true. |
|
971
|
|
|
* } |
|
972
|
|
|
*/ |
|
973
|
|
|
public function render_screen_options( $options = array() ) { |
|
974
|
|
|
$options = wp_parse_args( $options, array( |
|
975
|
|
|
'wrap' => true, |
|
976
|
|
|
) ); |
|
977
|
|
|
|
|
978
|
|
|
$wrapper_start = $wrapper_end = $form_start = $form_end = ''; |
|
979
|
|
|
|
|
980
|
|
|
// Output optional wrapper. |
|
981
|
|
|
if ( $options['wrap'] ) { |
|
982
|
|
|
$wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">'; |
|
983
|
|
|
$wrapper_end = '</div>'; |
|
984
|
|
|
} |
|
985
|
|
|
|
|
986
|
|
|
// Don't output the form and nonce for the widgets accessibility mode links. |
|
987
|
|
|
if ( 'widgets' !== $this->base ) { |
|
988
|
|
|
$form_start = "\n<form id='adv-settings' method='post'>\n"; |
|
989
|
|
|
$form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n"; |
|
990
|
|
|
} |
|
991
|
|
|
|
|
992
|
|
|
echo $wrapper_start . $form_start; |
|
993
|
|
|
|
|
994
|
|
|
$this->render_meta_boxes_preferences(); |
|
995
|
|
|
$this->render_list_table_columns_preferences(); |
|
996
|
|
|
$this->render_screen_layout(); |
|
997
|
|
|
$this->render_per_page_options(); |
|
998
|
|
|
$this->render_view_mode(); |
|
999
|
|
|
echo $this->_screen_settings; |
|
1000
|
|
|
|
|
1001
|
|
|
/** |
|
1002
|
|
|
* Filters whether to show the Screen Options submit button. |
|
1003
|
|
|
* |
|
1004
|
|
|
* @since 4.4.0 |
|
1005
|
|
|
* |
|
1006
|
|
|
* @param bool $show_button Whether to show Screen Options submit button. |
|
1007
|
|
|
* Default false. |
|
1008
|
|
|
* @param WP_Screen $this Current WP_Screen instance. |
|
1009
|
|
|
*/ |
|
1010
|
|
|
$show_button = apply_filters( 'screen_options_show_submit', false, $this ); |
|
1011
|
|
|
|
|
1012
|
|
|
if ( $show_button ) { |
|
1013
|
|
|
submit_button( __( 'Apply' ), 'primary', 'screen-options-apply', true ); |
|
1014
|
|
|
} |
|
1015
|
|
|
|
|
1016
|
|
|
echo $form_end . $wrapper_end; |
|
1017
|
|
|
} |
|
1018
|
|
|
|
|
1019
|
|
|
/** |
|
1020
|
|
|
* Render the meta boxes preferences. |
|
1021
|
|
|
* |
|
1022
|
|
|
* @since 4.4.0 |
|
1023
|
|
|
* |
|
1024
|
|
|
* @global array $wp_meta_boxes |
|
1025
|
|
|
*/ |
|
1026
|
|
|
public function render_meta_boxes_preferences() { |
|
1027
|
|
|
global $wp_meta_boxes; |
|
1028
|
|
|
|
|
1029
|
|
|
if ( ! isset( $wp_meta_boxes[ $this->id ] ) ) { |
|
1030
|
|
|
return; |
|
1031
|
|
|
} |
|
1032
|
|
|
?> |
|
1033
|
|
|
<fieldset class="metabox-prefs"> |
|
1034
|
|
|
<legend><?php _e( 'Boxes' ); ?></legend> |
|
1035
|
|
|
<?php |
|
1036
|
|
|
meta_box_prefs( $this ); |
|
1037
|
|
|
|
|
1038
|
|
|
if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) { |
|
1039
|
|
|
if ( isset( $_GET['welcome'] ) ) { |
|
1040
|
|
|
$welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; |
|
1041
|
|
|
update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); |
|
1042
|
|
|
} else { |
|
1043
|
|
|
$welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); |
|
1044
|
|
|
if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) { |
|
1045
|
|
|
$welcome_checked = false; |
|
1046
|
|
|
} |
|
1047
|
|
|
} |
|
1048
|
|
|
echo '<label for="wp_welcome_panel-hide">'; |
|
1049
|
|
|
echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; |
|
1050
|
|
|
echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; |
|
1051
|
|
|
} |
|
1052
|
|
|
?> |
|
1053
|
|
|
</fieldset> |
|
1054
|
|
|
<?php |
|
1055
|
|
|
} |
|
1056
|
|
|
|
|
1057
|
|
|
/** |
|
1058
|
|
|
* Render the list table columns preferences. |
|
1059
|
|
|
* |
|
1060
|
|
|
* @since 4.4.0 |
|
1061
|
|
|
*/ |
|
1062
|
|
|
public function render_list_table_columns_preferences() { |
|
1063
|
|
|
|
|
1064
|
|
|
$columns = get_column_headers( $this ); |
|
1065
|
|
|
$hidden = get_hidden_columns( $this ); |
|
1066
|
|
|
|
|
1067
|
|
|
if ( ! $columns ) { |
|
|
|
|
|
|
1068
|
|
|
return; |
|
1069
|
|
|
} |
|
1070
|
|
|
|
|
1071
|
|
|
$legend = ! empty( $columns['_title'] ) ? $columns['_title'] : __( 'Columns' ); |
|
1072
|
|
|
?> |
|
1073
|
|
|
<fieldset class="metabox-prefs"> |
|
1074
|
|
|
<legend><?php echo $legend; ?></legend> |
|
1075
|
|
|
<?php |
|
1076
|
|
|
$special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' ); |
|
1077
|
|
|
|
|
1078
|
|
|
foreach ( $columns as $column => $title ) { |
|
1079
|
|
|
// Can't hide these for they are special |
|
1080
|
|
|
if ( in_array( $column, $special ) ) { |
|
1081
|
|
|
continue; |
|
1082
|
|
|
} |
|
1083
|
|
|
|
|
1084
|
|
|
if ( empty( $title ) ) { |
|
1085
|
|
|
continue; |
|
1086
|
|
|
} |
|
1087
|
|
|
|
|
1088
|
|
|
if ( 'comments' == $column ) { |
|
1089
|
|
|
$title = __( 'Comments' ); |
|
1090
|
|
|
} |
|
1091
|
|
|
|
|
1092
|
|
|
$id = "$column-hide"; |
|
1093
|
|
|
echo '<label>'; |
|
1094
|
|
|
echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( ! in_array( $column, $hidden ), true, false ) . ' />'; |
|
1095
|
|
|
echo "$title</label>\n"; |
|
1096
|
|
|
} |
|
1097
|
|
|
?> |
|
1098
|
|
|
</fieldset> |
|
1099
|
|
|
<?php |
|
1100
|
|
|
} |
|
1101
|
|
|
|
|
1102
|
|
|
/** |
|
1103
|
|
|
* Render the option for number of columns on the page |
|
1104
|
|
|
* |
|
1105
|
|
|
* @since 3.3.0 |
|
1106
|
|
|
*/ |
|
1107
|
|
|
public function render_screen_layout() { |
|
1108
|
|
|
if ( ! $this->get_option( 'layout_columns' ) ) { |
|
1109
|
|
|
return; |
|
1110
|
|
|
} |
|
1111
|
|
|
|
|
1112
|
|
|
$screen_layout_columns = $this->get_columns(); |
|
1113
|
|
|
$num = $this->get_option( 'layout_columns', 'max' ); |
|
1114
|
|
|
|
|
1115
|
|
|
?> |
|
1116
|
|
|
<fieldset class='columns-prefs'> |
|
1117
|
|
|
<legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php |
|
1118
|
|
|
for ( $i = 1; $i <= $num; ++$i ): |
|
1119
|
|
|
?> |
|
1120
|
|
|
<label class="columns-prefs-<?php echo $i; ?>"> |
|
1121
|
|
|
<input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' |
|
1122
|
|
|
<?php checked( $screen_layout_columns, $i ); ?> /> |
|
1123
|
|
|
<?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?> |
|
1124
|
|
|
</label> |
|
1125
|
|
|
<?php |
|
1126
|
|
|
endfor; ?> |
|
1127
|
|
|
</fieldset> |
|
1128
|
|
|
<?php |
|
1129
|
|
|
} |
|
1130
|
|
|
|
|
1131
|
|
|
/** |
|
1132
|
|
|
* Render the items per page option |
|
1133
|
|
|
* |
|
1134
|
|
|
* @since 3.3.0 |
|
1135
|
|
|
*/ |
|
1136
|
|
|
public function render_per_page_options() { |
|
1137
|
|
|
if ( null === $this->get_option( 'per_page' ) ) { |
|
1138
|
|
|
return; |
|
1139
|
|
|
} |
|
1140
|
|
|
|
|
1141
|
|
|
$per_page_label = $this->get_option( 'per_page', 'label' ); |
|
1142
|
|
|
if ( null === $per_page_label ) { |
|
1143
|
|
|
$per_page_label = __( 'Number of items per page:' ); |
|
1144
|
|
|
} |
|
1145
|
|
|
|
|
1146
|
|
|
$option = $this->get_option( 'per_page', 'option' ); |
|
1147
|
|
|
if ( ! $option ) { |
|
1148
|
|
|
$option = str_replace( '-', '_', "{$this->id}_per_page" ); |
|
1149
|
|
|
} |
|
1150
|
|
|
|
|
1151
|
|
|
$per_page = (int) get_user_option( $option ); |
|
1152
|
|
|
if ( empty( $per_page ) || $per_page < 1 ) { |
|
1153
|
|
|
$per_page = $this->get_option( 'per_page', 'default' ); |
|
1154
|
|
|
if ( ! $per_page ) { |
|
1155
|
|
|
$per_page = 20; |
|
1156
|
|
|
} |
|
1157
|
|
|
} |
|
1158
|
|
|
|
|
1159
|
|
|
if ( 'edit_comments_per_page' == $option ) { |
|
1160
|
|
|
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; |
|
1161
|
|
|
|
|
1162
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */ |
|
1163
|
|
|
$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status ); |
|
1164
|
|
|
} elseif ( 'categories_per_page' == $option ) { |
|
1165
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */ |
|
1166
|
|
|
$per_page = apply_filters( 'edit_categories_per_page', $per_page ); |
|
1167
|
|
|
} else { |
|
1168
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-list-table.php */ |
|
1169
|
|
|
$per_page = apply_filters( "{$option}", $per_page ); |
|
1170
|
|
|
} |
|
1171
|
|
|
|
|
1172
|
|
|
// Back compat |
|
1173
|
|
|
if ( isset( $this->post_type ) ) { |
|
1174
|
|
|
/** This filter is documented in wp-admin/includes/post.php */ |
|
1175
|
|
|
$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type ); |
|
1176
|
|
|
} |
|
1177
|
|
|
|
|
1178
|
|
|
// This needs a submit button |
|
1179
|
|
|
add_filter( 'screen_options_show_submit', '__return_true' ); |
|
1180
|
|
|
|
|
1181
|
|
|
?> |
|
1182
|
|
|
<fieldset class="screen-options"> |
|
1183
|
|
|
<legend><?php _e( 'Pagination' ); ?></legend> |
|
1184
|
|
|
<?php if ( $per_page_label ) : ?> |
|
1185
|
|
|
<label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label> |
|
1186
|
|
|
<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" |
|
1187
|
|
|
id="<?php echo esc_attr( $option ); ?>" maxlength="3" |
|
1188
|
|
|
value="<?php echo esc_attr( $per_page ); ?>" /> |
|
1189
|
|
|
<?php endif; ?> |
|
1190
|
|
|
<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" /> |
|
1191
|
|
|
</fieldset> |
|
1192
|
|
|
<?php |
|
1193
|
|
|
} |
|
1194
|
|
|
|
|
1195
|
|
|
/** |
|
1196
|
|
|
* Render the list table view mode preferences. |
|
1197
|
|
|
* |
|
1198
|
|
|
* @since 4.4.0 |
|
1199
|
|
|
* |
|
1200
|
|
|
* @global string $mode List table view mode. |
|
1201
|
|
|
*/ |
|
1202
|
|
|
public function render_view_mode() { |
|
1203
|
|
|
$screen = get_current_screen(); |
|
1204
|
|
|
|
|
1205
|
|
|
// Currently only enabled for posts lists |
|
1206
|
|
|
if ( 'edit' !== $screen->base ) { |
|
1207
|
|
|
return; |
|
1208
|
|
|
} |
|
1209
|
|
|
|
|
1210
|
|
|
$view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) ); |
|
1211
|
|
|
|
|
1212
|
|
|
/** |
|
1213
|
|
|
* Filters the post types that have different view mode options. |
|
1214
|
|
|
* |
|
1215
|
|
|
* @since 4.4.0 |
|
1216
|
|
|
* |
|
1217
|
|
|
* @param array $view_mode_post_types Array of post types that can change view modes. |
|
1218
|
|
|
* Default hierarchical post types with show_ui on. |
|
1219
|
|
|
*/ |
|
1220
|
|
|
$view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types ); |
|
1221
|
|
|
|
|
1222
|
|
|
if ( ! in_array( $this->post_type, $view_mode_post_types ) ) { |
|
1223
|
|
|
return; |
|
1224
|
|
|
} |
|
1225
|
|
|
|
|
1226
|
|
|
global $mode; |
|
1227
|
|
|
|
|
1228
|
|
|
// This needs a submit button |
|
1229
|
|
|
add_filter( 'screen_options_show_submit', '__return_true' ); |
|
1230
|
|
|
?> |
|
1231
|
|
|
<fieldset class="metabox-prefs view-mode"> |
|
1232
|
|
|
<legend><?php _e( 'View Mode' ); ?></legend> |
|
1233
|
|
|
<label for="list-view-mode"> |
|
1234
|
|
|
<input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> /> |
|
1235
|
|
|
<?php _e( 'List View' ); ?> |
|
1236
|
|
|
</label> |
|
1237
|
|
|
<label for="excerpt-view-mode"> |
|
1238
|
|
|
<input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> /> |
|
1239
|
|
|
<?php _e( 'Excerpt View' ); ?> |
|
1240
|
|
|
</label> |
|
1241
|
|
|
</fieldset> |
|
1242
|
|
|
<?php |
|
1243
|
|
|
} |
|
1244
|
|
|
|
|
1245
|
|
|
/** |
|
1246
|
|
|
* Render screen reader text. |
|
1247
|
|
|
* |
|
1248
|
|
|
* @since 4.4.0 |
|
1249
|
|
|
* |
|
1250
|
|
|
* @param string $key The screen reader text array named key. |
|
1251
|
|
|
* @param string $tag Optional. The HTML tag to wrap the screen reader text. Default h2. |
|
1252
|
|
|
*/ |
|
1253
|
|
|
public function render_screen_reader_content( $key = '', $tag = 'h2' ) { |
|
1254
|
|
|
|
|
1255
|
|
|
if ( ! isset( $this->_screen_reader_content[ $key ] ) ) { |
|
1256
|
|
|
return; |
|
1257
|
|
|
} |
|
1258
|
|
|
echo "<$tag class='screen-reader-text'>" . $this->_screen_reader_content[ $key ] . "</$tag>"; |
|
1259
|
|
|
} |
|
1260
|
|
|
} |
|
1261
|
|
|
|