diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 228691d26d12b..e4533e875741f 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -1062,6 +1062,11 @@ public function parse_query( $query = '' ) { unset( $_query['pagename'] ); } + // Ignore an empty post name query variable. + if ( isset( $_query['name'] ) && '' === $_query['name'] ) { + unset( $_query['name'] ); + } + unset( $_query['embed'] ); if ( empty( $_query ) || ! array_diff( array_keys( $_query ), array( 'preview', 'page', 'paged', 'cpage' ) ) ) { diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 4b473178897ae..a58b892b8f168 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -72,6 +72,37 @@ public function test_page_on_front() { delete_option( 'page_for_posts' ); } + /** + * Tests that an empty name query variable does not override the static front page. + * + * @ticket 56312 + */ + public function test_page_on_front_with_empty_name_query_var() { + $page_on_front = self::factory()->post->create( + array( + 'post_type' => 'page', + ) + ); + + $page_for_posts = self::factory()->post->create( + array( + 'post_type' => 'page', + ) + ); + + update_option( 'show_on_front', 'page' ); + update_option( 'page_on_front', $page_on_front ); + update_option( 'page_for_posts', $page_for_posts ); + + $this->go_to( '/?name' ); + + $this->assertQueryTrue( 'is_front_page', 'is_page', 'is_singular' ); + + update_option( 'show_on_front', 'posts' ); + delete_option( 'page_on_front' ); + delete_option( 'page_for_posts' ); + } + public function test_404() { $this->go_to( '/notapage' ); $this->assertQueryTrue( 'is_404' );