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