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