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.


git-svn-id: https://develop.svn.wordpress.org/trunk@34951 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes
2015-10-08 19:06:32 +00:00
parent 7e923cc0fe
commit a6e9d49467
2 changed files with 98 additions and 11 deletions
+64 -1
View File
@@ -45,4 +45,67 @@ class Tests_Admin_includesTemplate extends WP_UnitTestCase {
$this->assertEquals('', selected(0,false,false));
$this->assertEquals('', checked(0,false,false));
}
}
public function test_add_meta_box() {
global $wp_meta_boxes;
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] );
}
public function test_remove_meta_box() {
global $wp_meta_boxes;
// Add a meta boxes to remove.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $current_screen = 'post' );
// Confirm it's there.
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes[ $current_screen ]['advanced']['default'] );
// Remove the meta box.
remove_meta_box( 'testbox1', $current_screen, 'advanced' );
// Check that it was removed properly (The meta box should be set to false once that it has been removed)
$this->assertFalse( $wp_meta_boxes[ $current_screen ]['advanced']['default']['testbox1'] );
}
/**
* @ticket 15000
*/
public function test_add_meta_box_on_multiple_screens() {
global $wp_meta_boxes;
// Add a meta box to three different post types
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'comment', 'attachment' ) );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['comment']['advanced']['default'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['attachment']['advanced']['default'] );
}
/**
* @ticket 15000
*/
public function test_remove_meta_box_from_multiple_screens() {
global $wp_meta_boxes;
// Add a meta box to three different screens.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'comment', 'attachment' ) );
// Remove meta box from posts.
remove_meta_box( 'testbox1', 'post', 'advanced' );
// Check that we have removed the meta boxes only from posts
$this->assertFalse( $wp_meta_boxes['post']['advanced']['default']['testbox1'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['comment']['advanced']['default'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['attachment']['advanced']['default'] );
// Remove the meta box from the other screens.
remove_meta_box( 'testbox1', array( 'comment', 'attachment' ), 'advanced' );
$this->assertFalse( $wp_meta_boxes['comment']['advanced']['default']['testbox1'] );
$this->assertFalse( $wp_meta_boxes['attachment']['advanced']['default']['testbox1'] );
}
}