From d9612016f5764773aa715192a30c54c56bf8bed3 Mon Sep 17 00:00:00 2001 From: KarunyaChavan Date: Tue, 23 Jun 2026 17:48:58 +0530 Subject: [PATCH] fix: correct selected state handling for placeholder options in wp_dropdown_pages(). - Update `wp_dropdown_pages()` in `wp-includes/post-template.php` to apply the `selected()` helper to the `show_option_none` and `show_option_no_change` placeholder options. - Fixes an issue where saving and reloading the page with a placeholder option selected would cause the dropdown to reset its state. - Add unit tests in `tests/phpunit/tests/post/wpDropdownPages.php` to verify that both placeholder options correctly reflect their selected states. --- src/wp-includes/post-template.php | 4 +- tests/phpunit/tests/post/wpDropdownPages.php | 49 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 2429ab3adb776..f0fff82ad1296 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -1230,10 +1230,10 @@ function wp_dropdown_pages( $args = '' ) { $output = "\n"; diff --git a/tests/phpunit/tests/post/wpDropdownPages.php b/tests/phpunit/tests/post/wpDropdownPages.php index d838875f1d315..60dc95f99b9c4 100644 --- a/tests/phpunit/tests/post/wpDropdownPages.php +++ b/tests/phpunit/tests/post/wpDropdownPages.php @@ -219,4 +219,53 @@ public function test_wp_dropdown_pages_should_obey_class_parameter() { $this->assertMatchesRegularExpression( '/]+class=\'bar\'/', $found ); } + + /** + * Tests that the 'show_option_none' option can be selected. + * + * @ticket 65510 + */ + public function test_wp_dropdown_pages_show_option_none_is_selected() { + self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + 'show_option_none' => 'None', + 'option_none_value' => 'none_value', + 'selected' => 'none_value', + ) + ); + + $this->assertStringContainsString( '', $found ); + } + + /** + * Tests that the 'show_option_no_change' option can be selected. + * + * @ticket 65510 + */ + public function test_wp_dropdown_pages_show_option_no_change_is_selected() { + self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + 'show_option_no_change' => 'No Change', + 'selected' => '-1', + ) + ); + + $this->assertStringContainsString( '', $found ); + } }