wp/wp-admin/includes/class-wp-screen.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
   106 	public $post_type;
   106 	public $post_type;
   107 
   107 
   108 	/**
   108 	/**
   109 	 * The taxonomy associated with the screen, if any.
   109 	 * The taxonomy associated with the screen, if any.
   110 	 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
   110 	 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
       
   111 	 *
   111 	 * @since 3.3.0
   112 	 * @since 3.3.0
   112 	 * @var string
   113 	 * @var string
   113 	 */
   114 	 */
   114 	public $taxonomy;
   115 	public $taxonomy;
   115 
   116 
   127 	 * @since 3.3.0
   128 	 * @since 3.3.0
   128 	 * @var string
   129 	 * @var string
   129 	 */
   130 	 */
   130 	private $_help_sidebar = '';
   131 	private $_help_sidebar = '';
   131 
   132 
   132  	/**
   133 	/**
   133 	 * The accessible hidden headings and text associated with the screen, if any.
   134 	 * The accessible hidden headings and text associated with the screen, if any.
   134 	 *
   135 	 *
   135 	 * @since 4.4.0
   136 	 * @since 4.4.0
   136 	 * @var array
   137 	 * @var array
   137 	 */
   138 	 */
   138 	private $_screen_reader_content = array();
   139 	private $_screen_reader_content = array();
   139 
   140 
   140 	/**
   141 	/**
   141 	 * Stores old string-based help.
   142 	 * Stores old string-based help.
   142 	 *
   143 	 *
   143 	 * @static
       
   144 	 *
       
   145 	 * @var array
   144 	 * @var array
   146 	 */
   145 	 */
   147 	private static $_old_compat_help = array();
   146 	private static $_old_compat_help = array();
   148 
   147 
   149 	/**
   148 	/**
   157 	/**
   156 	/**
   158 	 * The screen object registry.
   157 	 * The screen object registry.
   159 	 *
   158 	 *
   160 	 * @since 3.3.0
   159 	 * @since 3.3.0
   161 	 *
   160 	 *
   162 	 * @static
       
   163 	 *
       
   164 	 * @var array
   161 	 * @var array
   165 	 */
   162 	 */
   166 	private static $_registry = array();
   163 	private static $_registry = array();
   167 
   164 
   168 	/**
   165 	/**
   180 	 * @var string
   177 	 * @var string
   181 	 */
   178 	 */
   182 	private $_screen_settings;
   179 	private $_screen_settings;
   183 
   180 
   184 	/**
   181 	/**
       
   182 	 * Whether the screen is using the block editor.
       
   183 	 *
       
   184 	 * @since 5.0.0
       
   185 	 * @var bool
       
   186 	 */
       
   187 	public $is_block_editor = false;
       
   188 
       
   189 	/**
   185 	 * Fetches a screen object.
   190 	 * Fetches a screen object.
   186 	 *
   191 	 *
   187 	 * @since 3.3.0
   192 	 * @since 3.3.0
   188 	 *
   193 	 *
   189 	 * @static
       
   190 	 *
       
   191 	 * @global string $hook_suffix
   194 	 * @global string $hook_suffix
   192 	 *
   195 	 *
   193 	 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
   196 	 * @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.
   197 	 *                                    Defaults to the current $hook_suffix global.
   195 	 * @return WP_Screen Screen object.
   198 	 * @return WP_Screen Screen object.
   196 	 */
   199 	 */
   197 	public static function get( $hook_name = '' ) {
   200 	public static function get( $hook_name = '' ) {
   198 		if ( $hook_name instanceof WP_Screen ) {
   201 		if ( $hook_name instanceof WP_Screen ) {
   199 			return $hook_name;
   202 			return $hook_name;
   200 		}
   203 		}
   201 
   204 
   202 		$post_type = $taxonomy = null;
   205 		$post_type       = $taxonomy = null;
   203 		$in_admin = false;
   206 		$in_admin        = false;
   204 		$action = '';
   207 		$action          = '';
   205 
   208 		$is_block_editor = false;
   206 		if ( $hook_name )
   209 
       
   210 		if ( $hook_name ) {
   207 			$id = $hook_name;
   211 			$id = $hook_name;
   208 		else
   212 		} else {
   209 			$id = $GLOBALS['hook_suffix'];
   213 			$id = $GLOBALS['hook_suffix'];
       
   214 		}
   210 
   215 
   211 		// For those pesky meta boxes.
   216 		// For those pesky meta boxes.
   212 		if ( $hook_name && post_type_exists( $hook_name ) ) {
   217 		if ( $hook_name && post_type_exists( $hook_name ) ) {
   213 			$post_type = $id;
   218 			$post_type = $id;
   214 			$id = 'post'; // changes later. ends up being $base.
   219 			$id        = 'post'; // changes later. ends up being $base.
   215 		} else {
   220 		} else {
   216 			if ( '.php' == substr( $id, -4 ) )
   221 			if ( '.php' == substr( $id, -4 ) ) {
   217 				$id = substr( $id, 0, -4 );
   222 				$id = substr( $id, 0, -4 );
       
   223 			}
   218 
   224 
   219 			if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
   225 			if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
   220 				$id = substr( $id, 0, -4 );
   226 				$id     = substr( $id, 0, -4 );
   221 				$action = 'add';
   227 				$action = 'add';
   222 			}
   228 			}
   223 		}
   229 		}
   224 
   230 
   225 		if ( ! $post_type && $hook_name ) {
   231 		if ( ! $post_type && $hook_name ) {
   226 			if ( '-network' == substr( $id, -8 ) ) {
   232 			if ( '-network' == substr( $id, -8 ) ) {
   227 				$id = substr( $id, 0, -8 );
   233 				$id       = substr( $id, 0, -8 );
   228 				$in_admin = 'network';
   234 				$in_admin = 'network';
   229 			} elseif ( '-user' == substr( $id, -5 ) ) {
   235 			} elseif ( '-user' == substr( $id, -5 ) ) {
   230 				$id = substr( $id, 0, -5 );
   236 				$id       = substr( $id, 0, -5 );
   231 				$in_admin = 'user';
   237 				$in_admin = 'user';
   232 			}
   238 			}
   233 
   239 
   234 			$id = sanitize_key( $id );
   240 			$id = sanitize_key( $id );
   235 			if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
   241 			if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
   236 				$maybe = substr( $id, 5 );
   242 				$maybe = substr( $id, 5 );
   237 				if ( taxonomy_exists( $maybe ) ) {
   243 				if ( taxonomy_exists( $maybe ) ) {
   238 					$id = 'edit-tags';
   244 					$id       = 'edit-tags';
   239 					$taxonomy = $maybe;
   245 					$taxonomy = $maybe;
   240 				} elseif ( post_type_exists( $maybe ) ) {
   246 				} elseif ( post_type_exists( $maybe ) ) {
   241 					$id = 'edit';
   247 					$id        = 'edit';
   242 					$post_type = $maybe;
   248 					$post_type = $maybe;
   243 				}
   249 				}
   244 			}
   250 			}
   245 
   251 
   246 			if ( ! $in_admin )
   252 			if ( ! $in_admin ) {
   247 				$in_admin = 'site';
   253 				$in_admin = 'site';
       
   254 			}
   248 		} else {
   255 		} else {
   249 			if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
   256 			if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) {
   250 				$in_admin = 'network';
   257 				$in_admin = 'network';
   251 			elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
   258 			} elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) {
   252 				$in_admin = 'user';
   259 				$in_admin = 'user';
   253 			else
   260 			} else {
   254 				$in_admin = 'site';
   261 				$in_admin = 'site';
   255 		}
   262 			}
   256 
   263 		}
   257 		if ( 'index' == $id )
   264 
       
   265 		if ( 'index' == $id ) {
   258 			$id = 'dashboard';
   266 			$id = 'dashboard';
   259 		elseif ( 'front' == $id )
   267 		} elseif ( 'front' == $id ) {
   260 			$in_admin = false;
   268 			$in_admin = false;
       
   269 		}
   261 
   270 
   262 		$base = $id;
   271 		$base = $id;
   263 
   272 
   264 		// If this is the current screen, see if we can be more accurate for post types and taxonomies.
   273 		// If this is the current screen, see if we can be more accurate for post types and taxonomies.
   265 		if ( ! $hook_name ) {
   274 		if ( ! $hook_name ) {
   266 			if ( isset( $_REQUEST['post_type'] ) )
   275 			if ( isset( $_REQUEST['post_type'] ) ) {
   267 				$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
   276 				$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
   268 			if ( isset( $_REQUEST['taxonomy'] ) )
   277 			}
       
   278 			if ( isset( $_REQUEST['taxonomy'] ) ) {
   269 				$taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
   279 				$taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
       
   280 			}
   270 
   281 
   271 			switch ( $base ) {
   282 			switch ( $base ) {
   272 				case 'post' :
   283 				case 'post':
   273 					if ( isset( $_GET['post'] ) )
   284 					if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) {
       
   285 						wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
       
   286 					} elseif ( isset( $_GET['post'] ) ) {
   274 						$post_id = (int) $_GET['post'];
   287 						$post_id = (int) $_GET['post'];
   275 					elseif ( isset( $_POST['post_ID'] ) )
   288 					} elseif ( isset( $_POST['post_ID'] ) ) {
   276 						$post_id = (int) $_POST['post_ID'];
   289 						$post_id = (int) $_POST['post_ID'];
   277 					else
   290 					} else {
   278 						$post_id = 0;
   291 						$post_id = 0;
       
   292 					}
   279 
   293 
   280 					if ( $post_id ) {
   294 					if ( $post_id ) {
   281 						$post = get_post( $post_id );
   295 						$post = get_post( $post_id );
   282 						if ( $post )
   296 						if ( $post ) {
   283 							$post_type = $post->post_type;
   297 							$post_type = $post->post_type;
       
   298 
       
   299 							/** This filter is documented in wp-admin/post.php */
       
   300 							$replace_editor = apply_filters( 'replace_editor', false, $post );
       
   301 
       
   302 							if ( ! $replace_editor ) {
       
   303 								$is_block_editor = use_block_editor_for_post( $post );
       
   304 							}
       
   305 						}
   284 					}
   306 					}
   285 					break;
   307 					break;
   286 				case 'edit-tags' :
   308 				case 'edit-tags':
   287 				case 'term' :
   309 				case 'term':
   288 					if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
   310 					if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) {
   289 						$post_type = 'post';
   311 						$post_type = 'post';
       
   312 					}
   290 					break;
   313 					break;
   291 				case 'upload':
   314 				case 'upload':
   292 					$post_type = 'attachment';
   315 					$post_type = 'attachment';
   293 					break;
   316 					break;
   294 			}
   317 			}
   295 		}
   318 		}
   296 
   319 
   297 		switch ( $base ) {
   320 		switch ( $base ) {
   298 			case 'post' :
   321 			case 'post':
   299 				if ( null === $post_type )
   322 				if ( null === $post_type ) {
   300 					$post_type = 'post';
   323 					$post_type = 'post';
       
   324 				}
       
   325 
       
   326 				// When creating a new post, use the default block editor support value for the post type.
       
   327 				if ( empty( $post_id ) ) {
       
   328 					$is_block_editor = use_block_editor_for_post_type( $post_type );
       
   329 				}
       
   330 
   301 				$id = $post_type;
   331 				$id = $post_type;
   302 				break;
   332 				break;
   303 			case 'edit' :
   333 			case 'edit':
   304 				if ( null === $post_type )
   334 				if ( null === $post_type ) {
   305 					$post_type = 'post';
   335 					$post_type = 'post';
       
   336 				}
   306 				$id .= '-' . $post_type;
   337 				$id .= '-' . $post_type;
   307 				break;
   338 				break;
   308 			case 'edit-tags' :
   339 			case 'edit-tags':
   309 			case 'term' :
   340 			case 'term':
   310 				if ( null === $taxonomy )
   341 				if ( null === $taxonomy ) {
   311 					$taxonomy = 'post_tag';
   342 					$taxonomy = 'post_tag';
       
   343 				}
   312 				// The edit-tags ID does not contain the post type. Look for it in the request.
   344 				// The edit-tags ID does not contain the post type. Look for it in the request.
   313 				if ( null === $post_type ) {
   345 				if ( null === $post_type ) {
   314 					$post_type = 'post';
   346 					$post_type = 'post';
   315 					if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
   347 					if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
   316 						$post_type = $_REQUEST['post_type'];
   348 						$post_type = $_REQUEST['post_type'];
       
   349 					}
   317 				}
   350 				}
   318 
   351 
   319 				$id = 'edit-' . $taxonomy;
   352 				$id = 'edit-' . $taxonomy;
   320 				break;
   353 				break;
   321 		}
   354 		}
   328 			$base .= '-user';
   361 			$base .= '-user';
   329 		}
   362 		}
   330 
   363 
   331 		if ( isset( self::$_registry[ $id ] ) ) {
   364 		if ( isset( self::$_registry[ $id ] ) ) {
   332 			$screen = self::$_registry[ $id ];
   365 			$screen = self::$_registry[ $id ];
   333 			if ( $screen === get_current_screen() )
   366 			if ( $screen === get_current_screen() ) {
   334 				return $screen;
   367 				return $screen;
       
   368 			}
   335 		} else {
   369 		} else {
   336 			$screen = new WP_Screen();
   370 			$screen     = new WP_Screen();
   337 			$screen->id     = $id;
   371 			$screen->id = $id;
   338 		}
   372 		}
   339 
   373 
   340 		$screen->base       = $base;
   374 		$screen->base            = $base;
   341 		$screen->action     = $action;
   375 		$screen->action          = $action;
   342 		$screen->post_type  = (string) $post_type;
   376 		$screen->post_type       = (string) $post_type;
   343 		$screen->taxonomy   = (string) $taxonomy;
   377 		$screen->taxonomy        = (string) $taxonomy;
   344 		$screen->is_user    = ( 'user' == $in_admin );
   378 		$screen->is_user         = ( 'user' == $in_admin );
   345 		$screen->is_network = ( 'network' == $in_admin );
   379 		$screen->is_network      = ( 'network' == $in_admin );
   346 		$screen->in_admin   = $in_admin;
   380 		$screen->in_admin        = $in_admin;
       
   381 		$screen->is_block_editor = $is_block_editor;
   347 
   382 
   348 		self::$_registry[ $id ] = $screen;
   383 		self::$_registry[ $id ] = $screen;
   349 
   384 
   350 		return $screen;
   385 		return $screen;
   351 	}
   386 	}
   361 	 * @global string    $typenow
   396 	 * @global string    $typenow
   362 	 */
   397 	 */
   363 	public function set_current_screen() {
   398 	public function set_current_screen() {
   364 		global $current_screen, $taxnow, $typenow;
   399 		global $current_screen, $taxnow, $typenow;
   365 		$current_screen = $this;
   400 		$current_screen = $this;
   366 		$taxnow = $this->taxonomy;
   401 		$taxnow         = $this->taxonomy;
   367 		$typenow = $this->post_type;
   402 		$typenow        = $this->post_type;
   368 
   403 
   369 		/**
   404 		/**
   370 		 * Fires after the current screen has been set.
   405 		 * Fires after the current screen has been set.
   371 		 *
   406 		 *
   372 		 * @since 3.0.0
   407 		 * @since 3.0.0
   391 	 * @param string $admin The admin to check against (network | user | site).
   426 	 * @param string $admin The admin to check against (network | user | site).
   392 	 *                      If empty any of the three admins will result in true.
   427 	 *                      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.
   428 	 * @return bool True if the screen is in the indicated admin, false otherwise.
   394 	 */
   429 	 */
   395 	public function in_admin( $admin = null ) {
   430 	public function in_admin( $admin = null ) {
   396 		if ( empty( $admin ) )
   431 		if ( empty( $admin ) ) {
   397 			return (bool) $this->in_admin;
   432 			return (bool) $this->in_admin;
       
   433 		}
   398 
   434 
   399 		return ( $admin == $this->in_admin );
   435 		return ( $admin == $this->in_admin );
   400 	}
   436 	}
   401 
   437 
   402 	/**
   438 	/**
       
   439 	 * Sets or returns whether the block editor is loading on the current screen.
       
   440 	 *
       
   441 	 * @since 5.0.0
       
   442 	 *
       
   443 	 * @param bool $set Optional. Sets whether the block editor is loading on the current screen or not.
       
   444 	 * @return bool True if the block editor is being loaded, false otherwise.
       
   445 	 */
       
   446 	public function is_block_editor( $set = null ) {
       
   447 		if ( $set !== null ) {
       
   448 			$this->is_block_editor = (bool) $set;
       
   449 		}
       
   450 
       
   451 		return $this->is_block_editor;
       
   452 	}
       
   453 
       
   454 	/**
   403 	 * Sets the old string-based contextual help for the screen for backward compatibility.
   455 	 * Sets the old string-based contextual help for the screen for backward compatibility.
   404 	 *
   456 	 *
   405 	 * @since 3.3.0
   457 	 * @since 3.3.0
   406 	 *
       
   407 	 * @static
       
   408 	 *
   458 	 *
   409 	 * @param WP_Screen $screen A screen object.
   459 	 * @param WP_Screen $screen A screen object.
   410 	 * @param string $help Help text.
   460 	 * @param string $help Help text.
   411 	 */
   461 	 */
   412 	public static function add_old_compat_help( $screen, $help ) {
   462 	public static function add_old_compat_help( $screen, $help ) {
   420 	 * @since 3.3.0
   470 	 * @since 3.3.0
   421 	 *
   471 	 *
   422 	 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
   472 	 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
   423 	 */
   473 	 */
   424 	public function set_parentage( $parent_file ) {
   474 	public function set_parentage( $parent_file ) {
   425 		$this->parent_file = $parent_file;
   475 		$this->parent_file         = $parent_file;
   426 		list( $this->parent_base ) = explode( '?', $parent_file );
   476 		list( $this->parent_base ) = explode( '?', $parent_file );
   427 		$this->parent_base = str_replace( '.php', '', $this->parent_base );
   477 		$this->parent_base         = str_replace( '.php', '', $this->parent_base );
   428 	}
   478 	}
   429 
   479 
   430 	/**
   480 	/**
   431 	 * Adds an option for the screen.
   481 	 * 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.
   482 	 * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
   480 	 * @param string $key    Optional. Specific array key for when the option is an array.
   530 	 * @param string $key    Optional. Specific array key for when the option is an array.
   481 	 *                       Default false.
   531 	 *                       Default false.
   482 	 * @return string The option value if set, null otherwise.
   532 	 * @return string The option value if set, null otherwise.
   483 	 */
   533 	 */
   484 	public function get_option( $option, $key = false ) {
   534 	public function get_option( $option, $key = false ) {
   485 		if ( ! isset( $this->_options[ $option ] ) )
   535 		if ( ! isset( $this->_options[ $option ] ) ) {
   486 			return null;
   536 			return null;
       
   537 		}
   487 		if ( $key ) {
   538 		if ( $key ) {
   488 			if ( isset( $this->_options[ $option ][ $key ] ) )
   539 			if ( isset( $this->_options[ $option ][ $key ] ) ) {
   489 				return $this->_options[ $option ][ $key ];
   540 				return $this->_options[ $option ][ $key ];
       
   541 			}
   490 			return null;
   542 			return null;
   491 		}
   543 		}
   492 		return $this->_options[ $option ];
   544 		return $this->_options[ $option ];
   493 	}
   545 	}
   494 
   546 
   531 	 *
   583 	 *
   532 	 * @param string $id Help Tab ID.
   584 	 * @param string $id Help Tab ID.
   533 	 * @return array Help tab arguments.
   585 	 * @return array Help tab arguments.
   534 	 */
   586 	 */
   535 	public function get_help_tab( $id ) {
   587 	public function get_help_tab( $id ) {
   536 		if ( ! isset( $this->_help_tabs[ $id ] ) )
   588 		if ( ! isset( $this->_help_tabs[ $id ] ) ) {
   537 			return null;
   589 			return null;
       
   590 		}
   538 		return $this->_help_tabs[ $id ];
   591 		return $this->_help_tabs[ $id ];
   539 	}
   592 	}
   540 
   593 
   541 	/**
   594 	/**
   542 	 * Add a help tab to the contextual help for the screen.
   595 	 * Add a help tab to the contextual help for the screen.
   561 			'id'       => false,
   614 			'id'       => false,
   562 			'content'  => '',
   615 			'content'  => '',
   563 			'callback' => false,
   616 			'callback' => false,
   564 			'priority' => 10,
   617 			'priority' => 10,
   565 		);
   618 		);
   566 		$args = wp_parse_args( $args, $defaults );
   619 		$args     = wp_parse_args( $args, $defaults );
   567 
   620 
   568 		$args['id'] = sanitize_html_class( $args['id'] );
   621 		$args['id'] = sanitize_html_class( $args['id'] );
   569 
   622 
   570 		// Ensure we have an ID and title.
   623 		// Ensure we have an ID and title.
   571 		if ( ! $args['id'] || ! $args['title'] )
   624 		if ( ! $args['id'] || ! $args['title'] ) {
   572 			return;
   625 			return;
       
   626 		}
   573 
   627 
   574 		// Allows for overriding an existing tab with that ID.
   628 		// Allows for overriding an existing tab with that ID.
   575 		$this->_help_tabs[ $args['id'] ] = $args;
   629 		$this->_help_tabs[ $args['id'] ] = $args;
   576 	}
   630 	}
   577 
   631 
   633 	 */
   687 	 */
   634 	public function get_columns() {
   688 	public function get_columns() {
   635 		return $this->columns;
   689 		return $this->columns;
   636 	}
   690 	}
   637 
   691 
   638  	/**
   692 	/**
   639 	 * Get the accessible hidden headings and text used in the screen.
   693 	 * Get the accessible hidden headings and text used in the screen.
   640 	 *
   694 	 *
   641 	 * @since 4.4.0
   695 	 * @since 4.4.0
   642 	 *
   696 	 *
   643 	 * @see set_screen_reader_content() For more information on the array format.
   697 	 * @see set_screen_reader_content() For more information on the array format.
   683 		$defaults = array(
   737 		$defaults = array(
   684 			'heading_views'      => __( 'Filter items list' ),
   738 			'heading_views'      => __( 'Filter items list' ),
   685 			'heading_pagination' => __( 'Items list navigation' ),
   739 			'heading_pagination' => __( 'Items list navigation' ),
   686 			'heading_list'       => __( 'Items list' ),
   740 			'heading_list'       => __( 'Items list' ),
   687 		);
   741 		);
   688 		$content = wp_parse_args( $content, $defaults );
   742 		$content  = wp_parse_args( $content, $defaults );
   689 
   743 
   690 		$this->_screen_reader_content = $content;
   744 		$this->_screen_reader_content = $content;
   691 	}
   745 	}
   692 
   746 
   693 	/**
   747 	/**
   732 		 *                   get_current_screen()->remove_help_tab() instead.
   786 		 *                   get_current_screen()->remove_help_tab() instead.
   733 		 *
   787 		 *
   734 		 * @param string    $old_help  Help text that appears on the screen.
   788 		 * @param string    $old_help  Help text that appears on the screen.
   735 		 * @param string    $screen_id Screen ID.
   789 		 * @param string    $screen_id Screen ID.
   736 		 * @param WP_Screen $this      Current WP_Screen instance.
   790 		 * @param WP_Screen $this      Current WP_Screen instance.
   737 		 *
       
   738 		 */
   791 		 */
   739 		$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
   792 		$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
   740 
   793 
   741 		// Default help only if there is no old-style block of text and no new-style help tabs.
   794 		// 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() ) {
   795 		if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
   749 			 *                   get_current_screen()->remove_help_tab() instead.
   802 			 *                   get_current_screen()->remove_help_tab() instead.
   750 			 *
   803 			 *
   751 			 * @param string $old_help_default Default contextual help text.
   804 			 * @param string $old_help_default Default contextual help text.
   752 			 */
   805 			 */
   753 			$default_help = apply_filters( 'default_contextual_help', '' );
   806 			$default_help = apply_filters( 'default_contextual_help', '' );
   754 			if ( $default_help )
   807 			if ( $default_help ) {
   755 				$old_help = '<p>' . $default_help . '</p>';
   808 				$old_help = '<p>' . $default_help . '</p>';
       
   809 			}
   756 		}
   810 		}
   757 
   811 
   758 		if ( $old_help ) {
   812 		if ( $old_help ) {
   759 			$this->add_help_tab( array(
   813 			$this->add_help_tab(
   760 				'id'      => 'old-contextual-help',
   814 				array(
   761 				'title'   => __('Overview'),
   815 					'id'      => 'old-contextual-help',
   762 				'content' => $old_help,
   816 					'title'   => __( 'Overview' ),
   763 			) );
   817 					'content' => $old_help,
       
   818 				)
       
   819 			);
   764 		}
   820 		}
   765 
   821 
   766 		$help_sidebar = $this->get_help_sidebar();
   822 		$help_sidebar = $this->get_help_sidebar();
   767 
   823 
   768 		$help_class = 'hidden';
   824 		$help_class = 'hidden';
   769 		if ( ! $help_sidebar )
   825 		if ( ! $help_sidebar ) {
   770 			$help_class .= ' no-sidebar';
   826 			$help_class .= ' no-sidebar';
       
   827 		}
   771 
   828 
   772 		// Time to render!
   829 		// Time to render!
   773 		?>
   830 		?>
   774 		<div id="screen-meta" class="metabox-prefs">
   831 		<div id="screen-meta" class="metabox-prefs">
   775 
   832 
   776 			<div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
   833 			<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>
   834 				<div id="contextual-help-back"></div>
   778 				<div id="contextual-help-columns">
   835 				<div id="contextual-help-columns">
   779 					<div class="contextual-help-tabs">
   836 					<div class="contextual-help-tabs">
   780 						<ul>
   837 						<ul>
   781 						<?php
   838 						<?php
   788 							<li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
   845 							<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 ); ?>">
   846 								<a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">
   790 									<?php echo esc_html( $tab['title'] ); ?>
   847 									<?php echo esc_html( $tab['title'] ); ?>
   791 								</a>
   848 								</a>
   792 							</li>
   849 							</li>
   793 						<?php
   850 							<?php
   794 							$class = '';
   851 							$class = '';
   795 						endforeach;
   852 						endforeach;
   796 						?>
   853 						?>
   797 						</ul>
   854 						</ul>
   798 					</div>
   855 					</div>
   804 					<?php endif; ?>
   861 					<?php endif; ?>
   805 
   862 
   806 					<div class="contextual-help-tabs-wrap">
   863 					<div class="contextual-help-tabs-wrap">
   807 						<?php
   864 						<?php
   808 						$classes = 'help-tab-content active';
   865 						$classes = 'help-tab-content active';
   809 						foreach ( $this->get_help_tabs() as $tab ):
   866 						foreach ( $this->get_help_tabs() as $tab ) :
   810 							$panel_id = "tab-panel-{$tab['id']}";
   867 							$panel_id = "tab-panel-{$tab['id']}";
   811 							?>
   868 							?>
   812 
   869 
   813 							<div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
   870 							<div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
   814 								<?php
   871 								<?php
   815 								// Print tab content.
   872 								// Print tab content.
   816 								echo $tab['content'];
   873 								echo $tab['content'];
   817 
   874 
   818 								// If it exists, fire tab callback.
   875 								// If it exists, fire tab callback.
   819 								if ( ! empty( $tab['callback'] ) )
   876 								if ( ! empty( $tab['callback'] ) ) {
   820 									call_user_func_array( $tab['callback'], array( $this, $tab ) );
   877 									call_user_func_array( $tab['callback'], array( $this, $tab ) );
       
   878 								}
   821 								?>
   879 								?>
   822 							</div>
   880 							</div>
   823 						<?php
   881 							<?php
   824 							$classes = 'help-tab-content';
   882 							$classes = 'help-tab-content';
   825 						endforeach;
   883 						endforeach;
   826 						?>
   884 						?>
   827 					</div>
   885 					</div>
   828 				</div>
   886 				</div>
   842 		 * @param string    $screen_id     Screen ID.
   900 		 * @param string    $screen_id     Screen ID.
   843 		 * @param WP_Screen $this          Current WP_Screen instance.
   901 		 * @param WP_Screen $this          Current WP_Screen instance.
   844 		 */
   902 		 */
   845 		$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
   903 		$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
   846 
   904 
   847 		if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
   905 		if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) {
   848 			$this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
   906 			$this->add_option( 'layout_columns', array( 'max' => $columns[ $this->id ] ) );
       
   907 		}
   849 
   908 
   850 		if ( $this->get_option( 'layout_columns' ) ) {
   909 		if ( $this->get_option( 'layout_columns' ) ) {
   851 			$this->columns = (int) get_user_option("screen_layout_$this->id");
   910 			$this->columns = (int) get_user_option( "screen_layout_$this->id" );
   852 
   911 
   853 			if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
   912 			if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) {
   854 				$this->columns = $this->get_option( 'layout_columns', 'default' );
   913 				$this->columns = $this->get_option( 'layout_columns', 'default' );
   855 		}
   914 			}
   856 		$GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
   915 		}
       
   916 		$GLOBALS['screen_layout_columns'] = $this->columns; // Set the global for back-compat.
   857 
   917 
   858 		// Add screen options
   918 		// Add screen options
   859 		if ( $this->show_screen_options() )
   919 		if ( $this->show_screen_options() ) {
   860 			$this->render_screen_options();
   920 			$this->render_screen_options();
       
   921 		}
   861 		?>
   922 		?>
   862 		</div>
   923 		</div>
   863 		<?php
   924 		<?php
   864 		if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
   925 		if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) {
   865 			return;
   926 			return;
       
   927 		}
   866 		?>
   928 		?>
   867 		<div id="screen-meta-links">
   929 		<div id="screen-meta-links">
   868 		<?php if ( $this->get_help_tabs() ) : ?>
   930 		<?php if ( $this->show_screen_options() ) : ?>
       
   931 			<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
       
   932 			<button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
       
   933 			</div>
       
   934 			<?php
       
   935 		endif;
       
   936 		if ( $this->get_help_tabs() ) :
       
   937 			?>
   869 			<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
   938 			<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>
   939 			<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>
   940 			</div>
   877 		<?php endif; ?>
   941 		<?php endif; ?>
   878 		</div>
   942 		</div>
   879 		<?php
   943 		<?php
   880 	}
   944 	}
   881 
   945 
   882 	/**
   946 	/**
   883 	 *
       
   884 	 * @global array $wp_meta_boxes
   947 	 * @global array $wp_meta_boxes
   885 	 *
   948 	 *
   886 	 * @return bool
   949 	 * @return bool
   887 	 */
   950 	 */
   888 	public function show_screen_options() {
   951 	public function show_screen_options() {
   889 		global $wp_meta_boxes;
   952 		global $wp_meta_boxes;
   890 
   953 
   891 		if ( is_bool( $this->_show_screen_options ) )
   954 		if ( is_bool( $this->_show_screen_options ) ) {
   892 			return $this->_show_screen_options;
   955 			return $this->_show_screen_options;
       
   956 		}
   893 
   957 
   894 		$columns = get_column_headers( $this );
   958 		$columns = get_column_headers( $this );
   895 
   959 
   896 		$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
   960 		$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
   897 
   961 
   898 		switch ( $this->base ) {
   962 		$this->_screen_settings = '';
   899 			case 'widgets':
   963 
   900 				$nonce = wp_create_nonce( 'widgets-access' );
   964 		if ( 'post' === $this->base ) {
   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";
   965 			$expand                 = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
   902 				break;
   966 			$expand                .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
   903 			case 'post' :
   967 			$expand                .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
   904 				$expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
   968 			$this->_screen_settings = $expand;
   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 		}
   969 		}
   913 
   970 
   914 		/**
   971 		/**
   915 		 * Filters the screen settings text displayed in the Screen Options tab.
   972 		 * Filters the screen settings text displayed in the Screen Options tab.
   916 		 *
   973 		 *
   922 		 * @param string    $screen_settings Screen settings.
   979 		 * @param string    $screen_settings Screen settings.
   923 		 * @param WP_Screen $this            WP_Screen object.
   980 		 * @param WP_Screen $this            WP_Screen object.
   924 		 */
   981 		 */
   925 		$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
   982 		$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
   926 
   983 
   927 		if ( $this->_screen_settings || $this->_options )
   984 		if ( $this->_screen_settings || $this->_options ) {
   928 			$show_screen = true;
   985 			$show_screen = true;
       
   986 		}
   929 
   987 
   930 		/**
   988 		/**
   931 		 * Filters whether to show the Screen Options tab.
   989 		 * Filters whether to show the Screen Options tab.
   932 		 *
   990 		 *
   933 		 * @since 3.2.0
   991 		 * @since 3.2.0
   948 	 * @param array $options {
  1006 	 * @param array $options {
   949 	 *     @type bool $wrap  Whether the screen-options-wrap div will be included. Defaults to true.
  1007 	 *     @type bool $wrap  Whether the screen-options-wrap div will be included. Defaults to true.
   950 	 * }
  1008 	 * }
   951 	 */
  1009 	 */
   952 	public function render_screen_options( $options = array() ) {
  1010 	public function render_screen_options( $options = array() ) {
   953 		$options = wp_parse_args( $options, array(
  1011 		$options = wp_parse_args(
   954 			'wrap' => true,
  1012 			$options,
   955 		) );
  1013 			array(
       
  1014 				'wrap' => true,
       
  1015 			)
       
  1016 		);
   956 
  1017 
   957 		$wrapper_start = $wrapper_end = $form_start = $form_end = '';
  1018 		$wrapper_start = $wrapper_end = $form_start = $form_end = '';
   958 
  1019 
   959 		// Output optional wrapper.
  1020 		// Output optional wrapper.
   960 		if ( $options['wrap'] ) {
  1021 		if ( $options['wrap'] ) {
   961 			$wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">';
  1022 			$wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">';
   962 			$wrapper_end = '</div>';
  1023 			$wrapper_end   = '</div>';
   963 		}
  1024 		}
   964 
  1025 
   965 		// Don't output the form and nonce for the widgets accessibility mode links.
  1026 		// Don't output the form and nonce for the widgets accessibility mode links.
   966 		if ( 'widgets' !== $this->base ) {
  1027 		if ( 'widgets' !== $this->base ) {
   967 			$form_start = "\n<form id='adv-settings' method='post'>\n";
  1028 			$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";
  1029 			$form_end   = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
   969 		}
  1030 		}
   970 
  1031 
   971 		echo $wrapper_start . $form_start;
  1032 		echo $wrapper_start . $form_start;
   972 
  1033 
   973 		$this->render_meta_boxes_preferences();
  1034 		$this->render_meta_boxes_preferences();
  1012 		<fieldset class="metabox-prefs">
  1073 		<fieldset class="metabox-prefs">
  1013 		<legend><?php _e( 'Boxes' ); ?></legend>
  1074 		<legend><?php _e( 'Boxes' ); ?></legend>
  1014 		<?php
  1075 		<?php
  1015 			meta_box_prefs( $this );
  1076 			meta_box_prefs( $this );
  1016 
  1077 
  1017 			if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
  1078 		if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
  1018 				if ( isset( $_GET['welcome'] ) ) {
  1079 			if ( isset( $_GET['welcome'] ) ) {
  1019 					$welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
  1080 				$welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
  1020 					update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
  1081 				update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
  1021 				} else {
  1082 			} else {
  1022 					$welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
  1083 				$welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
  1023 					if ( '' === $welcome_checked ) {
  1084 				if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
  1024 						$welcome_checked = '1';
  1085 					$welcome_checked = false;
  1025 					}
       
  1026 					if ( '2' === $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
       
  1027 						$welcome_checked = false;
       
  1028 					}
       
  1029 				}
  1086 				}
  1030 				echo '<label for="wp_welcome_panel-hide">';
  1087 			}
  1031 				echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
  1088 			echo '<label for="wp_welcome_panel-hide">';
  1032 				echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
  1089 			echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
  1033 			}
  1090 			echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
  1034 
  1091 		}
  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 		?>
  1092 		?>
  1053 		</fieldset>
  1093 		</fieldset>
  1054 		<?php
  1094 		<?php
  1055 	}
  1095 	}
  1056 
  1096 
  1111 		if ( ! $this->get_option( 'layout_columns' ) ) {
  1151 		if ( ! $this->get_option( 'layout_columns' ) ) {
  1112 			return;
  1152 			return;
  1113 		}
  1153 		}
  1114 
  1154 
  1115 		$screen_layout_columns = $this->get_columns();
  1155 		$screen_layout_columns = $this->get_columns();
  1116 		$num = $this->get_option( 'layout_columns', 'max' );
  1156 		$num                   = $this->get_option( 'layout_columns', 'max' );
  1117 
  1157 
  1118 		?>
  1158 		?>
  1119 		<fieldset class='columns-prefs'>
  1159 		<fieldset class='columns-prefs'>
  1120 		<legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php
  1160 		<legend class="screen-layout"><?php _e( 'Layout' ); ?></legend>
  1121 			for ( $i = 1; $i <= $num; ++$i ):
  1161 												<?php
  1122 				?>
  1162 												for ( $i = 1; $i <= $num; ++$i ) :
  1123 				<label class="columns-prefs-<?php echo $i; ?>">
  1163 													?>
  1124 					<input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
  1164 													<label class="columns-prefs-<?php echo $i; ?>">
  1125 						<?php checked( $screen_layout_columns, $i ); ?> />
  1165 				<input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
  1126 					<?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
  1166 													<?php checked( $screen_layout_columns, $i ); ?> />
       
  1167 													<?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
  1127 				</label>
  1168 				</label>
  1128 				<?php
  1169 													<?php
  1129 			endfor; ?>
  1170 			endfor;
       
  1171 												?>
  1130 		</fieldset>
  1172 		</fieldset>
  1131 		<?php
  1173 		<?php
  1132 	}
  1174 	}
  1133 
  1175 
  1134 	/**
  1176 	/**
  1208 		// Currently only enabled for posts lists
  1250 		// Currently only enabled for posts lists
  1209 		if ( 'edit' !== $screen->base ) {
  1251 		if ( 'edit' !== $screen->base ) {
  1210 			return;
  1252 			return;
  1211 		}
  1253 		}
  1212 
  1254 
  1213 		$view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) );
  1255 		$view_mode_post_types = get_post_types(
       
  1256 			array(
       
  1257 				'hierarchical' => false,
       
  1258 				'show_ui'      => true,
       
  1259 			)
       
  1260 		);
  1214 
  1261 
  1215 		/**
  1262 		/**
  1216 		 * Filters the post types that have different view mode options.
  1263 		 * Filters the post types that have different view mode options.
  1217 		 *
  1264 		 *
  1218 		 * @since 4.4.0
  1265 		 * @since 4.4.0
  1219 		 *
  1266 		 *
  1220 		 * @param array $view_mode_post_types Array of post types that can change view modes.
  1267 		 * @param string[] $view_mode_post_types Array of post types that can change view modes.
  1221 		 *                                    Default non-hierarchical post types with show_ui on.
  1268 		 *                                       Default non-hierarchical post types with show_ui on.
  1222 		 */
  1269 		 */
  1223 		$view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
  1270 		$view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
  1224 
  1271 
  1225 		if ( ! in_array( $this->post_type, $view_mode_post_types ) ) {
  1272 		if ( ! in_array( $this->post_type, $view_mode_post_types ) ) {
  1226 			return;
  1273 			return;
  1228 
  1275 
  1229 		global $mode;
  1276 		global $mode;
  1230 
  1277 
  1231 		// This needs a submit button
  1278 		// This needs a submit button
  1232 		add_filter( 'screen_options_show_submit', '__return_true' );
  1279 		add_filter( 'screen_options_show_submit', '__return_true' );
  1233 ?>
  1280 		?>
  1234 		<fieldset class="metabox-prefs view-mode">
  1281 		<fieldset class="metabox-prefs view-mode">
  1235 		<legend><?php _e( 'View Mode' ); ?></legend>
  1282 		<legend><?php _e( 'View Mode' ); ?></legend>
  1236 				<label for="list-view-mode">
  1283 				<label for="list-view-mode">
  1237 					<input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
  1284 					<input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
  1238 					<?php _e( 'List View' ); ?>
  1285 					<?php _e( 'List View' ); ?>
  1240 				<label for="excerpt-view-mode">
  1287 				<label for="excerpt-view-mode">
  1241 					<input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
  1288 					<input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
  1242 					<?php _e( 'Excerpt View' ); ?>
  1289 					<?php _e( 'Excerpt View' ); ?>
  1243 				</label>
  1290 				</label>
  1244 		</fieldset>
  1291 		</fieldset>
  1245 <?php
  1292 		<?php
  1246 	}
  1293 	}
  1247 
  1294 
  1248 	/**
  1295 	/**
  1249 	 * Render screen reader text.
  1296 	 * Render screen reader text.
  1250 	 *
  1297 	 *