Administration: Add the ability to pass an array of screen IDs to `add_meta_box()` and `remove_meta_box()`.
The `$screen` parameter in both functions can now accept a single screen ID, `WP_Screen` object, or an array of screen IDs. Adds tests. Props coffee2code, iamfriendly, madalinungureanu, mordauk, igmoweb, meloniq, DrewAPicture. See #15000. Built from https://develop.svn.wordpress.org/trunk@34951 git-svn-id: http://core.svn.wordpress.org/trunk@34916 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b5be742e1f
commit
6e4268e6fa
|
@ -847,9 +847,10 @@ function wp_import_upload_form( $action ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a meta box to an edit form.
|
||||
* Adds a meta box to one or more screens.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs.
|
||||
*
|
||||
* @global array $wp_meta_boxes
|
||||
*
|
||||
|
@ -857,8 +858,10 @@ function wp_import_upload_form( $action ) {
|
|||
* @param string $title Title of the meta box.
|
||||
* @param callable $callback Function that fills the box with the desired content.
|
||||
* The function should echo its output.
|
||||
* @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post
|
||||
* type, 'link', or 'comment'). Default is the current screen.
|
||||
* @param string|array|WP_Screen $screen Optional. The screen or screens on which to show the box
|
||||
* (such as a post type, 'link', or 'comment'). Accepts a single
|
||||
* screen ID, WP_Screen object, or array of screen IDs. Default
|
||||
* is the current screen.
|
||||
* @param string $context Optional. The context within the screen where the boxes
|
||||
* should display. Available contexts vary from screen to
|
||||
* screen. Post edit screen contexts include 'normal', 'side',
|
||||
|
@ -874,10 +877,19 @@ function wp_import_upload_form( $action ) {
|
|||
function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
if ( empty( $screen ) )
|
||||
if ( empty( $screen ) ) {
|
||||
$screen = get_current_screen();
|
||||
elseif ( is_string( $screen ) )
|
||||
} elseif ( is_string( $screen ) ) {
|
||||
$screen = convert_to_screen( $screen );
|
||||
} elseif ( is_array( $screen ) ) {
|
||||
foreach ( $screen as $single_screen ) {
|
||||
add_meta_box( $id, $title, $callback, $single_screen, $context, $priority, $callback_args );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! isset( $screen->id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page = $screen->id;
|
||||
|
||||
|
@ -1011,23 +1023,35 @@ function do_meta_boxes( $screen, $context, $object ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove a meta box from an edit form.
|
||||
* Removes a meta box from one or more screens.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs.
|
||||
*
|
||||
* @global array $wp_meta_boxes
|
||||
*
|
||||
* @param string $id String for use in the 'id' attribute of tags.
|
||||
* @param string|object $screen The screen on which to show the box (post, page, link).
|
||||
* @param string|array|WP_Screen $screen The screen or screens on which the meta box is shown (such as a
|
||||
* post type, 'link', or 'comment'). Accepts a single screen ID,
|
||||
* WP_Screen object, or array of screen IDs.
|
||||
* @param string $context The context within the page where the boxes should show ('normal', 'advanced').
|
||||
*/
|
||||
function remove_meta_box( $id, $screen, $context ) {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
if ( empty( $screen ) )
|
||||
if ( empty( $screen ) ) {
|
||||
$screen = get_current_screen();
|
||||
elseif ( is_string( $screen ) )
|
||||
} elseif ( is_string( $screen ) ) {
|
||||
$screen = convert_to_screen( $screen );
|
||||
} elseif ( is_array( $screen ) ) {
|
||||
foreach ( $screen as $single_screen ) {
|
||||
remove_meta_box( $id, $single_screen, $context );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! isset( $screen->id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page = $screen->id;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-alpha-34950';
|
||||
$wp_version = '4.4-alpha-34951';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue