diff --git a/lib/meta-box-partial-page.php b/lib/meta-box-partial-page.php index 901aea951919bd..6a55a062ba0f8c 100644 --- a/lib/meta-box-partial-page.php +++ b/lib/meta-box-partial-page.php @@ -206,6 +206,9 @@ function gutenberg_intercept_meta_box_render() { foreach ( $contexts as $context => $priorities ) { foreach ( $priorities as $priority => $boxes ) { foreach ( $boxes as $id => $box ) { + if ( ! is_array( $box ) ) { + continue; + } if ( ! is_array( $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['args'] ) ) { $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['args'] = array(); } diff --git a/phpunit/class-meta-box-test.php b/phpunit/class-meta-box-test.php index cf2c767a8bda9a..c62ef1ab1940e1 100644 --- a/phpunit/class-meta-box-test.php +++ b/phpunit/class-meta-box-test.php @@ -235,4 +235,18 @@ public function test_gutenberg_filter_meta_boxes_for_taxonomies() { $this->assertEquals( $expected, $actual ); } + + /** + * Test that a removed meta box remains empty after gutenberg_intercept_meta_box_render() fires. + */ + public function test_gutenberg_intercept_meta_box_render_skips_empty_boxes() { + global $wp_meta_boxes; + + add_meta_box( 'test-intercept-box', 'Test Intercept box', '__return_empty_string', 'post', 'side', 'default' ); + remove_meta_box( 'test-intercept-box', 'post', 'side' ); + + gutenberg_intercept_meta_box_render(); + + $this->assertFalse( $wp_meta_boxes['post']['side']['default']['test-intercept-box'] ); + } }