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
|
|
|
|
*
|
2011-10-24 02:40:15 -04:00
|
|
|
* @param string|WP_Screen $screen The screen you want the headers for
|
2019-10-26 17:09:04 -04:00
|
|
|
* @return string[] The column header labels keyed by column ID.
|
2011-09-26 17:32:10 -04:00
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
function get_column_headers( $screen ) {
|
2021-05-09 16:27:02 -04:00
|
|
|
static $column_headers = array();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-09-26 17:32:10 -04:00
|
|
|
$screen = convert_to_screen( $screen );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
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
|
|
|
|
*
|
2019-10-26 17:09:04 -04:00
|
|
|
* @param string[] $columns The column header labels keyed by column ID.
|
2014-02-25 05:05:14 -05:00
|
|
|
*/
|
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
|
2019-12-07 08:23:01 -05:00
|
|
|
* @return string[] Array of IDs of hidden columns.
|
2011-09-26 17:32:10 -04:00
|
|
|
*/
|
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
|
|
|
|
*
|
2019-12-07 08:23:01 -05:00
|
|
|
* @param string[] $hidden Array of IDs of columns hidden by default.
|
2015-08-21 11:32:29 -04:00
|
|
|
* @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
|
|
|
*
|
2019-12-07 08:23:01 -05:00
|
|
|
* @param string[] $hidden Array of IDs 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;
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-10-24 02:40:15 -04:00
|
|
|
$screen = convert_to_screen( $screen );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-10-07 00:57:12 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
|
2011-10-07 00:57:12 -04:00
|
|
|
return;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-10-07 00:57:12 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$hidden = get_hidden_meta_boxes( $screen );
|
2011-10-07 00:57:12 -04:00
|
|
|
|
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;
|
|
|
|
}
|
2021-05-09 16:27:02 -04:00
|
|
|
|
2015-06-08 08:35:26 -04:00
|
|
|
foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
|
2021-05-09 16:27:02 -04:00
|
|
|
if ( false === $box || ! $box['title'] ) {
|
2011-10-07 00:57:12 -04:00
|
|
|
continue;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2021-05-09 16:27:02 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Submit box cannot be hidden.
|
2020-05-16 14:42:12 -04:00
|
|
|
if ( 'submitdiv' === $box['id'] || 'linksubmitdiv' === $box['id'] ) {
|
2011-10-07 00:57:12 -04:00
|
|
|
continue;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-07-05 11:22:29 -04:00
|
|
|
|
|
|
|
$widget_title = $box['title'];
|
|
|
|
|
2016-07-07 12:39:29 -04:00
|
|
|
if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
|
2016-07-05 11:22:29 -04:00
|
|
|
$widget_title = $box['args']['__widget_basename'];
|
|
|
|
}
|
|
|
|
|
2020-04-09 11:43:10 -04:00
|
|
|
$is_hidden = in_array( $box['id'], $hidden, true );
|
|
|
|
|
2016-07-05 11:22:29 -04:00
|
|
|
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'] ),
|
2020-04-09 11:43:10 -04:00
|
|
|
checked( $is_hidden, false, false ),
|
2016-07-05 11:22:29 -04:00
|
|
|
$widget_title
|
|
|
|
);
|
2011-10-07 00:57:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 17:32:10 -04:00
|
|
|
/**
|
2019-11-05 16:30:03 -05:00
|
|
|
* Gets an array of IDs of hidden meta boxes.
|
2011-09-26 17:32:10 -04:00
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
2011-10-24 02:40:15 -04:00
|
|
|
* @param string|WP_Screen $screen Screen identifier
|
2019-11-05 16:30:03 -05:00
|
|
|
* @return string[] IDs of hidden meta boxes.
|
2011-09-26 17:32:10 -04:00
|
|
|
*/
|
2011-10-07 00:57:12 -04:00
|
|
|
function get_hidden_meta_boxes( $screen ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( is_string( $screen ) ) {
|
2011-09-26 17:32:10 -04:00
|
|
|
$screen = convert_to_screen( $screen );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-09-26 17:32:10 -04:00
|
|
|
|
|
|
|
$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
|
|
|
|
|
2011-10-23 15:22:27 -04:00
|
|
|
$use_defaults = ! is_array( $hidden );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Hide slug boxes by default.
|
2011-10-23 15:22:27 -04:00
|
|
|
if ( $use_defaults ) {
|
|
|
|
$hidden = array();
|
2021-05-09 16:27:02 -04:00
|
|
|
|
2020-05-16 14:42:12 -04:00
|
|
|
if ( 'post' === $screen->base ) {
|
|
|
|
if ( in_array( $screen->post_type, array( 'post', 'page', 'attachment' ), true ) ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' );
|
|
|
|
} else {
|
2011-10-23 15:22:27 -04:00
|
|
|
$hidden = array( 'slugdiv' );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-10-23 15:22:27 -04:00
|
|
|
}
|
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
|
|
|
|
*
|
2019-11-05 16:30:03 -05:00
|
|
|
* @param string[] $hidden An array of IDs of meta boxes hidden by default.
|
2014-02-25 05:05:14 -05:00
|
|
|
* @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
|
|
|
|
*
|
2019-11-05 16:30:03 -05:00
|
|
|
* @param string[] $hidden An array of IDs of hidden meta boxes.
|
2014-02-25 05:05:14 -05: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 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.
|
2020-07-22 20:52:05 -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();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $current_screen ) {
|
2011-09-30 20:24:44 -04:00
|
|
|
return;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
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
|
|
|
*
|
2019-08-03 22:03:55 -04:00
|
|
|
* @global WP_Screen $current_screen WordPress current screen object.
|
2015-05-28 22:06:31 -04:00
|
|
|
*
|
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;
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $current_screen ) ) {
|
2011-09-26 17:32:10 -04:00
|
|
|
return null;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-09-26 17:32:10 -04:00
|
|
|
|
|
|
|
return $current_screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current screen object
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-11-05 16:30:03 -05: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 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
|
|
|
}
|