2011-09-26 17:32:10 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WordPress Administration Screen API.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the column headers for a screen
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2015-05-29 11:43:29 -04:00
|
|
|
* @staticvar array $column_headers
|
|
|
|
*
|
2011-10-24 02:40:15 -04:00
|
|
|
* @param string|WP_Screen $screen The screen you want the headers for
|
2011-09-26 17:32:10 -04:00
|
|
|
* @return array Containing the headers in the format id => UI String
|
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
function get_column_headers( $screen ) {
|
2011-09-26 17:32:10 -04:00
|
|
|
if ( is_string( $screen ) )
|
|
|
|
$screen = convert_to_screen( $screen );
|
|
|
|
|
2011-10-11 17:32:16 -04:00
|
|
|
static $column_headers = array();
|
2011-09-26 17:32:10 -04:00
|
|
|
|
2014-02-25 05:05:14 -05:00
|
|
|
if ( ! isset( $column_headers[ $screen->id ] ) ) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the column headers for a list table on a specific screen.
|
|
|
|
*
|
2014-11-30 06:28:24 -05:00
|
|
|
* The dynamic portion of the hook name, `$screen->id`, refers to the
|
2014-02-25 05:05:14 -05:00
|
|
|
* 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.
|
|
|
|
*/
|
2014-05-08 05:58:14 -04:00
|
|
|
$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
|
2014-02-25 05:05:14 -05:00
|
|
|
}
|
2011-09-26 17:32:10 -04:00
|
|
|
|
2011-10-11 17:32:16 -04:00
|
|
|
return $column_headers[ $screen->id ];
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of hidden columns.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2011-10-24 02:40:15 -04:00
|
|
|
* @param string|WP_Screen $screen The screen you want the hidden columns for
|
2011-09-26 17:32:10 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
function get_hidden_columns( $screen ) {
|
2015-08-21 11:32:29 -04:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-09-26 17:32:10 -04:00
|
|
|
$screen = convert_to_screen( $screen );
|
2015-08-21 11:32:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
|
|
|
|
|
|
|
|
if ( ! $hidden ) {
|
|
|
|
$hidden = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the default list of hidden columns.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
|
|
|
* @param array $hidden An array of columns hidden by default.
|
|
|
|
* @param WP_Screen $screen WP_Screen object of the current screen.
|
|
|
|
*/
|
|
|
|
$hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
|
|
|
|
}
|
2011-09-26 17:32:10 -04:00
|
|
|
|
2015-08-21 11:32:29 -04:00
|
|
|
/**
|
|
|
|
* Filter the list of hidden columns.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
|
|
|
* @param array $hidden An array of hidden columns.
|
|
|
|
* @param WP_Screen $screen WP_Screen object of the current screen.
|
|
|
|
*/
|
|
|
|
return apply_filters( 'hidden_columns', $hidden, $screen );
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2011-10-07 00:57:12 -04:00
|
|
|
/**
|
2011-10-24 02:40:15 -04:00
|
|
|
* Prints the meta box preferences for screen meta.
|
2011-10-07 00:57:12 -04:00
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2015-05-28 22:06:31 -04:00
|
|
|
* @global array $wp_meta_boxes
|
|
|
|
*
|
2014-11-30 20:00:22 -05:00
|
|
|
* @param WP_Screen $screen
|
2011-10-07 00:57:12 -04:00
|
|
|
*/
|
2011-10-11 17:32:16 -04:00
|
|
|
function meta_box_prefs( $screen ) {
|
2011-10-07 00:57:12 -04:00
|
|
|
global $wp_meta_boxes;
|
|
|
|
|
2011-10-24 02:40:15 -04:00
|
|
|
if ( is_string( $screen ) )
|
|
|
|
$screen = convert_to_screen( $screen );
|
2011-10-07 00:57:12 -04:00
|
|
|
|
|
|
|
if ( empty($wp_meta_boxes[$screen->id]) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$hidden = get_hidden_meta_boxes($screen);
|
|
|
|
|
2015-06-08 08:35:26 -04:00
|
|
|
foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
|
|
|
|
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
|
|
|
|
if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
|
2011-10-07 00:57:12 -04:00
|
|
|
if ( false == $box || ! $box['title'] )
|
|
|
|
continue;
|
|
|
|
// Submit box cannot be hidden
|
|
|
|
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
|
|
|
|
continue;
|
|
|
|
$box_id = $box['id'];
|
|
|
|
echo '<label for="' . $box_id . '-hide">';
|
|
|
|
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"' : '') . ' />';
|
|
|
|
echo "{$box['title']}</label>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 17:32:10 -04:00
|
|
|
/**
|
|
|
|
* Get Hidden Meta Boxes
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2011-10-24 02:40:15 -04:00
|
|
|
* @param string|WP_Screen $screen Screen identifier
|
2011-09-26 17:32:10 -04:00
|
|
|
* @return array Hidden Meta Boxes
|
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
function get_hidden_meta_boxes( $screen ) {
|
2011-09-26 17:32:10 -04:00
|
|
|
if ( is_string( $screen ) )
|
|
|
|
$screen = convert_to_screen( $screen );
|
|
|
|
|
|
|
|
$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
|
|
|
|
|
2011-10-23 15:22:27 -04:00
|
|
|
$use_defaults = ! is_array( $hidden );
|
|
|
|
|
2011-09-26 17:32:10 -04:00
|
|
|
// Hide slug boxes by default
|
2011-10-23 15:22:27 -04:00
|
|
|
if ( $use_defaults ) {
|
|
|
|
$hidden = array();
|
|
|
|
if ( 'post' == $screen->base ) {
|
2012-09-21 18:52:54 -04:00
|
|
|
if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
|
2011-10-23 15:22:27 -04:00
|
|
|
$hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
|
|
|
|
else
|
|
|
|
$hidden = array( 'slugdiv' );
|
|
|
|
}
|
2014-02-25 05:05:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-10-23 15:22:27 -04:00
|
|
|
$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2014-02-25 05:05:14 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-10-23 15:22:27 -04:00
|
|
|
return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2011-10-07 00:57:12 -04:00
|
|
|
/**
|
|
|
|
* Register and configure an admin screen option
|
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
|
|
|
* @param string $option An option name.
|
2011-10-07 01:23:33 -04:00
|
|
|
* @param mixed $args Option-dependent arguments.
|
2011-10-07 00:57:12 -04:00
|
|
|
*/
|
|
|
|
function add_screen_option( $option, $args = array() ) {
|
|
|
|
$current_screen = get_current_screen();
|
|
|
|
|
|
|
|
if ( ! $current_screen )
|
2011-09-30 20:24:44 -04:00
|
|
|
return;
|
2011-09-26 17:32:10 -04:00
|
|
|
|
2011-11-02 16:14:10 -04:00
|
|
|
$current_screen->add_option( $option, $args );
|
2011-10-07 00:57:12 -04:00
|
|
|
}
|
|
|
|
|
2011-09-26 17:32:10 -04:00
|
|
|
/**
|
2011-10-24 02:40:15 -04:00
|
|
|
* Get the current screen object
|
2011-09-26 17:32:10 -04:00
|
|
|
*
|
2011-10-24 02:40:15 -04:00
|
|
|
* @since 3.1.0
|
2011-09-26 17:32:10 -04:00
|
|
|
*
|
2015-05-28 22:06:31 -04:00
|
|
|
* @global WP_Screen $current_screen
|
|
|
|
*
|
2012-02-17 18:15:05 -05:00
|
|
|
* @return WP_Screen Current screen object
|
2011-09-26 17:32:10 -04:00
|
|
|
*/
|
|
|
|
function get_current_screen() {
|
|
|
|
global $current_screen;
|
|
|
|
|
2011-10-24 02:40:15 -04:00
|
|
|
if ( ! isset( $current_screen ) )
|
2011-09-26 17:32:10 -04:00
|
|
|
return null;
|
|
|
|
|
|
|
|
return $current_screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current screen object
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2011-10-24 14:34:08 -04:00
|
|
|
* @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
|
2015-05-29 17:17:27 -04:00
|
|
|
* or an existing screen object.
|
2011-09-26 17:32:10 -04:00
|
|
|
*/
|
2011-12-14 12:36:38 -05:00
|
|
|
function set_current_screen( $hook_name = '' ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
WP_Screen::get( $hook_name )->set_current_screen();
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
2011-10-24 02:40:15 -04:00
|
|
|
* A class representing the admin screen.
|
2011-09-27 10:30:56 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @access public
|
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
final class WP_Screen {
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
2011-12-13 18:45:31 -05:00
|
|
|
* Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
|
2011-09-27 10:30:56 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-11-28 17:58:51 -05:00
|
|
|
public $action;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
|
|
|
/**
|
2011-12-13 18:45:31 -05:00
|
|
|
* The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
|
2011-09-27 10:30:56 -04:00
|
|
|
* For example, for an $id of 'edit-post' the base is 'edit'.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $base;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
2012-04-24 16:46:04 -04:00
|
|
|
/**
|
|
|
|
* The number of columns to display. Access with get_columns().
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
* @var int
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private $columns = 0;
|
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
|
|
|
* The unique ID of the screen.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $id;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
2012-08-31 13:16:46 -04:00
|
|
|
/**
|
|
|
|
* Which admin the screen is in. network | user | site | false
|
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
* @var string
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $in_admin;
|
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
|
|
|
* Whether the screen is in the network admin.
|
|
|
|
*
|
2012-08-31 13:16:46 -04:00
|
|
|
* Deprecated. Use in_admin() instead.
|
|
|
|
*
|
2011-09-27 10:30:56 -04:00
|
|
|
* @since 3.3.0
|
2012-08-31 13:16:46 -04:00
|
|
|
* @deprecated 3.5.0
|
2011-09-27 10:30:56 -04:00
|
|
|
* @var bool
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $is_network;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the screen is in the user admin.
|
|
|
|
*
|
2012-08-31 13:16:46 -04:00
|
|
|
* Deprecated. Use in_admin() instead.
|
|
|
|
*
|
2011-09-27 10:30:56 -04:00
|
|
|
* @since 3.3.0
|
2012-08-31 13:16:46 -04:00
|
|
|
* @deprecated 3.5.0
|
2011-09-27 10:30:56 -04:00
|
|
|
* @var bool
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $is_user;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The base menu parent.
|
|
|
|
* This is derived from $parent_file by removing the query string and any .php extension.
|
|
|
|
* $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $parent_base;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The parent_file for the screen per the admin menu system.
|
|
|
|
* Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $parent_file;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The post type associated with the screen, if any.
|
|
|
|
* The 'edit.php?post_type=page' screen has a post type of 'page'.
|
2011-10-24 14:34:08 -04:00
|
|
|
* The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
|
2011-09-27 10:30:56 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $post_type;
|
2011-09-27 10:30:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The taxonomy associated with the screen, if any.
|
|
|
|
* The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
2011-10-01 13:59:46 -04:00
|
|
|
* @access public
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-26 19:31:54 -04:00
|
|
|
public $taxonomy;
|
|
|
|
|
2011-09-30 20:24:44 -04:00
|
|
|
/**
|
|
|
|
* The help tab data associated with the screen, if any.
|
2013-03-08 22:52:27 -05:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
2011-10-24 14:34:08 -04:00
|
|
|
private $_help_tabs = array();
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2013-03-08 22:52:27 -05:00
|
|
|
/**
|
2011-10-24 14:34:08 -04:00
|
|
|
* The help sidebar data associated with screen, if any.
|
2011-09-30 20:24:44 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2011-10-11 17:32:16 -04:00
|
|
|
* @var string
|
2011-09-30 20:24:44 -04:00
|
|
|
* @access private
|
2013-03-08 22:52:27 -05:00
|
|
|
*/
|
2011-10-24 14:34:08 -04:00
|
|
|
private $_help_sidebar = '';
|
2011-09-30 20:24:44 -04:00
|
|
|
|
|
|
|
/**
|
2011-10-11 17:32:16 -04:00
|
|
|
* Stores old string-based help.
|
2015-05-29 11:43:29 -04:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @access private
|
|
|
|
*
|
|
|
|
* @var array
|
2011-09-30 20:24:44 -04:00
|
|
|
*/
|
2011-10-11 17:32:16 -04:00
|
|
|
private static $_old_compat_help = array();
|
2011-09-30 20:24:44 -04:00
|
|
|
|
|
|
|
/**
|
2011-10-24 14:34:08 -04:00
|
|
|
* The screen options associated with screen, if any.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private $_options = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The screen object registry.
|
2011-09-30 20:24:44 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2015-05-29 11:43:29 -04:00
|
|
|
*
|
|
|
|
* @static
|
2011-09-30 20:24:44 -04:00
|
|
|
* @access private
|
2015-05-29 11:43:29 -04:00
|
|
|
*
|
|
|
|
* @var array
|
2011-09-30 20:24:44 -04:00
|
|
|
*/
|
2011-10-24 14:34:08 -04:00
|
|
|
private static $_registry = array();
|
2011-09-30 20:24:44 -04:00
|
|
|
|
|
|
|
/**
|
2011-10-07 00:57:12 -04:00
|
|
|
* Stores the result of the public show_screen_options function.
|
2011-09-30 20:24:44 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var bool
|
|
|
|
* @access private
|
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
private $_show_screen_options;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the 'screen_settings' section of screen options.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @var string
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private $_screen_settings;
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2013-03-08 22:52:27 -05:00
|
|
|
/**
|
2011-10-24 14:34:08 -04:00
|
|
|
* Fetches a screen object.
|
2013-03-08 22:52:27 -05:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2011-10-24 14:34:08 -04:00
|
|
|
* @access public
|
2013-03-08 22:52:27 -05:00
|
|
|
*
|
2015-05-29 11:43:29 -04:00
|
|
|
* @static
|
|
|
|
*
|
2015-05-28 22:06:31 -04:00
|
|
|
* @global string $hook_suffix
|
|
|
|
*
|
2014-12-20 15:56:22 -05:00
|
|
|
* @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
|
2015-05-29 17:17:27 -04:00
|
|
|
* Defaults to the current $hook_suffix global.
|
2011-10-24 14:34:08 -04:00
|
|
|
* @return WP_Screen Screen object.
|
2013-03-08 22:52:27 -05:00
|
|
|
*/
|
2011-10-25 12:05:39 -04:00
|
|
|
public static function get( $hook_name = '' ) {
|
2015-01-15 20:06:24 -05:00
|
|
|
if ( $hook_name instanceof WP_Screen ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
return $hook_name;
|
2015-01-15 20:06:24 -05:00
|
|
|
}
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2011-11-28 17:58:51 -05:00
|
|
|
$post_type = $taxonomy = null;
|
2012-08-31 13:16:46 -04:00
|
|
|
$in_admin = false;
|
2011-11-28 17:58:51 -05:00
|
|
|
$action = '';
|
2011-10-24 14:34:08 -04:00
|
|
|
|
2011-10-25 02:54:23 -04:00
|
|
|
if ( $hook_name )
|
|
|
|
$id = $hook_name;
|
|
|
|
else
|
|
|
|
$id = $GLOBALS['hook_suffix'];
|
|
|
|
|
2011-11-28 13:33:40 -05:00
|
|
|
// For those pesky meta boxes.
|
|
|
|
if ( $hook_name && post_type_exists( $hook_name ) ) {
|
|
|
|
$post_type = $id;
|
|
|
|
$id = 'post'; // changes later. ends up being $base.
|
|
|
|
} else {
|
2011-11-28 17:58:51 -05:00
|
|
|
if ( '.php' == substr( $id, -4 ) )
|
2011-11-28 13:33:40 -05:00
|
|
|
$id = substr( $id, 0, -4 );
|
2011-11-28 17:58:51 -05:00
|
|
|
|
|
|
|
if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
|
2011-11-28 13:33:40 -05:00
|
|
|
$id = substr( $id, 0, -4 );
|
|
|
|
$action = 'add';
|
|
|
|
}
|
|
|
|
}
|
2011-10-25 02:54:23 -04:00
|
|
|
|
2011-11-28 13:33:40 -05:00
|
|
|
if ( ! $post_type && $hook_name ) {
|
2011-11-03 19:00:46 -04:00
|
|
|
if ( '-network' == substr( $id, -8 ) ) {
|
2011-11-28 13:33:40 -05:00
|
|
|
$id = substr( $id, 0, -8 );
|
2012-08-31 13:16:46 -04:00
|
|
|
$in_admin = 'network';
|
2011-11-03 19:00:46 -04:00
|
|
|
} elseif ( '-user' == substr( $id, -5 ) ) {
|
2011-11-28 13:33:40 -05:00
|
|
|
$id = substr( $id, 0, -5 );
|
2012-08-31 13:16:46 -04:00
|
|
|
$in_admin = 'user';
|
2011-11-03 19:00:46 -04:00
|
|
|
}
|
2011-10-25 02:54:23 -04:00
|
|
|
|
|
|
|
$id = sanitize_key( $id );
|
2011-11-28 17:58:51 -05:00
|
|
|
if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
|
2011-11-28 13:33:40 -05:00
|
|
|
$maybe = substr( $id, 5 );
|
|
|
|
if ( taxonomy_exists( $maybe ) ) {
|
2013-03-08 22:52:27 -05:00
|
|
|
$id = 'edit-tags';
|
2011-11-28 13:33:40 -05:00
|
|
|
$taxonomy = $maybe;
|
|
|
|
} elseif ( post_type_exists( $maybe ) ) {
|
|
|
|
$id = 'edit';
|
|
|
|
$post_type = $maybe;
|
2011-11-01 17:36:04 -04:00
|
|
|
}
|
2013-03-08 22:52:27 -05:00
|
|
|
}
|
2012-08-31 13:16:46 -04:00
|
|
|
|
|
|
|
if ( ! $in_admin )
|
|
|
|
$in_admin = 'site';
|
2011-11-03 19:00:46 -04:00
|
|
|
} else {
|
2012-08-31 13:16:46 -04:00
|
|
|
if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
|
|
|
|
$in_admin = 'network';
|
|
|
|
elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
|
|
|
|
$in_admin = 'user';
|
|
|
|
else
|
|
|
|
$in_admin = 'site';
|
2011-10-25 02:54:23 -04:00
|
|
|
}
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
if ( 'index' == $id )
|
|
|
|
$id = 'dashboard';
|
2012-08-31 13:16:46 -04:00
|
|
|
elseif ( 'front' == $id )
|
|
|
|
$in_admin = false;
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
$base = $id;
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
// If this is the current screen, see if we can be more accurate for post types and taxonomies.
|
|
|
|
if ( ! $hook_name ) {
|
2011-11-17 13:01:08 -05:00
|
|
|
if ( isset( $_REQUEST['post_type'] ) )
|
|
|
|
$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
|
|
|
|
if ( isset( $_REQUEST['taxonomy'] ) )
|
|
|
|
$taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
|
2011-10-31 17:28:17 -04:00
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
switch ( $base ) {
|
|
|
|
case 'post' :
|
|
|
|
if ( isset( $_GET['post'] ) )
|
|
|
|
$post_id = (int) $_GET['post'];
|
|
|
|
elseif ( isset( $_POST['post_ID'] ) )
|
|
|
|
$post_id = (int) $_POST['post_ID'];
|
|
|
|
else
|
|
|
|
$post_id = 0;
|
|
|
|
|
|
|
|
if ( $post_id ) {
|
|
|
|
$post = get_post( $post_id );
|
|
|
|
if ( $post )
|
|
|
|
$post_type = $post->post_type;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'edit-tags' :
|
2011-11-17 13:01:08 -05:00
|
|
|
if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
|
2011-10-24 14:34:08 -04:00
|
|
|
$post_type = 'post';
|
|
|
|
break;
|
|
|
|
}
|
2013-03-08 22:52:27 -05:00
|
|
|
}
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
switch ( $base ) {
|
|
|
|
case 'post' :
|
2011-11-17 13:01:08 -05:00
|
|
|
if ( null === $post_type )
|
2011-10-24 14:34:08 -04:00
|
|
|
$post_type = 'post';
|
|
|
|
$id = $post_type;
|
|
|
|
break;
|
|
|
|
case 'edit' :
|
2011-11-17 13:01:08 -05:00
|
|
|
if ( null === $post_type )
|
2011-10-24 14:34:08 -04:00
|
|
|
$post_type = 'post';
|
|
|
|
$id .= '-' . $post_type;
|
|
|
|
break;
|
|
|
|
case 'edit-tags' :
|
2011-11-17 13:01:08 -05:00
|
|
|
if ( null === $taxonomy )
|
2011-10-24 14:34:08 -04:00
|
|
|
$taxonomy = 'post_tag';
|
2012-09-24 16:39:53 -04:00
|
|
|
// The edit-tags ID does not contain the post type. Look for it in the request.
|
|
|
|
if ( null === $post_type ) {
|
|
|
|
$post_type = 'post';
|
|
|
|
if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
|
|
|
|
$post_type = $_REQUEST['post_type'];
|
|
|
|
}
|
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
$id = 'edit-' . $taxonomy;
|
|
|
|
break;
|
|
|
|
}
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2012-08-31 13:16:46 -04:00
|
|
|
if ( 'network' == $in_admin ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
$id .= '-network';
|
|
|
|
$base .= '-network';
|
2012-08-31 13:16:46 -04:00
|
|
|
} elseif ( 'user' == $in_admin ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
$id .= '-user';
|
|
|
|
$base .= '-user';
|
2013-03-08 22:52:27 -05:00
|
|
|
}
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2011-10-31 17:28:17 -04:00
|
|
|
if ( isset( self::$_registry[ $id ] ) ) {
|
|
|
|
$screen = self::$_registry[ $id ];
|
|
|
|
if ( $screen === get_current_screen() )
|
|
|
|
return $screen;
|
|
|
|
} else {
|
|
|
|
$screen = new WP_Screen();
|
|
|
|
$screen->id = $id;
|
|
|
|
}
|
2011-10-24 14:34:08 -04:00
|
|
|
|
|
|
|
$screen->base = $base;
|
|
|
|
$screen->action = $action;
|
2011-11-17 13:01:08 -05:00
|
|
|
$screen->post_type = (string) $post_type;
|
|
|
|
$screen->taxonomy = (string) $taxonomy;
|
2012-08-31 13:16:46 -04:00
|
|
|
$screen->is_user = ( 'user' == $in_admin );
|
|
|
|
$screen->is_network = ( 'network' == $in_admin );
|
|
|
|
$screen->in_admin = $in_admin;
|
2011-10-24 14:34:08 -04:00
|
|
|
|
|
|
|
self::$_registry[ $id ] = $screen;
|
|
|
|
|
|
|
|
return $screen;
|
2013-03-08 22:52:27 -05:00
|
|
|
}
|
2011-10-24 15:13:23 -04:00
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
2011-10-24 14:34:08 -04:00
|
|
|
* Makes the screen object the current screen.
|
2011-09-27 20:57:56 -04:00
|
|
|
*
|
2011-10-24 14:34:08 -04:00
|
|
|
* @see set_current_screen()
|
2011-09-27 10:30:56 -04:00
|
|
|
* @since 3.3.0
|
2015-05-28 22:06:31 -04:00
|
|
|
*
|
|
|
|
* @global WP_Screen $current_screen
|
|
|
|
* @global string $taxnow
|
|
|
|
* @global string $typenow
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2014-05-19 01:04:16 -04:00
|
|
|
public function set_current_screen() {
|
2011-10-24 14:34:08 -04:00
|
|
|
global $current_screen, $taxnow, $typenow;
|
|
|
|
$current_screen = $this;
|
|
|
|
$taxnow = $this->taxonomy;
|
|
|
|
$typenow = $this->post_type;
|
2014-02-25 05:05:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires after the current screen has been set.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param WP_Screen $current_screen Current WP_Screen object.
|
|
|
|
*/
|
2011-11-30 22:34:55 -05:00
|
|
|
do_action( 'current_screen', $current_screen );
|
2011-10-11 17:32:16 -04:00
|
|
|
}
|
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private function __construct() {}
|
|
|
|
|
2012-08-31 13:16:46 -04:00
|
|
|
/**
|
|
|
|
* Indicates whether the screen is in a particular admin
|
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
*
|
|
|
|
* @param string $admin The admin to check against (network | user | site).
|
2015-05-29 17:17:27 -04:00
|
|
|
* If empty any of the three admins will result in true.
|
|
|
|
* @return bool True if the screen is in the indicated admin, false otherwise.
|
2012-08-31 13:16:46 -04:00
|
|
|
*/
|
|
|
|
public function in_admin( $admin = null ) {
|
|
|
|
if ( empty( $admin ) )
|
|
|
|
return (bool) $this->in_admin;
|
|
|
|
|
|
|
|
return ( $admin == $this->in_admin );
|
|
|
|
}
|
|
|
|
|
2011-10-24 02:40:15 -04:00
|
|
|
/**
|
|
|
|
* Sets the old string-based contextual help for the screen.
|
|
|
|
*
|
|
|
|
* For backwards compatibility.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*
|
2015-05-29 11:43:29 -04:00
|
|
|
* @static
|
|
|
|
*
|
2011-10-24 02:40:15 -04:00
|
|
|
* @param WP_Screen $screen A screen object.
|
|
|
|
* @param string $help Help text.
|
|
|
|
*/
|
2014-05-19 01:04:16 -04:00
|
|
|
public static function add_old_compat_help( $screen, $help ) {
|
2011-10-24 15:13:23 -04:00
|
|
|
self::$_old_compat_help[ $screen->id ] = $help;
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
|
|
|
* Set the parent information for the screen.
|
|
|
|
* This is called in admin-header.php after the menu parent for the screen has been determined.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*
|
2011-12-13 18:45:31 -05:00
|
|
|
* @param string $parent_file The parent file of the screen. Typically the $parent_file global.
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2014-05-19 01:04:16 -04:00
|
|
|
public function set_parentage( $parent_file ) {
|
2011-09-26 17:32:10 -04:00
|
|
|
$this->parent_file = $parent_file;
|
2011-10-24 02:40:15 -04:00
|
|
|
list( $this->parent_base ) = explode( '?', $parent_file );
|
|
|
|
$this->parent_base = str_replace( '.php', '', $this->parent_base );
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
|
|
|
* Adds an option for the screen.
|
2011-10-07 00:57:12 -04:00
|
|
|
* Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
|
2011-09-27 20:57:56 -04:00
|
|
|
*
|
2011-09-27 10:30:56 -04:00
|
|
|
* @since 3.3.0
|
|
|
|
*
|
|
|
|
* @param string $option Option ID
|
2011-10-07 01:23:33 -04:00
|
|
|
* @param mixed $args Option-dependent arguments.
|
2011-10-03 00:00:57 -04:00
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
public function add_option( $option, $args = array() ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
$this->_options[ $option ] = $args;
|
2011-10-11 17:32:16 -04:00
|
|
|
}
|
|
|
|
|
2013-11-28 00:10:09 -05:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2011-10-11 17:32:16 -04:00
|
|
|
/**
|
|
|
|
* Gets the arguments for an option for the screen.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*
|
2014-11-17 12:11:23 -05:00
|
|
|
* @param string $option Option name.
|
|
|
|
* @param string $key Optional. Specific array key for when the option is an array.
|
|
|
|
* Default false.
|
2014-11-30 20:00:22 -05:00
|
|
|
* @return string The option value if set, null otherwise.
|
2011-10-11 17:32:16 -04:00
|
|
|
*/
|
|
|
|
public function get_option( $option, $key = false ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
if ( ! isset( $this->_options[ $option ] ) )
|
2011-10-11 17:32:16 -04:00
|
|
|
return null;
|
|
|
|
if ( $key ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
if ( isset( $this->_options[ $option ][ $key ] ) )
|
|
|
|
return $this->_options[ $option ][ $key ];
|
2011-10-11 17:32:16 -04:00
|
|
|
return null;
|
|
|
|
}
|
2011-10-24 14:34:08 -04:00
|
|
|
return $this->_options[ $option ];
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2012-02-17 18:40:02 -05:00
|
|
|
/**
|
|
|
|
* Gets the help tabs registered for the screen.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @return array Help tabs with arguments.
|
|
|
|
*/
|
|
|
|
public function get_help_tabs() {
|
|
|
|
return $this->_help_tabs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the arguments for a help tab.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @param string $id Help Tab ID.
|
|
|
|
* @return array Help tab arguments.
|
|
|
|
*/
|
|
|
|
public function get_help_tab( $id ) {
|
|
|
|
if ( ! isset( $this->_help_tabs[ $id ] ) )
|
|
|
|
return null;
|
|
|
|
return $this->_help_tabs[ $id ];
|
|
|
|
}
|
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
|
|
|
* Add a help tab to the contextual help for the screen.
|
2011-11-02 16:14:10 -04:00
|
|
|
* Call this on the load-$pagenow hook for the relevant screen.
|
2011-09-27 20:57:56 -04:00
|
|
|
*
|
2011-09-27 10:30:56 -04:00
|
|
|
* @since 3.3.0
|
|
|
|
*
|
2011-09-30 20:24:44 -04:00
|
|
|
* @param array $args
|
|
|
|
* - string - title - Title for the tab.
|
2011-10-11 15:29:09 -04:00
|
|
|
* - string - id - Tab ID. Must be HTML-safe.
|
2011-09-30 20:24:44 -04:00
|
|
|
* - string - content - Help tab content in plain text or HTML. Optional.
|
|
|
|
* - callback - callback - A callback to generate the tab content. Optional.
|
|
|
|
*
|
2011-09-27 10:30:56 -04:00
|
|
|
*/
|
2011-09-30 20:24:44 -04:00
|
|
|
public function add_help_tab( $args ) {
|
|
|
|
$defaults = array(
|
|
|
|
'title' => false,
|
|
|
|
'id' => false,
|
|
|
|
'content' => '',
|
2011-10-07 00:57:12 -04:00
|
|
|
'callback' => false,
|
2011-09-30 20:24:44 -04:00
|
|
|
);
|
|
|
|
$args = wp_parse_args( $args, $defaults );
|
|
|
|
|
2011-10-11 15:29:09 -04:00
|
|
|
$args['id'] = sanitize_html_class( $args['id'] );
|
2011-10-07 00:57:12 -04:00
|
|
|
|
2011-10-11 15:29:09 -04:00
|
|
|
// Ensure we have an ID and title.
|
|
|
|
if ( ! $args['id'] || ! $args['title'] )
|
|
|
|
return;
|
2011-09-26 17:32:10 -04:00
|
|
|
|
2012-02-17 18:40:02 -05:00
|
|
|
// Allows for overriding an existing tab with that ID.
|
|
|
|
$this->_help_tabs[ $args['id'] ] = $args;
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
|
|
|
|
2011-11-02 16:14:10 -04:00
|
|
|
/**
|
|
|
|
* Removes a help tab from the contextual help for the screen.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*
|
|
|
|
* @param string $id The help tab ID.
|
|
|
|
*/
|
|
|
|
public function remove_help_tab( $id ) {
|
|
|
|
unset( $this->_help_tabs[ $id ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all help tabs from the contextual help for the screen.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
public function remove_help_tabs() {
|
|
|
|
$this->_help_tabs = array();
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:40:02 -05:00
|
|
|
/**
|
|
|
|
* Gets the content from a contextual help sidebar.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2012-02-18 16:59:47 -05:00
|
|
|
* @return string Contents of the help sidebar.
|
2012-02-17 18:40:02 -05:00
|
|
|
*/
|
|
|
|
public function get_help_sidebar() {
|
|
|
|
return $this->_help_sidebar;
|
|
|
|
}
|
2012-04-24 16:46:04 -04:00
|
|
|
|
2011-09-27 10:30:56 -04:00
|
|
|
/**
|
|
|
|
* Add a sidebar to the contextual help for the screen.
|
2011-10-07 00:57:12 -04:00
|
|
|
* 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.
|
2011-09-27 20:57:56 -04:00
|
|
|
*
|
2011-09-27 10:30:56 -04:00
|
|
|
* @since 3.3.0
|
|
|
|
*
|
|
|
|
* @param string $content Sidebar content in plain text or HTML.
|
|
|
|
*/
|
2011-11-02 16:14:10 -04:00
|
|
|
public function set_help_sidebar( $content ) {
|
2011-10-24 14:34:08 -04:00
|
|
|
$this->_help_sidebar = $content;
|
2011-09-30 20:24:44 -04:00
|
|
|
}
|
|
|
|
|
2012-04-24 16:46:04 -04:00
|
|
|
/**
|
|
|
|
* Gets the number of layout columns the user has selected.
|
|
|
|
*
|
|
|
|
* The layout_columns option controls the max number and default number of
|
|
|
|
* columns. This method returns the number of columns within that range selected
|
|
|
|
* by the user via Screen Options. If no selection has been made, the default
|
|
|
|
* provisioned in layout_columns is returned. If the screen does not support
|
|
|
|
* selecting the number of layout columns, 0 is returned.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @return int Number of columns to display.
|
|
|
|
*/
|
|
|
|
public function get_columns() {
|
|
|
|
return $this->columns;
|
|
|
|
}
|
|
|
|
|
2011-09-30 20:24:44 -04:00
|
|
|
/**
|
|
|
|
* Render the screen's help section.
|
|
|
|
*
|
|
|
|
* This will trigger the deprecated filters for backwards compatibility.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2015-05-28 22:06:31 -04:00
|
|
|
*
|
|
|
|
* @global string $screen_layout_columns
|
2011-09-30 20:24:44 -04:00
|
|
|
*/
|
|
|
|
public function render_screen_meta() {
|
2011-09-26 17:32:10 -04:00
|
|
|
|
2014-02-25 05:05:14 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-10-11 17:45:28 -04:00
|
|
|
self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2011-10-31 17:37:43 -04:00
|
|
|
$old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
|
2014-02-25 05:05:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2011-10-31 17:37:43 -04:00
|
|
|
$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.
|
2012-02-17 18:40:02 -05:00
|
|
|
if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
|
2014-02-25 05:05:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-11-06 13:13:06 -05:00
|
|
|
$default_help = apply_filters( 'default_contextual_help', '' );
|
|
|
|
if ( $default_help )
|
|
|
|
$old_help = '<p>' . $default_help . '</p>';
|
2011-10-31 17:37:43 -04:00
|
|
|
}
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2011-10-31 17:37:43 -04:00
|
|
|
if ( $old_help ) {
|
2011-09-30 20:24:44 -04:00
|
|
|
$this->add_help_tab( array(
|
2011-12-06 19:13:52 -05:00
|
|
|
'id' => 'old-contextual-help',
|
2011-11-30 15:58:39 -05:00
|
|
|
'title' => __('Overview'),
|
2011-10-31 17:37:43 -04:00
|
|
|
'content' => $old_help,
|
2011-10-07 00:57:12 -04:00
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:40:02 -05:00
|
|
|
$help_sidebar = $this->get_help_sidebar();
|
2011-11-23 17:14:03 -05:00
|
|
|
|
|
|
|
$help_class = 'hidden';
|
2012-02-17 18:40:02 -05:00
|
|
|
if ( ! $help_sidebar )
|
2011-11-23 17:14:03 -05:00
|
|
|
$help_class .= ' no-sidebar';
|
|
|
|
|
2011-09-30 20:24:44 -04:00
|
|
|
// Time to render!
|
|
|
|
?>
|
2011-11-03 13:08:12 -04:00
|
|
|
<div id="screen-meta" class="metabox-prefs">
|
2011-11-23 17:14:03 -05:00
|
|
|
|
2012-08-06 00:26:37 -04:00
|
|
|
<div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
|
2011-11-19 20:03:17 -05:00
|
|
|
<div id="contextual-help-back"></div>
|
|
|
|
<div id="contextual-help-columns">
|
|
|
|
<div class="contextual-help-tabs">
|
|
|
|
<ul>
|
2012-02-17 18:40:02 -05:00
|
|
|
<?php
|
|
|
|
$class = ' class="active"';
|
|
|
|
foreach ( $this->get_help_tabs() as $tab ) :
|
2011-11-19 20:03:17 -05:00
|
|
|
$link_id = "tab-link-{$tab['id']}";
|
|
|
|
$panel_id = "tab-panel-{$tab['id']}";
|
|
|
|
?>
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2012-02-24 15:49:54 -05:00
|
|
|
<li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
|
2012-08-06 00:26:37 -04:00
|
|
|
<a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">
|
2011-11-19 20:03:17 -05:00
|
|
|
<?php echo esc_html( $tab['title'] ); ?>
|
|
|
|
</a>
|
|
|
|
</li>
|
2012-02-17 18:40:02 -05:00
|
|
|
<?php
|
|
|
|
$class = '';
|
|
|
|
endforeach;
|
|
|
|
?>
|
2011-11-19 20:03:17 -05:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
2012-02-17 18:40:02 -05:00
|
|
|
<?php if ( $help_sidebar ) : ?>
|
2011-11-19 20:03:17 -05:00
|
|
|
<div class="contextual-help-sidebar">
|
2012-02-17 18:40:02 -05:00
|
|
|
<?php echo $help_sidebar; ?>
|
2011-11-19 20:03:17 -05:00
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
<div class="contextual-help-tabs-wrap">
|
2012-02-17 18:40:02 -05:00
|
|
|
<?php
|
|
|
|
$classes = 'help-tab-content active';
|
|
|
|
foreach ( $this->get_help_tabs() as $tab ):
|
2011-11-19 20:03:17 -05:00
|
|
|
$panel_id = "tab-panel-{$tab['id']}";
|
2011-09-30 20:24:44 -04:00
|
|
|
?>
|
2011-11-19 20:03:17 -05:00
|
|
|
|
2012-02-17 18:40:02 -05:00
|
|
|
<div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
|
2011-11-19 20:03:17 -05:00
|
|
|
<?php
|
|
|
|
// Print tab content.
|
|
|
|
echo $tab['content'];
|
|
|
|
|
|
|
|
// If it exists, fire tab callback.
|
|
|
|
if ( ! empty( $tab['callback'] ) )
|
|
|
|
call_user_func_array( $tab['callback'], array( $this, $tab ) );
|
|
|
|
?>
|
|
|
|
</div>
|
2012-02-17 18:40:02 -05:00
|
|
|
<?php
|
|
|
|
$classes = 'help-tab-content';
|
|
|
|
endforeach;
|
|
|
|
?>
|
2011-11-19 20:03:17 -05:00
|
|
|
</div>
|
2011-09-30 20:24:44 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2011-11-03 13:08:12 -04:00
|
|
|
<?php
|
2012-04-24 16:46:04 -04:00
|
|
|
// Setup layout columns
|
|
|
|
|
2014-02-25 05:05:14 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-04-24 16:46:04 -04:00
|
|
|
$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
|
|
|
|
|
|
|
|
if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
|
|
|
|
$this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
|
|
|
|
|
|
|
|
if ( $this->get_option( 'layout_columns' ) ) {
|
|
|
|
$this->columns = (int) get_user_option("screen_layout_$this->id");
|
2012-05-03 12:41:59 -04:00
|
|
|
|
2012-04-24 16:46:04 -04:00
|
|
|
if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
|
|
|
|
$this->columns = $this->get_option( 'layout_columns', 'default' );
|
|
|
|
}
|
2012-04-25 13:49:48 -04:00
|
|
|
$GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
|
2012-04-24 16:46:04 -04:00
|
|
|
|
2011-11-03 13:08:12 -04:00
|
|
|
// Add screen options
|
|
|
|
if ( $this->show_screen_options() )
|
|
|
|
$this->render_screen_options();
|
|
|
|
?>
|
|
|
|
</div>
|
2011-11-06 13:13:06 -05:00
|
|
|
<?php
|
2012-02-17 18:40:02 -05:00
|
|
|
if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
|
2011-11-06 13:13:06 -05:00
|
|
|
return;
|
|
|
|
?>
|
2011-11-03 16:26:09 -04:00
|
|
|
<div id="screen-meta-links">
|
2012-02-17 18:40:02 -05:00
|
|
|
<?php if ( $this->get_help_tabs() ) : ?>
|
2011-11-06 13:13:06 -05:00
|
|
|
<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
|
2015-06-18 12:36:25 -04:00
|
|
|
<button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
|
2011-11-06 13:13:06 -05:00
|
|
|
</div>
|
|
|
|
<?php endif;
|
|
|
|
if ( $this->show_screen_options() ) : ?>
|
|
|
|
<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
|
2015-06-18 12:36:25 -04:00
|
|
|
<button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
|
2011-11-06 13:13:06 -05:00
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
2011-09-30 20:24:44 -04:00
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2015-05-28 22:06:31 -04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @global array $wp_meta_boxes
|
2015-05-29 11:43:29 -04:00
|
|
|
*
|
2015-05-28 22:06:31 -04:00
|
|
|
* @return bool
|
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
public function show_screen_options() {
|
2011-10-24 02:40:15 -04:00
|
|
|
global $wp_meta_boxes;
|
2011-10-07 00:57:12 -04:00
|
|
|
|
|
|
|
if ( is_bool( $this->_show_screen_options ) )
|
|
|
|
return $this->_show_screen_options;
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2011-10-07 00:57:12 -04:00
|
|
|
$columns = get_column_headers( $this );
|
|
|
|
|
2011-10-24 02:40:15 -04:00
|
|
|
$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
|
2011-10-07 00:57:12 -04:00
|
|
|
|
2014-08-24 13:57:16 -04:00
|
|
|
switch ( $this->base ) {
|
2011-09-30 20:24:44 -04:00
|
|
|
case 'widgets':
|
2011-10-07 00:57:12 -04:00
|
|
|
$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";
|
2011-09-30 20:24:44 -04:00
|
|
|
break;
|
2014-08-24 13:57:16 -04:00
|
|
|
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 ) . ' />';
|
2014-12-03 17:00:29 -05:00
|
|
|
$expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></div>';
|
2014-08-24 13:57:16 -04:00
|
|
|
$this->_screen_settings = $expand;
|
|
|
|
break;
|
2013-02-28 02:40:11 -05:00
|
|
|
default:
|
|
|
|
$this->_screen_settings = '';
|
|
|
|
break;
|
2011-09-30 20:24:44 -04:00
|
|
|
}
|
|
|
|
|
2014-02-25 05:05:14 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-02-28 02:40:11 -05:00
|
|
|
$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
|
|
|
|
|
2011-10-24 14:34:08 -04:00
|
|
|
if ( $this->_screen_settings || $this->_options )
|
2011-10-07 00:57:12 -04:00
|
|
|
$show_screen = true;
|
2011-10-03 23:32:12 -04:00
|
|
|
|
2014-02-25 05:05:14 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
$this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
|
|
|
|
return $this->_show_screen_options;
|
2011-10-02 02:59:36 -04:00
|
|
|
}
|
|
|
|
|
2011-09-30 20:24:44 -04:00
|
|
|
/**
|
2011-10-07 00:57:12 -04:00
|
|
|
* Render the screen options tab.
|
2011-09-30 20:24:44 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2015-05-28 22:06:31 -04:00
|
|
|
*
|
|
|
|
* @global array $wp_meta_boxes
|
2011-09-30 20:24:44 -04:00
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
public function render_screen_options() {
|
2014-05-06 13:14:15 -04:00
|
|
|
global $wp_meta_boxes;
|
2011-10-07 00:57:12 -04:00
|
|
|
|
2011-09-30 20:24:44 -04:00
|
|
|
$columns = get_column_headers( $this );
|
2011-10-07 00:57:12 -04:00
|
|
|
$hidden = get_hidden_columns( $this );
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2011-10-07 00:57:12 -04:00
|
|
|
?>
|
2012-08-06 00:26:37 -04:00
|
|
|
<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>">
|
2015-01-15 23:16:24 -05:00
|
|
|
<form id="adv-settings" method="post">
|
2014-07-24 01:26:15 -04:00
|
|
|
<?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
|
2012-02-17 18:19:52 -05:00
|
|
|
<h5><?php _e( 'Show on screen' ); ?></h5>
|
2011-10-07 01:23:33 -04:00
|
|
|
<?php
|
2012-02-17 18:19:52 -05:00
|
|
|
endif;
|
|
|
|
|
2011-10-07 01:23:33 -04:00
|
|
|
if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
|
2011-10-07 00:57:12 -04:00
|
|
|
<div class="metabox-prefs">
|
2011-10-19 17:43:21 -04:00
|
|
|
<?php
|
|
|
|
meta_box_prefs( $this );
|
|
|
|
|
2012-09-26 15:44:43 -04:00
|
|
|
if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
|
2011-11-23 13:30:45 -05:00
|
|
|
if ( isset( $_GET['welcome'] ) ) {
|
|
|
|
$welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
|
|
|
|
update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
|
|
|
|
} else {
|
|
|
|
$welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
|
|
|
|
if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) )
|
|
|
|
$welcome_checked = false;
|
|
|
|
}
|
2011-10-19 17:43:21 -04:00
|
|
|
echo '<label for="wp_welcome_panel-hide">';
|
2011-12-13 18:45:31 -05:00
|
|
|
echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
|
2012-02-01 09:47:49 -05:00
|
|
|
echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
|
2011-10-19 17:43:21 -04:00
|
|
|
}
|
|
|
|
?>
|
2011-10-07 00:57:12 -04:00
|
|
|
<br class="clear" />
|
|
|
|
</div>
|
|
|
|
<?php endif;
|
2012-02-17 18:19:52 -05:00
|
|
|
if ( $columns ) :
|
|
|
|
if ( ! empty( $columns['_title'] ) ) : ?>
|
|
|
|
<h5><?php echo $columns['_title']; ?></h5>
|
|
|
|
<?php endif; ?>
|
2011-09-30 20:24:44 -04:00
|
|
|
<div class="metabox-prefs">
|
|
|
|
<?php
|
|
|
|
$special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
|
|
|
|
|
|
|
|
foreach ( $columns as $column => $title ) {
|
|
|
|
// Can't hide these for they are special
|
|
|
|
if ( in_array( $column, $special ) )
|
|
|
|
continue;
|
|
|
|
if ( empty( $title ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( 'comments' == $column )
|
|
|
|
$title = __( 'Comments' );
|
|
|
|
$id = "$column-hide";
|
|
|
|
echo '<label for="' . $id . '">';
|
|
|
|
echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
|
|
|
|
echo "$title</label>\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<br class="clear" />
|
|
|
|
</div>
|
2011-10-07 00:57:12 -04:00
|
|
|
<?php endif;
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2011-10-07 00:57:12 -04:00
|
|
|
$this->render_screen_layout();
|
|
|
|
$this->render_per_page_options();
|
|
|
|
echo $this->_screen_settings;
|
2011-10-03 23:32:12 -04:00
|
|
|
|
2011-10-07 00:57:12 -04:00
|
|
|
?>
|
|
|
|
<div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
|
|
|
|
</form>
|
2011-11-03 13:08:12 -04:00
|
|
|
</div>
|
2011-10-07 00:57:12 -04:00
|
|
|
<?php
|
2011-09-30 20:24:44 -04:00
|
|
|
}
|
|
|
|
|
2011-10-01 20:04:30 -04:00
|
|
|
/**
|
|
|
|
* Render the option for number of columns on the page
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
2014-05-19 01:04:16 -04:00
|
|
|
public function render_screen_layout() {
|
2012-04-24 16:46:04 -04:00
|
|
|
if ( ! $this->get_option('layout_columns') )
|
2011-09-30 20:24:44 -04:00
|
|
|
return;
|
|
|
|
|
2012-04-24 16:46:04 -04:00
|
|
|
$screen_layout_columns = $this->get_columns();
|
2011-10-11 17:32:16 -04:00
|
|
|
$num = $this->get_option( 'layout_columns', 'max' );
|
2011-09-30 20:24:44 -04:00
|
|
|
|
|
|
|
?>
|
2012-03-23 17:41:00 -04:00
|
|
|
<h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>
|
2011-09-30 20:24:44 -04:00
|
|
|
<div class='columns-prefs'><?php
|
|
|
|
_e('Number of Columns:');
|
|
|
|
for ( $i = 1; $i <= $num; ++$i ):
|
|
|
|
?>
|
2012-03-23 17:41:00 -04:00
|
|
|
<label class="columns-prefs-<?php echo $i; ?>">
|
2011-09-30 20:24:44 -04:00
|
|
|
<input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
|
|
|
|
<?php checked( $screen_layout_columns, $i ); ?> />
|
|
|
|
<?php echo esc_html( $i ); ?>
|
|
|
|
</label>
|
|
|
|
<?php
|
|
|
|
endfor; ?>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2011-10-01 20:04:30 -04:00
|
|
|
/**
|
|
|
|
* Render the items per page option
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
2014-05-19 01:04:16 -04:00
|
|
|
public function render_per_page_options() {
|
2015-03-10 11:32:27 -04:00
|
|
|
if ( null === $this->get_option( 'per_page' ) ) {
|
2011-09-30 20:24:44 -04:00
|
|
|
return;
|
2015-03-10 11:32:27 -04:00
|
|
|
}
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2011-10-11 17:32:16 -04:00
|
|
|
$per_page_label = $this->get_option( 'per_page', 'label' );
|
2015-03-10 11:32:27 -04:00
|
|
|
if ( null === $per_page_label ) {
|
|
|
|
$per_page_label = __( 'Number of items per page:' );
|
|
|
|
}
|
2011-09-30 20:24:44 -04:00
|
|
|
|
2011-10-11 17:32:16 -04:00
|
|
|
$option = $this->get_option( 'per_page', 'option' );
|
2015-03-10 11:32:27 -04:00
|
|
|
if ( ! $option ) {
|
2011-09-30 20:24:44 -04:00
|
|
|
$option = str_replace( '-', '_', "{$this->id}_per_page" );
|
2015-03-10 11:32:27 -04:00
|
|
|
}
|
2011-09-30 20:24:44 -04:00
|
|
|
|
|
|
|
$per_page = (int) get_user_option( $option );
|
|
|
|
if ( empty( $per_page ) || $per_page < 1 ) {
|
2011-10-11 17:32:16 -04:00
|
|
|
$per_page = $this->get_option( 'per_page', 'default' );
|
2015-03-10 11:32:27 -04:00
|
|
|
if ( ! $per_page ) {
|
2011-09-30 20:24:44 -04:00
|
|
|
$per_page = 20;
|
2015-03-10 11:32:27 -04:00
|
|
|
}
|
2011-09-30 20:24:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'edit_comments_per_page' == $option ) {
|
|
|
|
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
|
2014-02-25 05:05:14 -05:00
|
|
|
|
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
|
2011-09-30 20:24:44 -04:00
|
|
|
$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
|
|
|
|
} elseif ( 'categories_per_page' == $option ) {
|
2014-02-25 05:05:14 -05:00
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
|
2011-09-30 20:24:44 -04:00
|
|
|
$per_page = apply_filters( 'edit_categories_per_page', $per_page );
|
|
|
|
} else {
|
2014-02-25 05:05:14 -05:00
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-list-table.php */
|
2011-09-30 20:24:44 -04:00
|
|
|
$per_page = apply_filters( $option, $per_page );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Back compat
|
2014-02-25 05:05:14 -05:00
|
|
|
if ( isset( $this->post_type ) ) {
|
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
|
2011-09-30 20:24:44 -04:00
|
|
|
$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
|
2014-02-25 05:05:14 -05:00
|
|
|
}
|
2011-09-30 20:24:44 -04:00
|
|
|
|
|
|
|
?>
|
2012-04-27 15:46:33 -04:00
|
|
|
<div class="screen-options">
|
|
|
|
<?php if ( $per_page_label ) : ?>
|
2015-03-10 11:32:27 -04:00
|
|
|
<label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
|
2012-04-27 15:46:33 -04:00
|
|
|
<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 ); ?>" />
|
2011-09-30 20:24:44 -04:00
|
|
|
<?php endif;
|
|
|
|
|
|
|
|
echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
|
2015-03-10 11:32:27 -04:00
|
|
|
<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
|
2011-09-30 20:24:44 -04:00
|
|
|
</div>
|
|
|
|
<?php
|
2011-09-26 17:32:10 -04:00
|
|
|
}
|
2011-11-03 13:08:12 -04:00
|
|
|
}
|