Administration: Avoid a PHP 7.4 notice in `add_meta_box()` when attempting to re-add a previously removed box.

The logic for skipping previously removed meta boxes with the `core` priority should also apply to the `sorted` priority that is used when the boxes were manually reordered.

Add a unit test.

Props coolmann, franzarmas, SergeyBiryukov.
Fixes #50019.
Built from https://develop.svn.wordpress.org/trunk@47777


git-svn-id: http://core.svn.wordpress.org/trunk@47553 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-05-09 12:26:12 +00:00
parent 928ce10da0
commit 5511b43e2c
2 changed files with 15 additions and 12 deletions

View File

@ -1063,16 +1063,18 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan
continue;
}
// If a core box was previously added or removed by a plugin, don't add.
if ( 'core' === $priority ) {
// If core box previously deleted, don't add.
if ( false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) {
// If a core box was previously removed, don't add.
if ( ( 'core' === $priority || 'sorted' === $priority )
&& false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]
) {
return;
}
// If a core box was previously added by a plugin, don't add.
if ( 'core' === $priority ) {
/*
* If box was added with default priority, give it core priority to
* maintain sort order.
* If the box was added with default priority, give it core priority
* to maintain sort order.
*/
if ( 'default' === $a_priority ) {
$wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ];
@ -1080,6 +1082,7 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan
}
return;
}
// If no priority given and ID already present, use existing priority.
if ( empty( $priority ) ) {
$priority = $a_priority;

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-47776';
$wp_version = '5.5-alpha-47777';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.