2011-09-26 23:32:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WordPress Administration Screen API.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the column headers for a screen
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2015-05-29 17:43:29 +02:00
|
|
|
* @staticvar array $column_headers
|
|
|
|
*
|
2011-10-24 08:40:15 +02:00
|
|
|
* @param string|WP_Screen $screen The screen you want the headers for
|
2019-10-26 23:09:04 +02:00
|
|
|
* @return string[] The column header labels keyed by column ID.
|
2011-09-26 23:32:10 +02:00
|
|
|
*/
|
2011-10-07 06:57:12 +02:00
|
|
|
function get_column_headers( $screen ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-09-26 23:32:10 +02:00
|
|
|
$screen = convert_to_screen( $screen );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-09-26 23:32:10 +02:00
|
|
|
|
2011-10-11 23:32:16 +02:00
|
|
|
static $column_headers = array();
|
2011-09-26 23:32:10 +02:00
|
|
|
|
2014-02-25 11:05:14 +01:00
|
|
|
if ( ! isset( $column_headers[ $screen->id ] ) ) {
|
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the column headers for a list table on a specific screen.
|
2014-02-25 11:05:14 +01:00
|
|
|
*
|
2014-11-30 12:28:24 +01:00
|
|
|
* The dynamic portion of the hook name, `$screen->id`, refers to the
|
2014-02-25 11:05:14 +01: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
|
|
|
|
*
|
2019-10-26 23:09:04 +02:00
|
|
|
* @param string[] $columns The column header labels keyed by column ID.
|
2014-02-25 11:05:14 +01:00
|
|
|
*/
|
2014-05-08 11:58:14 +02:00
|
|
|
$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
|
2014-02-25 11:05:14 +01:00
|
|
|
}
|
2011-09-26 23:32:10 +02:00
|
|
|
|
2011-10-11 23:32:16 +02:00
|
|
|
return $column_headers[ $screen->id ];
|
2011-09-26 23:32:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of hidden columns.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2011-10-24 08:40:15 +02:00
|
|
|
* @param string|WP_Screen $screen The screen you want the hidden columns for
|
2019-12-07 14:23:01 +01:00
|
|
|
* @return string[] Array of IDs of hidden columns.
|
2011-09-26 23:32:10 +02:00
|
|
|
*/
|
2011-10-07 06:57:12 +02:00
|
|
|
function get_hidden_columns( $screen ) {
|
2015-08-21 17:32:29 +02:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-09-26 23:32:10 +02:00
|
|
|
$screen = convert_to_screen( $screen );
|
2015-08-21 17:32:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
|
|
|
|
|
2016-01-02 05:44:27 +01:00
|
|
|
$use_defaults = ! is_array( $hidden );
|
|
|
|
|
|
|
|
if ( $use_defaults ) {
|
2015-08-21 17:32:29 +02:00
|
|
|
$hidden = array();
|
|
|
|
|
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the default list of hidden columns.
|
2015-08-21 17:32:29 +02:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
2019-12-07 14:23:01 +01:00
|
|
|
* @param string[] $hidden Array of IDs of columns hidden by default.
|
2015-08-21 17:32:29 +02:00
|
|
|
* @param WP_Screen $screen WP_Screen object of the current screen.
|
|
|
|
*/
|
|
|
|
$hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
|
|
|
|
}
|
2011-09-26 23:32:10 +02:00
|
|
|
|
2015-08-21 17:32:29 +02:00
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the list of hidden columns.
|
2015-08-21 17:32:29 +02:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2016-01-02 16:16:28 +01:00
|
|
|
* @since 4.4.1 Added the `use_defaults` parameter.
|
2015-08-21 17:32:29 +02:00
|
|
|
*
|
2019-12-07 14:23:01 +01:00
|
|
|
* @param string[] $hidden Array of IDs of hidden columns.
|
|
|
|
* @param WP_Screen $screen WP_Screen object of the current screen.
|
2016-01-02 05:44:27 +01:00
|
|
|
* @param bool $use_defaults Whether to show the default columns.
|
2015-08-21 17:32:29 +02:00
|
|
|
*/
|
2016-01-02 05:44:27 +01:00
|
|
|
return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults );
|
2011-09-26 23:32:10 +02:00
|
|
|
}
|
|
|
|
|
2011-10-07 06:57:12 +02:00
|
|
|
/**
|
2011-10-24 08:40:15 +02:00
|
|
|
* Prints the meta box preferences for screen meta.
|
2011-10-07 06:57:12 +02:00
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2015-05-29 04:06:31 +02:00
|
|
|
* @global array $wp_meta_boxes
|
|
|
|
*
|
2014-12-01 02:00:22 +01:00
|
|
|
* @param WP_Screen $screen
|
2011-10-07 06:57:12 +02:00
|
|
|
*/
|
2011-10-11 23:32:16 +02:00
|
|
|
function meta_box_prefs( $screen ) {
|
2011-10-07 06:57:12 +02:00
|
|
|
global $wp_meta_boxes;
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-10-24 08:40:15 +02:00
|
|
|
$screen = convert_to_screen( $screen );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-10-07 06:57:12 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
|
2011-10-07 06:57:12 +02:00
|
|
|
return;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-10-07 06:57:12 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$hidden = get_hidden_meta_boxes( $screen );
|
2011-10-07 06:57:12 +02:00
|
|
|
|
2015-06-08 14:35:26 +02: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 ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( false == $box || ! $box['title'] ) {
|
2011-10-07 06:57:12 +02:00
|
|
|
continue;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2020-01-29 01:45:18 +01:00
|
|
|
// Submit box cannot be hidden.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) {
|
2011-10-07 06:57:12 +02:00
|
|
|
continue;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2016-07-05 17:22:29 +02:00
|
|
|
|
|
|
|
$widget_title = $box['title'];
|
|
|
|
|
2016-07-07 18:39:29 +02:00
|
|
|
if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
|
2016-07-05 17:22:29 +02:00
|
|
|
$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 06:57:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 23:32:10 +02:00
|
|
|
/**
|
2019-11-05 22:30:03 +01:00
|
|
|
* Gets an array of IDs of hidden meta boxes.
|
2011-09-26 23:32:10 +02:00
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2011-10-24 08:40:15 +02:00
|
|
|
* @param string|WP_Screen $screen Screen identifier
|
2019-11-05 22:30:03 +01:00
|
|
|
* @return string[] IDs of hidden meta boxes.
|
2011-09-26 23:32:10 +02:00
|
|
|
*/
|
2011-10-07 06:57:12 +02:00
|
|
|
function get_hidden_meta_boxes( $screen ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-09-26 23:32:10 +02:00
|
|
|
$screen = convert_to_screen( $screen );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-09-26 23:32:10 +02:00
|
|
|
|
|
|
|
$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
|
|
|
|
|
2011-10-23 21:22:27 +02:00
|
|
|
$use_defaults = ! is_array( $hidden );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Hide slug boxes by default.
|
2011-10-23 21:22:27 +02:00
|
|
|
if ( $use_defaults ) {
|
|
|
|
$hidden = array();
|
|
|
|
if ( 'post' == $screen->base ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) {
|
|
|
|
$hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' );
|
|
|
|
} else {
|
2011-10-23 21:22:27 +02:00
|
|
|
$hidden = array( 'slugdiv' );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-10-23 21:22:27 +02:00
|
|
|
}
|
2014-02-25 11:05:14 +01:00
|
|
|
|
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the default list of hidden meta boxes.
|
2014-02-25 11:05:14 +01:00
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
2019-11-05 22:30:03 +01:00
|
|
|
* @param string[] $hidden An array of IDs of meta boxes hidden by default.
|
2014-02-25 11:05:14 +01:00
|
|
|
* @param WP_Screen $screen WP_Screen object of the current screen.
|
|
|
|
*/
|
2011-10-23 21:22:27 +02:00
|
|
|
$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
|
2011-09-26 23:32:10 +02:00
|
|
|
}
|
|
|
|
|
2014-02-25 11:05:14 +01:00
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the list of hidden meta boxes.
|
2014-02-25 11:05:14 +01:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*
|
2019-11-05 22:30:03 +01:00
|
|
|
* @param string[] $hidden An array of IDs of hidden meta boxes.
|
2014-02-25 11:05:14 +01:00
|
|
|
* @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 21:22:27 +02:00
|
|
|
return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
|
2011-09-26 23:32:10 +02:00
|
|
|
}
|
|
|
|
|
2011-10-07 06:57:12 +02:00
|
|
|
/**
|
|
|
|
* Register and configure an admin screen option
|
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
|
|
|
* @param string $option An option name.
|
2011-10-07 07:23:33 +02:00
|
|
|
* @param mixed $args Option-dependent arguments.
|
2011-10-07 06:57:12 +02:00
|
|
|
*/
|
|
|
|
function add_screen_option( $option, $args = array() ) {
|
|
|
|
$current_screen = get_current_screen();
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $current_screen ) {
|
2011-10-01 02:24:44 +02:00
|
|
|
return;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-09-26 23:32:10 +02:00
|
|
|
|
2011-11-02 21:14:10 +01:00
|
|
|
$current_screen->add_option( $option, $args );
|
2011-10-07 06:57:12 +02:00
|
|
|
}
|
|
|
|
|
2011-09-26 23:32:10 +02:00
|
|
|
/**
|
2011-10-24 08:40:15 +02:00
|
|
|
* Get the current screen object
|
2011-09-26 23:32:10 +02:00
|
|
|
*
|
2011-10-24 08:40:15 +02:00
|
|
|
* @since 3.1.0
|
2011-09-26 23:32:10 +02:00
|
|
|
*
|
2019-08-04 04:03:55 +02:00
|
|
|
* @global WP_Screen $current_screen WordPress current screen object.
|
2015-05-29 04:06:31 +02:00
|
|
|
*
|
2016-05-23 18:34:28 +02:00
|
|
|
* @return WP_Screen|null Current screen object or null when screen not defined.
|
2011-09-26 23:32:10 +02:00
|
|
|
*/
|
|
|
|
function get_current_screen() {
|
|
|
|
global $current_screen;
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! isset( $current_screen ) ) {
|
2011-09-26 23:32:10 +02:00
|
|
|
return null;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-09-26 23:32:10 +02:00
|
|
|
|
|
|
|
return $current_screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current screen object
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-11-05 22:30:03 +01:00
|
|
|
* @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
|
|
|
|
* or an existing screen object.
|
2011-09-26 23:32:10 +02:00
|
|
|
*/
|
2011-12-14 18:36:38 +01:00
|
|
|
function set_current_screen( $hook_name = '' ) {
|
2011-10-24 20:34:08 +02:00
|
|
|
WP_Screen::get( $hook_name )->set_current_screen();
|
2011-09-26 23:32:10 +02:00
|
|
|
}
|