From bd149da1d7d951ab5892443f0d9a9ba6264224b0 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Wed, 6 May 2026 14:06:35 +0530 Subject: [PATCH 1/5] enqueue 'postbox' script if meta boxes are present --- src/wp-admin/includes/class-wp-screen.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php index 227fda90c6273..0d54552c5e1ba 100644 --- a/src/wp-admin/includes/class-wp-screen.php +++ b/src/wp-admin/includes/class-wp-screen.php @@ -1001,6 +1001,14 @@ public function show_screen_options() { $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' ); + /* + * @since 7.0.0 + * @see https://core.trac.wordpress.org/ticket/17704 + */ + if ( ! empty( $wp_meta_boxes[ $this->id ] ) ) { + wp_enqueue_script( 'postbox' ); + } + $this->_screen_settings = ''; if ( 'post' === $this->base ) { From d7c87c5fccebc4d401c6d2def1b4f8652e223746 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Wed, 6 May 2026 14:06:49 +0530 Subject: [PATCH 2/5] add initialization for postbox toggles on page load --- src/js/_enqueues/admin/postbox.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/js/_enqueues/admin/postbox.js b/src/js/_enqueues/admin/postbox.js index b6d1b6569dc84..c7b159fbec918 100644 --- a/src/js/_enqueues/admin/postbox.js +++ b/src/js/_enqueues/admin/postbox.js @@ -657,4 +657,14 @@ pbhide : false }; + /* + * @since 7.0.0 + * @see https://core.trac.wordpress.org/ticket/17704 + */ + $( function() { + if ( typeof window.pagenow !== 'undefined' && ! postboxes.page && $( '.postbox' ).length ) { + postboxes.add_postbox_toggles( window.pagenow ); + } + } ); + }(jQuery)); From 8beabbfba2a6cee4e889967de282b964e1648330 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Thu, 7 May 2026 13:51:32 +0530 Subject: [PATCH 3/5] Add test to verify postbox script is enqueued when meta boxes exist --- tests/phpunit/tests/admin/includesScreen.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index 26186391f261d..5a8277e278b93 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -630,4 +630,23 @@ public function test_is_block_editor( $hook, $filter, $expected ) { $this->assertSame( $expected, $screen->is_block_editor ); } + + public function test_show_screen_options_enqueues_postbox_script_when_meta_boxes_exist() { + global $wp_meta_boxes; + + set_current_screen( 'tools.php' ); + $screen = get_current_screen(); + + add_meta_box( 'testbox-17704', 'Test Meta Box', '__return_false', $screen ); + + $screen->show_screen_options(); + + $this->assertTrue( + wp_script_is( 'postbox', 'enqueued' ), + 'The postbox script should be enqueued when meta boxes are registered for the screen.' + ); + + remove_meta_box( 'testbox-17704', $screen, 'advanced' ); + wp_dequeue_script( 'postbox' ); + } } From dc958230cdf905eb67fe201925b13140c2fadb6f Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Thu, 7 May 2026 13:51:48 +0530 Subject: [PATCH 4/5] Add test to ensure postbox script is not enqueued when no meta boxes are present --- tests/phpunit/tests/admin/includesScreen.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index 5a8277e278b93..2adc35f2e32c2 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -649,4 +649,20 @@ public function test_show_screen_options_enqueues_postbox_script_when_meta_boxes remove_meta_box( 'testbox-17704', $screen, 'advanced' ); wp_dequeue_script( 'postbox' ); } + + public function test_show_screen_options_does_not_enqueue_postbox_script_when_no_meta_boxes() { + global $wp_meta_boxes; + + set_current_screen( 'options-general.php' ); + $screen = get_current_screen(); + + unset( $wp_meta_boxes[ $screen->id ] ); + + $screen->show_screen_options(); + + $this->assertFalse( + wp_script_is( 'postbox', 'enqueued' ), + 'The postbox script should not be enqueued when no meta boxes are registered for the screen.' + ); + } } From 45fbd9611076cfd48edd0e4a9f5fbbcc7c8d8efb Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Thu, 7 May 2026 13:52:15 +0530 Subject: [PATCH 5/5] Add test doc block --- tests/phpunit/tests/admin/includesScreen.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index 2adc35f2e32c2..d73e25b0a9a4d 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -631,6 +631,9 @@ public function test_is_block_editor( $hook, $filter, $expected ) { $this->assertSame( $expected, $screen->is_block_editor ); } + /** + * @ticket 17704 + */ public function test_show_screen_options_enqueues_postbox_script_when_meta_boxes_exist() { global $wp_meta_boxes; @@ -650,6 +653,9 @@ public function test_show_screen_options_enqueues_postbox_script_when_meta_boxes wp_dequeue_script( 'postbox' ); } + /** + * @ticket 17704 + */ public function test_show_screen_options_does_not_enqueue_postbox_script_when_no_meta_boxes() { global $wp_meta_boxes;