Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) ) {
Expand Down
31 changes: 31 additions & 0 deletions tests/phpunit/tests/query/conditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
Loading