wp/wp-admin/includes/screen.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
--- a/wp/wp-admin/includes/screen.php	Mon Jun 08 16:11:51 2015 +0000
+++ b/wp/wp-admin/includes/screen.php	Tue Jun 09 03:35:32 2015 +0200
@@ -20,8 +20,22 @@
 
 	static $column_headers = array();
 
-	if ( ! isset( $column_headers[ $screen->id ] ) )
-		$column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
+	if ( ! isset( $column_headers[ $screen->id ] ) ) {
+
+		/**
+		 * Filter the column headers for a list table on a specific screen.
+		 *
+		 * The dynamic portion of the hook name, `$screen->id`, refers to the
+		 * ID of a specific screen. For example, the screen ID for the Posts
+		 * list table is edit-post, so the filter for that screen would be
+		 * manage_edit-post_columns.
+		 *
+		 * @since 3.0.0
+		 *
+		 * @param array $columns An array of column headers. Default empty.
+		 */
+		$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
+	}
 
 	return $column_headers[ $screen->id ];
 }
@@ -46,7 +60,7 @@
  *
  * @since 2.7.0
  *
- * @param string|WP_Screen $screen
+ * @param WP_Screen $screen
  */
 function meta_box_prefs( $screen ) {
 	global $wp_meta_boxes;
@@ -101,9 +115,28 @@
 			else
 				$hidden = array( 'slugdiv' );
 		}
+
+		/**
+		 * Filter the default list of hidden meta boxes.
+		 *
+		 * @since 3.1.0
+		 *
+		 * @param array     $hidden An array of meta boxes hidden by default.
+		 * @param WP_Screen $screen WP_Screen object of the current screen.
+		 */
 		$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
 	}
 
+	/**
+	 * Filter the list of hidden meta boxes.
+	 *
+	 * @since 3.3.0
+	 *
+	 * @param array     $hidden       An array of hidden meta boxes.
+	 * @param WP_Screen $screen       WP_Screen object of the current screen.
+	 * @param bool      $use_defaults Whether to show the default meta boxes.
+	 *                                Default true.
+	 */
 	return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
 }
 
@@ -125,53 +158,6 @@
 }
 
 /**
- * Displays a screen icon.
- *
- * @uses get_screen_icon()
- * @since 2.7.0
- *
- * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
- * 	which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
- */
-function screen_icon( $screen = '' ) {
-	echo get_screen_icon( $screen );
-}
-
-/**
- * Gets a screen icon.
- *
- * @since 3.2.0
- *
- * @global $post_ID
- * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
- * 	which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
- * @return string HTML for the screen icon.
- */
-function get_screen_icon( $screen = '' ) {
-	if ( empty( $screen ) )
-		$screen = get_current_screen();
-	elseif ( is_string( $screen ) )
-		$icon_id = $screen;
-
-	$class = 'icon32';
-
-	if ( empty( $icon_id ) ) {
-		if ( ! empty( $screen->parent_base ) )
-			$icon_id = $screen->parent_base;
-		else
-			$icon_id = $screen->base;
-
-		if ( 'page' == $screen->post_type )
-			$icon_id = 'edit-pages';
-
-		if ( $screen->post_type )
-			$class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen->post_type );
-	}
-
-	return '<div id="icon-' . esc_attr( $icon_id ) . '" class="' . $class . '"><br /></div>';
-}
-
-/**
  * Get the current screen object
  *
  * @since 3.1.0
@@ -191,7 +177,6 @@
  * Set the current screen object
  *
  * @since 3.0.0
- * @uses $current_screen
  *
  * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
  *	or an existing screen object.
@@ -383,14 +368,15 @@
 	 * @since 3.3.0
 	 * @access public
 	 *
-	 * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
+	 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
 	 * 	Defaults to the current $hook_suffix global.
 	 * @return WP_Screen Screen object.
 	 */
 	public static function get( $hook_name = '' ) {
 
-		if ( is_a( $hook_name, 'WP_Screen' ) )
+		if ( $hook_name instanceof WP_Screen ) {
 			return $hook_name;
+		}
 
 		$post_type = $taxonomy = null;
 		$in_admin = false;
@@ -544,11 +530,19 @@
 	 * @see set_current_screen()
 	 * @since 3.3.0
 	 */
-	function set_current_screen() {
+	public function set_current_screen() {
 		global $current_screen, $taxnow, $typenow;
 		$current_screen = $this;
 		$taxnow = $this->taxonomy;
 		$typenow = $this->post_type;
+
+		/**
+		 * Fires after the current screen has been set.
+		 *
+		 * @since 3.0.0
+		 *
+		 * @param WP_Screen $current_screen Current WP_Screen object.
+		 */
 		do_action( 'current_screen', $current_screen );
 	}
 
@@ -587,7 +581,7 @@
 	 * @param WP_Screen $screen A screen object.
 	 * @param string $help Help text.
 	 */
-	static function add_old_compat_help( $screen, $help ) {
+	public static function add_old_compat_help( $screen, $help ) {
 		self::$_old_compat_help[ $screen->id ] = $help;
 	}
 
@@ -599,7 +593,7 @@
 	 *
 	 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
 	 */
-	function set_parentage( $parent_file ) {
+	public function set_parentage( $parent_file ) {
 		$this->parent_file = $parent_file;
 		list( $this->parent_base ) = explode( '?', $parent_file );
 		$this->parent_base = str_replace( '.php', '', $this->parent_base );
@@ -619,12 +613,45 @@
 	}
 
 	/**
+	 * Remove an option from the screen.
+	 *
+	 * @since 3.8.0
+	 *
+	 * @param string $option Option ID.
+	 */
+	public function remove_option( $option ) {
+		unset( $this->_options[ $option ] );
+	}
+
+	/**
+	 * Remove all options from the screen.
+	 *
+	 * @since 3.8.0
+	 */
+	public function remove_options() {
+		$this->_options = array();
+	}
+
+	/**
+	 * Get the options registered for the screen.
+	 *
+	 * @since 3.8.0
+	 *
+	 * @return array Options with arguments.
+	 */
+	public function get_options() {
+		return $this->_options;
+	}
+
+	/**
 	 * Gets the arguments for an option for the screen.
 	 *
 	 * @since 3.3.0
 	 *
-	 * @param string $option Option ID.
-	 * @param mixed $key Optional. Specific array key for when the option is an array.
+	 * @param string $option Option name.
+	 * @param string $key    Optional. Specific array key for when the option is an array.
+	 *                       Default false.
+	 * @return string The option value if set, null otherwise.
 	 */
 	public function get_option( $option, $key = false ) {
 		if ( ! isset( $this->_options[ $option ] ) )
@@ -763,14 +790,46 @@
 	 */
 	public function render_screen_meta() {
 
-		// Call old contextual_help_list filter.
+		/**
+		 * Filter the legacy contextual help list.
+		 *
+		 * @since 2.7.0
+		 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
+		 *                   get_current_screen()->remove_help_tab() instead.
+		 *
+		 * @param array     $old_compat_help Old contextual help.
+		 * @param WP_Screen $this            Current WP_Screen instance.
+		 */
 		self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
 
 		$old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
+
+		/**
+		 * Filter the legacy contextual help text.
+		 *
+		 * @since 2.7.0
+		 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
+		 *                   get_current_screen()->remove_help_tab() instead.
+		 *
+		 * @param string    $old_help  Help text that appears on the screen.
+		 * @param string    $screen_id Screen ID.
+		 * @param WP_Screen $this      Current WP_Screen instance.
+		 *
+		 */
 		$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
 
 		// Default help only if there is no old-style block of text and no new-style help tabs.
 		if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
+
+			/**
+			 * Filter the default legacy contextual help text.
+			 *
+			 * @since 2.8.0
+			 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
+			 *                   get_current_screen()->remove_help_tab() instead.
+			 *
+			 * @param string $old_help_default Default contextual help text.
+			 */
 			$default_help = apply_filters( 'default_contextual_help', '' );
 			if ( $default_help )
 				$old_help = '<p>' . $default_help . '</p>';
@@ -851,7 +910,18 @@
 		<?php
 		// Setup layout columns
 
-		// Back compat for plugins using the filter instead of add_screen_option()
+		/**
+		 * Filter the array of screen layout columns.
+		 *
+		 * This hook provides back-compat for plugins using the back-compat
+		 * filter instead of add_screen_option().
+		 *
+		 * @since 2.8.0
+		 *
+		 * @param array     $empty_columns Empty array.
+		 * @param string    $screen_id     Screen ID.
+		 * @param WP_Screen $this          Current WP_Screen instance.
+		 */
 		$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
 
 		if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
@@ -899,20 +969,46 @@
 
 		$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
 
-		switch ( $this->id ) {
+		switch ( $this->base ) {
 			case 'widgets':
 				$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";
 				break;
+			case 'post' :
+				$expand = '<div class="editor-expand hidden"><label for="editor-expand-toggle">';
+				$expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
+				$expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></div>';
+				$this->_screen_settings = $expand;
+				break;
 			default:
 				$this->_screen_settings = '';
 				break;
 		}
 
+		/**
+		 * Filter the screen settings text displayed in the Screen Options tab.
+		 *
+		 * This filter is currently only used on the Widgets screen to enable
+		 * accessibility mode.
+		 *
+		 * @since 3.0.0
+		 *
+		 * @param string    $screen_settings Screen settings.
+		 * @param WP_Screen $this            WP_Screen object.
+		 */
 		$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
 
 		if ( $this->_screen_settings || $this->_options )
 			$show_screen = true;
 
+		/**
+		 * Filter whether to show the Screen Options tab.
+		 *
+		 * @since 3.2.0
+		 *
+		 * @param bool      $show_screen Whether to show Screen Options tab.
+		 *                               Default true.
+		 * @param WP_Screen $this        Current WP_Screen instance.
+		 */
 		$this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
 		return $this->_show_screen_options;
 	}
@@ -923,15 +1019,14 @@
 	 * @since 3.3.0
 	 */
 	public function render_screen_options() {
-		global $wp_meta_boxes, $wp_list_table;
+		global $wp_meta_boxes;
 
 		$columns = get_column_headers( $this );
 		$hidden  = get_hidden_columns( $this );
-		$post    = get_post();
 
 		?>
 		<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>">
-		<form id="adv-settings" action="" method="post">
+		<form id="adv-settings" method="post">
 		<?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
 			<h5><?php _e( 'Show on screen' ); ?></h5>
 		<?php
@@ -1002,7 +1097,7 @@
 	 *
 	 * @since 3.3.0
 	 */
-	function render_screen_layout() {
+	public function render_screen_layout() {
 		if ( ! $this->get_option('layout_columns') )
 			return;
 
@@ -1031,49 +1126,59 @@
 	 *
 	 * @since 3.3.0
 	 */
-	function render_per_page_options() {
-		if ( ! $this->get_option( 'per_page' ) )
+	public function render_per_page_options() {
+		if ( null === $this->get_option( 'per_page' ) ) {
 			return;
+		}
 
 		$per_page_label = $this->get_option( 'per_page', 'label' );
+		if ( null === $per_page_label ) {
+			$per_page_label = __( 'Number of items per page:' );
+		}
 
 		$option = $this->get_option( 'per_page', 'option' );
-		if ( ! $option )
+		if ( ! $option ) {
 			$option = str_replace( '-', '_', "{$this->id}_per_page" );
+		}
 
 		$per_page = (int) get_user_option( $option );
 		if ( empty( $per_page ) || $per_page < 1 ) {
 			$per_page = $this->get_option( 'per_page', 'default' );
-			if ( ! $per_page )
+			if ( ! $per_page ) {
 				$per_page = 20;
+			}
 		}
 
 		if ( 'edit_comments_per_page' == $option ) {
 			$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
+
+			/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
 			$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
 		} elseif ( 'categories_per_page' == $option ) {
+			/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
 			$per_page = apply_filters( 'edit_categories_per_page', $per_page );
 		} else {
+			/** This filter is documented in wp-admin/includes/class-wp-list-table.php */
 			$per_page = apply_filters( $option, $per_page );
 		}
 
 		// Back compat
-		if ( isset( $this->post_type ) )
+		if ( isset( $this->post_type ) ) {
+			/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
 			$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
+		}
 
 		?>
 		<div class="screen-options">
 			<?php if ( $per_page_label ) : ?>
+				<label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
 				<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
 					id="<?php echo esc_attr( $option ); ?>" maxlength="3"
 					value="<?php echo esc_attr( $per_page ); ?>" />
-				<label for="<?php echo esc_attr( $option ); ?>">
-					<?php echo esc_html( $per_page_label ); ?>
-				</label>
 			<?php endif;
 
 			echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
-			<input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' />
+			<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
 		</div>
 		<?php
 	}