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
8 changes: 7 additions & 1 deletion src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4047,7 +4047,13 @@ public function get_queried_object() {
}
}

$this->queried_object = get_userdata( $this->queried_object_id );
if ( $this->queried_object_id ) {
$user = get_userdata( $this->queried_object_id );

if ( $user ) {
$this->queried_object = $user;
}
}
}

return $this->queried_object;
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/tests/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,40 @@ public function test_get_queried_object_should_work_for_author_name_before_get_p
$this->assertSame( get_queried_object_id(), $user_id );
}

/**
* @ticket 65400
*/
public function test_get_queried_object_should_return_null_when_author_id_is_non_existent() {
add_action(
'parse_query',
static function ( $query ) {
$query->is_author = true;
$query->set( 'author', 999999 );
}
);

$this->go_to( home_url( '/' ) );

$this->assertNull( get_queried_object() );
}

/**
* @ticket 65400
*/
public function test_get_queried_object_should_return_null_when_author_is_unset() {
// Trigger is_author without a valid author query var.
add_action(
'parse_query',
static function ( $query ) {
$query->is_author = true;
}
);

$this->go_to( home_url( '/' ) );

$this->assertNull( get_queried_object() );
}

/**
* Tests that the `posts_clauses` filter receives an array of clauses
* with the other `posts_*` filters applied, e.g. `posts_join_paged`.
Expand Down
Loading