From 772491d528f91a136729a58c77dbbc25b5a92d9e Mon Sep 17 00:00:00 2001 From: USERSATOSHI Date: Wed, 3 Jun 2026 19:24:45 +0530 Subject: [PATCH 1/2] fix: Prevent get_queried_object() from returning false in author queries --- src/wp-includes/class-wp-query.php | 8 +++++++- tests/phpunit/tests/query.php | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index c9bf901ae1576..196eca5afd341 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -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; diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index 40d23816d1ab6..cba53a46c1e7d 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -723,6 +723,32 @@ 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() { + $this->go_to( home_url( '?author=999999' ) ); + + $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`. From dfaa52193048bdd97dd4d6a32e719a34b1d665b9 Mon Sep 17 00:00:00 2001 From: USERSATOSHI Date: Wed, 3 Jun 2026 19:52:59 +0530 Subject: [PATCH 2/2] test: fix the non existent test case --- tests/phpunit/tests/query.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index cba53a46c1e7d..3a91a48ab9921 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -727,7 +727,15 @@ public function test_get_queried_object_should_work_for_author_name_before_get_p * @ticket 65400 */ public function test_get_queried_object_should_return_null_when_author_id_is_non_existent() { - $this->go_to( home_url( '?author=999999' ) ); + 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() ); }