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