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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47777 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-05-09 12:24:31 +00:00
parent e6547ba815
commit efb6e805da
2 changed files with 34 additions and 12 deletions

View File

@@ -57,7 +57,7 @@ class Tests_Admin_includesTemplate extends WP_UnitTestCase {
public function test_remove_meta_box() {
global $wp_meta_boxes;
// Add a meta boxes to remove.
// Add a meta box to remove.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $current_screen = 'post' );
// Confirm it's there.
@@ -108,6 +108,25 @@ class Tests_Admin_includesTemplate extends WP_UnitTestCase {
$this->assertFalse( $wp_meta_boxes['attachment']['advanced']['default']['testbox1'] );
}
/**
* @ticket 50019
*/
public function test_add_meta_box_with_previously_removed_box_and_sorted_priority() {
global $wp_meta_boxes;
// Add a meta box to remove.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $current_screen = 'post' );
// Remove the meta box.
remove_meta_box( 'testbox1', $current_screen, 'advanced' );
// Attempt to re-add the meta box with the 'sorted' priority.
add_meta_box( 'testbox1', null, null, $current_screen, 'advanced', 'sorted' );
// Check that the meta box was not re-added.
$this->assertFalse( $wp_meta_boxes[ $current_screen ]['advanced']['default']['testbox1'] );
}
/**
* Test calling get_settings_errors() with variations on where it gets errors from.
*