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 ] ) ) {
|
|
|
|
|
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the column headers for a list table on a specific screen.
|
2014-02-25 05:05:14 -05:00
|
|
|
*
|
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' );
|
|
|
|
|
2016-01-01 23:44:27 -05:00
|
|
|
$use_defaults = ! is_array( $hidden );
|
|
|
|
|
|
|
|
if ( $use_defaults ) {
|
2015-08-21 11:32:29 -04:00
|
|
|
$hidden = array();
|
|
|
|
|
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the default list of hidden columns.
|
2015-08-21 11:32:29 -04:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the list of hidden columns.
|
2015-08-21 11:32:29 -04:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2016-01-02 10:16:28 -05:00
|
|
|
* @since 4.4.1 Added the `use_defaults` parameter.
|
2015-08-21 11:32:29 -04:00
|
|
|
*
|
|
|
|
* @param array $hidden An array of hidden columns.
|
|
|
|
* @param WP_Screen $screen WP_Screen object of the current screen.
|
2016-01-01 23:44:27 -05:00
|
|
|
* @param bool $use_defaults Whether to show the default columns.
|
2015-08-21 11:32:29 -04:00
|
|
|
*/
|
2016-01-01 23:44:27 -05:00
|
|
|
return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults );
|
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;
|
2016-07-05 11:22:29 -04:00
|
|
|
|
|
|
|
$widget_title = $box['title'];
|
|
|
|
|
|
|
|
if ( isset( $box['args']['__widget_basename'] ) ) {
|
|
|
|
$widget_title = $box['args']['__widget_basename'];
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(
|
|
|
|
'<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>',
|
|
|
|
esc_attr( $box['id'] ),
|
|
|
|
checked( in_array( $box['id'], $hidden ), false, false ),
|
|
|
|
$widget_title
|
|
|
|
);
|
2011-10-07 00:57:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the default list of hidden meta boxes.
|
2014-02-25 05:05:14 -05:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the list of hidden meta boxes.
|
2014-02-25 05:05:14 -05:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
2016-05-23 12:34:28 -04:00
|
|
|
* @return WP_Screen|null Current screen object or null when screen not defined.
|
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
|
|
|
}
|