wp/wp-admin/includes/screen.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    18 	if ( is_string( $screen ) )
    18 	if ( is_string( $screen ) )
    19 		$screen = convert_to_screen( $screen );
    19 		$screen = convert_to_screen( $screen );
    20 
    20 
    21 	static $column_headers = array();
    21 	static $column_headers = array();
    22 
    22 
    23 	if ( ! isset( $column_headers[ $screen->id ] ) )
    23 	if ( ! isset( $column_headers[ $screen->id ] ) ) {
    24 		$column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
    24 
       
    25 		/**
       
    26 		 * Filter the column headers for a list table on a specific screen.
       
    27 		 *
       
    28 		 * 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
       
    30 		 * list table is edit-post, so the filter for that screen would be
       
    31 		 * manage_edit-post_columns.
       
    32 		 *
       
    33 		 * @since 3.0.0
       
    34 		 *
       
    35 		 * @param array $columns An array of column headers. Default empty.
       
    36 		 */
       
    37 		$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
       
    38 	}
    25 
    39 
    26 	return $column_headers[ $screen->id ];
    40 	return $column_headers[ $screen->id ];
    27 }
    41 }
    28 
    42 
    29 /**
    43 /**
    44 /**
    58 /**
    45  * Prints the meta box preferences for screen meta.
    59  * Prints the meta box preferences for screen meta.
    46  *
    60  *
    47  * @since 2.7.0
    61  * @since 2.7.0
    48  *
    62  *
    49  * @param string|WP_Screen $screen
    63  * @param WP_Screen $screen
    50  */
    64  */
    51 function meta_box_prefs( $screen ) {
    65 function meta_box_prefs( $screen ) {
    52 	global $wp_meta_boxes;
    66 	global $wp_meta_boxes;
    53 
    67 
    54 	if ( is_string( $screen ) )
    68 	if ( is_string( $screen ) )
    99 			if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
   113 			if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
   100 				$hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
   114 				$hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
   101 			else
   115 			else
   102 				$hidden = array( 'slugdiv' );
   116 				$hidden = array( 'slugdiv' );
   103 		}
   117 		}
       
   118 
       
   119 		/**
       
   120 		 * Filter the default list of hidden meta boxes.
       
   121 		 *
       
   122 		 * @since 3.1.0
       
   123 		 *
       
   124 		 * @param array     $hidden An array of meta boxes hidden by default.
       
   125 		 * @param WP_Screen $screen WP_Screen object of the current screen.
       
   126 		 */
   104 		$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
   127 		$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
   105 	}
   128 	}
   106 
   129 
       
   130 	/**
       
   131 	 * Filter the list of hidden meta boxes.
       
   132 	 *
       
   133 	 * @since 3.3.0
       
   134 	 *
       
   135 	 * @param array     $hidden       An array of hidden meta boxes.
       
   136 	 * @param WP_Screen $screen       WP_Screen object of the current screen.
       
   137 	 * @param bool      $use_defaults Whether to show the default meta boxes.
       
   138 	 *                                Default true.
       
   139 	 */
   107 	return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
   140 	return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
   108 }
   141 }
   109 
   142 
   110 /**
   143 /**
   111  * Register and configure an admin screen option
   144  * Register and configure an admin screen option
   123 
   156 
   124 	$current_screen->add_option( $option, $args );
   157 	$current_screen->add_option( $option, $args );
   125 }
   158 }
   126 
   159 
   127 /**
   160 /**
   128  * Displays a screen icon.
       
   129  *
       
   130  * @uses get_screen_icon()
       
   131  * @since 2.7.0
       
   132  *
       
   133  * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
       
   134  * 	which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
       
   135  */
       
   136 function screen_icon( $screen = '' ) {
       
   137 	echo get_screen_icon( $screen );
       
   138 }
       
   139 
       
   140 /**
       
   141  * Gets a screen icon.
       
   142  *
       
   143  * @since 3.2.0
       
   144  *
       
   145  * @global $post_ID
       
   146  * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
       
   147  * 	which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
       
   148  * @return string HTML for the screen icon.
       
   149  */
       
   150 function get_screen_icon( $screen = '' ) {
       
   151 	if ( empty( $screen ) )
       
   152 		$screen = get_current_screen();
       
   153 	elseif ( is_string( $screen ) )
       
   154 		$icon_id = $screen;
       
   155 
       
   156 	$class = 'icon32';
       
   157 
       
   158 	if ( empty( $icon_id ) ) {
       
   159 		if ( ! empty( $screen->parent_base ) )
       
   160 			$icon_id = $screen->parent_base;
       
   161 		else
       
   162 			$icon_id = $screen->base;
       
   163 
       
   164 		if ( 'page' == $screen->post_type )
       
   165 			$icon_id = 'edit-pages';
       
   166 
       
   167 		if ( $screen->post_type )
       
   168 			$class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen->post_type );
       
   169 	}
       
   170 
       
   171 	return '<div id="icon-' . esc_attr( $icon_id ) . '" class="' . $class . '"><br /></div>';
       
   172 }
       
   173 
       
   174 /**
       
   175  * Get the current screen object
   161  * Get the current screen object
   176  *
   162  *
   177  * @since 3.1.0
   163  * @since 3.1.0
   178  *
   164  *
   179  * @return WP_Screen Current screen object
   165  * @return WP_Screen Current screen object
   189 
   175 
   190 /**
   176 /**
   191  * Set the current screen object
   177  * Set the current screen object
   192  *
   178  *
   193  * @since 3.0.0
   179  * @since 3.0.0
   194  * @uses $current_screen
       
   195  *
   180  *
   196  * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
   181  * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
   197  *	or an existing screen object.
   182  *	or an existing screen object.
   198  */
   183  */
   199 function set_current_screen( $hook_name = '' ) {
   184 function set_current_screen( $hook_name = '' ) {
   381 	 * Fetches a screen object.
   366 	 * Fetches a screen object.
   382 	 *
   367 	 *
   383 	 * @since 3.3.0
   368 	 * @since 3.3.0
   384 	 * @access public
   369 	 * @access public
   385 	 *
   370 	 *
   386 	 * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
   371 	 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
   387 	 * 	Defaults to the current $hook_suffix global.
   372 	 * 	Defaults to the current $hook_suffix global.
   388 	 * @return WP_Screen Screen object.
   373 	 * @return WP_Screen Screen object.
   389 	 */
   374 	 */
   390 	public static function get( $hook_name = '' ) {
   375 	public static function get( $hook_name = '' ) {
   391 
   376 
   392 		if ( is_a( $hook_name, 'WP_Screen' ) )
   377 		if ( $hook_name instanceof WP_Screen ) {
   393 			return $hook_name;
   378 			return $hook_name;
       
   379 		}
   394 
   380 
   395 		$post_type = $taxonomy = null;
   381 		$post_type = $taxonomy = null;
   396 		$in_admin = false;
   382 		$in_admin = false;
   397 		$action = '';
   383 		$action = '';
   398 
   384 
   542 	 * Makes the screen object the current screen.
   528 	 * Makes the screen object the current screen.
   543 	 *
   529 	 *
   544 	 * @see set_current_screen()
   530 	 * @see set_current_screen()
   545 	 * @since 3.3.0
   531 	 * @since 3.3.0
   546 	 */
   532 	 */
   547 	function set_current_screen() {
   533 	public function set_current_screen() {
   548 		global $current_screen, $taxnow, $typenow;
   534 		global $current_screen, $taxnow, $typenow;
   549 		$current_screen = $this;
   535 		$current_screen = $this;
   550 		$taxnow = $this->taxonomy;
   536 		$taxnow = $this->taxonomy;
   551 		$typenow = $this->post_type;
   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 		 */
   552 		do_action( 'current_screen', $current_screen );
   546 		do_action( 'current_screen', $current_screen );
   553 	}
   547 	}
   554 
   548 
   555 	/**
   549 	/**
   556 	 * Constructor
   550 	 * Constructor
   585 	 * @since 3.3.0
   579 	 * @since 3.3.0
   586 	 *
   580 	 *
   587 	 * @param WP_Screen $screen A screen object.
   581 	 * @param WP_Screen $screen A screen object.
   588 	 * @param string $help Help text.
   582 	 * @param string $help Help text.
   589 	 */
   583 	 */
   590 	static function add_old_compat_help( $screen, $help ) {
   584 	public static function add_old_compat_help( $screen, $help ) {
   591 		self::$_old_compat_help[ $screen->id ] = $help;
   585 		self::$_old_compat_help[ $screen->id ] = $help;
   592 	}
   586 	}
   593 
   587 
   594 	/**
   588 	/**
   595 	 * Set the parent information for the screen.
   589 	 * Set the parent information for the screen.
   597 	 *
   591 	 *
   598 	 * @since 3.3.0
   592 	 * @since 3.3.0
   599 	 *
   593 	 *
   600 	 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
   594 	 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
   601 	 */
   595 	 */
   602 	function set_parentage( $parent_file ) {
   596 	public function set_parentage( $parent_file ) {
   603 		$this->parent_file = $parent_file;
   597 		$this->parent_file = $parent_file;
   604 		list( $this->parent_base ) = explode( '?', $parent_file );
   598 		list( $this->parent_base ) = explode( '?', $parent_file );
   605 		$this->parent_base = str_replace( '.php', '', $this->parent_base );
   599 		$this->parent_base = str_replace( '.php', '', $this->parent_base );
   606 	}
   600 	}
   607 
   601 
   617 	public function add_option( $option, $args = array() ) {
   611 	public function add_option( $option, $args = array() ) {
   618 		$this->_options[ $option ] = $args;
   612 		$this->_options[ $option ] = $args;
   619 	}
   613 	}
   620 
   614 
   621 	/**
   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 	/**
   622 	 * Gets the arguments for an option for the screen.
   647 	 * Gets the arguments for an option for the screen.
   623 	 *
   648 	 *
   624 	 * @since 3.3.0
   649 	 * @since 3.3.0
   625 	 *
   650 	 *
   626 	 * @param string $option Option ID.
   651 	 * @param string $option Option name.
   627 	 * @param mixed $key Optional. Specific array key for when the option is an array.
   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.
   628 	 */
   655 	 */
   629 	public function get_option( $option, $key = false ) {
   656 	public function get_option( $option, $key = false ) {
   630 		if ( ! isset( $this->_options[ $option ] ) )
   657 		if ( ! isset( $this->_options[ $option ] ) )
   631 			return null;
   658 			return null;
   632 		if ( $key ) {
   659 		if ( $key ) {
   761 	 *
   788 	 *
   762 	 * @since 3.3.0
   789 	 * @since 3.3.0
   763 	 */
   790 	 */
   764 	public function render_screen_meta() {
   791 	public function render_screen_meta() {
   765 
   792 
   766 		// Call old contextual_help_list filter.
   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 		 */
   767 		self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
   803 		self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
   768 
   804 
   769 		$old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
   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 		 */
   770 		$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
   819 		$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
   771 
   820 
   772 		// Default help only if there is no old-style block of text and no new-style help tabs.
   821 		// Default help only if there is no old-style block of text and no new-style help tabs.
   773 		if ( empty( $old_help ) && ! $this->get_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 			 */
   774 			$default_help = apply_filters( 'default_contextual_help', '' );
   833 			$default_help = apply_filters( 'default_contextual_help', '' );
   775 			if ( $default_help )
   834 			if ( $default_help )
   776 				$old_help = '<p>' . $default_help . '</p>';
   835 				$old_help = '<p>' . $default_help . '</p>';
   777 		}
   836 		}
   778 
   837 
   849 				</div>
   908 				</div>
   850 			</div>
   909 			</div>
   851 		<?php
   910 		<?php
   852 		// Setup layout columns
   911 		// Setup layout columns
   853 
   912 
   854 		// Back compat for plugins using the filter instead of add_screen_option()
   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 		 */
   855 		$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
   925 		$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
   856 
   926 
   857 		if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
   927 		if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
   858 			$this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
   928 			$this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
   859 
   929 
   897 
   967 
   898 		$columns = get_column_headers( $this );
   968 		$columns = get_column_headers( $this );
   899 
   969 
   900 		$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
   970 		$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
   901 
   971 
   902 		switch ( $this->id ) {
   972 		switch ( $this->base ) {
   903 			case 'widgets':
   973 			case 'widgets':
   904 				$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";
   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;
   905 				break;
   981 				break;
   906 			default:
   982 			default:
   907 				$this->_screen_settings = '';
   983 				$this->_screen_settings = '';
   908 				break;
   984 				break;
   909 		}
   985 		}
   910 
   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 		 */
   911 		$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
   998 		$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
   912 
   999 
   913 		if ( $this->_screen_settings || $this->_options )
  1000 		if ( $this->_screen_settings || $this->_options )
   914 			$show_screen = true;
  1001 			$show_screen = true;
   915 
  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 		 */
   916 		$this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
  1012 		$this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
   917 		return $this->_show_screen_options;
  1013 		return $this->_show_screen_options;
   918 	}
  1014 	}
   919 
  1015 
   920 	/**
  1016 	/**
   921 	 * Render the screen options tab.
  1017 	 * Render the screen options tab.
   922 	 *
  1018 	 *
   923 	 * @since 3.3.0
  1019 	 * @since 3.3.0
   924 	 */
  1020 	 */
   925 	public function render_screen_options() {
  1021 	public function render_screen_options() {
   926 		global $wp_meta_boxes, $wp_list_table;
  1022 		global $wp_meta_boxes;
   927 
  1023 
   928 		$columns = get_column_headers( $this );
  1024 		$columns = get_column_headers( $this );
   929 		$hidden  = get_hidden_columns( $this );
  1025 		$hidden  = get_hidden_columns( $this );
   930 		$post    = get_post();
       
   931 
  1026 
   932 		?>
  1027 		?>
   933 		<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>">
  1028 		<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>">
   934 		<form id="adv-settings" action="" method="post">
  1029 		<form id="adv-settings" method="post">
   935 		<?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
  1030 		<?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
   936 			<h5><?php _e( 'Show on screen' ); ?></h5>
  1031 			<h5><?php _e( 'Show on screen' ); ?></h5>
   937 		<?php
  1032 		<?php
   938 		endif;
  1033 		endif;
   939 
  1034 
  1000 	/**
  1095 	/**
  1001 	 * Render the option for number of columns on the page
  1096 	 * Render the option for number of columns on the page
  1002 	 *
  1097 	 *
  1003 	 * @since 3.3.0
  1098 	 * @since 3.3.0
  1004 	 */
  1099 	 */
  1005 	function render_screen_layout() {
  1100 	public function render_screen_layout() {
  1006 		if ( ! $this->get_option('layout_columns') )
  1101 		if ( ! $this->get_option('layout_columns') )
  1007 			return;
  1102 			return;
  1008 
  1103 
  1009 		$screen_layout_columns = $this->get_columns();
  1104 		$screen_layout_columns = $this->get_columns();
  1010 		$num = $this->get_option( 'layout_columns', 'max' );
  1105 		$num = $this->get_option( 'layout_columns', 'max' );
  1029 	/**
  1124 	/**
  1030 	 * Render the items per page option
  1125 	 * Render the items per page option
  1031 	 *
  1126 	 *
  1032 	 * @since 3.3.0
  1127 	 * @since 3.3.0
  1033 	 */
  1128 	 */
  1034 	function render_per_page_options() {
  1129 	public function render_per_page_options() {
  1035 		if ( ! $this->get_option( 'per_page' ) )
  1130 		if ( null === $this->get_option( 'per_page' ) ) {
  1036 			return;
  1131 			return;
       
  1132 		}
  1037 
  1133 
  1038 		$per_page_label = $this->get_option( 'per_page', 'label' );
  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 		}
  1039 
  1138 
  1040 		$option = $this->get_option( 'per_page', 'option' );
  1139 		$option = $this->get_option( 'per_page', 'option' );
  1041 		if ( ! $option )
  1140 		if ( ! $option ) {
  1042 			$option = str_replace( '-', '_', "{$this->id}_per_page" );
  1141 			$option = str_replace( '-', '_', "{$this->id}_per_page" );
       
  1142 		}
  1043 
  1143 
  1044 		$per_page = (int) get_user_option( $option );
  1144 		$per_page = (int) get_user_option( $option );
  1045 		if ( empty( $per_page ) || $per_page < 1 ) {
  1145 		if ( empty( $per_page ) || $per_page < 1 ) {
  1046 			$per_page = $this->get_option( 'per_page', 'default' );
  1146 			$per_page = $this->get_option( 'per_page', 'default' );
  1047 			if ( ! $per_page )
  1147 			if ( ! $per_page ) {
  1048 				$per_page = 20;
  1148 				$per_page = 20;
       
  1149 			}
  1049 		}
  1150 		}
  1050 
  1151 
  1051 		if ( 'edit_comments_per_page' == $option ) {
  1152 		if ( 'edit_comments_per_page' == $option ) {
  1052 			$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
  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 */
  1053 			$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
  1156 			$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
  1054 		} elseif ( 'categories_per_page' == $option ) {
  1157 		} elseif ( 'categories_per_page' == $option ) {
       
  1158 			/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
  1055 			$per_page = apply_filters( 'edit_categories_per_page', $per_page );
  1159 			$per_page = apply_filters( 'edit_categories_per_page', $per_page );
  1056 		} else {
  1160 		} else {
       
  1161 			/** This filter is documented in wp-admin/includes/class-wp-list-table.php */
  1057 			$per_page = apply_filters( $option, $per_page );
  1162 			$per_page = apply_filters( $option, $per_page );
  1058 		}
  1163 		}
  1059 
  1164 
  1060 		// Back compat
  1165 		// Back compat
  1061 		if ( isset( $this->post_type ) )
  1166 		if ( isset( $this->post_type ) ) {
       
  1167 			/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
  1062 			$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
  1168 			$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
       
  1169 		}
  1063 
  1170 
  1064 		?>
  1171 		?>
  1065 		<div class="screen-options">
  1172 		<div class="screen-options">
  1066 			<?php if ( $per_page_label ) : ?>
  1173 			<?php if ( $per_page_label ) : ?>
       
  1174 				<label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
  1067 				<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
  1175 				<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
  1068 					id="<?php echo esc_attr( $option ); ?>" maxlength="3"
  1176 					id="<?php echo esc_attr( $option ); ?>" maxlength="3"
  1069 					value="<?php echo esc_attr( $per_page ); ?>" />
  1177 					value="<?php echo esc_attr( $per_page ); ?>" />
  1070 				<label for="<?php echo esc_attr( $option ); ?>">
       
  1071 					<?php echo esc_html( $per_page_label ); ?>
       
  1072 				</label>
       
  1073 			<?php endif;
  1178 			<?php endif;
  1074 
  1179 
  1075 			echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
  1180 			echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
  1076 			<input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' />
  1181 			<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
  1077 		</div>
  1182 		</div>
  1078 		<?php
  1183 		<?php
  1079 	}
  1184 	}
  1080 }
  1185 }