From ea3844074ea85a8380e86b83524d8afb57bb82af Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 23 Jan 2026 14:14:47 -0800 Subject: [PATCH 1/3] https://core.trac.wordpress.org/attachment/ticket/64507/author_name_string.patch Co-authored-by: leedxw --- src/wp-includes/class-wp-query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 8edcf80b54400..a62093bb88c0c 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -2414,7 +2414,7 @@ public function get_posts() { // Author stuff for nice URLs. - if ( '' !== $query_vars['author_name'] ) { + if ( '' !== $query_vars['author_name'] && is_string( $query_vars['author_name'] ) ) { if ( str_contains( $query_vars['author_name'], '/' ) ) { $query_vars['author_name'] = explode( '/', $query_vars['author_name'] ); if ( $query_vars['author_name'][ count( $query_vars['author_name'] ) - 1 ] ) { @@ -4035,7 +4035,7 @@ public function get_queried_object() { $this->queried_object_id = (int) $this->post->ID; } elseif ( $this->is_author ) { $author = (int) $this->get( 'author' ); - $author_name = $this->get( 'author_name' ); + $author_name = ( is_string( $this->get( 'author_name' ) ) ) ? $this->get( 'author_name' ) : false; if ( $author ) { $this->queried_object_id = $author; From 1802279322a0b1475950caf6fe8a6a1302ddb077 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 23 Jan 2026 20:37:16 -0800 Subject: [PATCH 2/3] Refine author_name logic --- src/wp-includes/class-wp-query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index a62093bb88c0c..f4c57a9fdd491 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -4035,11 +4035,11 @@ public function get_queried_object() { $this->queried_object_id = (int) $this->post->ID; } elseif ( $this->is_author ) { $author = (int) $this->get( 'author' ); - $author_name = ( is_string( $this->get( 'author_name' ) ) ) ? $this->get( 'author_name' ) : false; + $author_name = $this->get( 'author_name' ); if ( $author ) { $this->queried_object_id = $author; - } elseif ( $author_name ) { + } elseif ( is_string( $author_name ) && '' !== $author_name ) { $user = get_user_by( 'slug', $author_name ); if ( $user ) { From 40069cb7841dfeba97f2f739181dcbd338c08a52 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 23 Jan 2026 20:45:05 -0800 Subject: [PATCH 3/3] Add type checking for other query vars in get_queried_object() and add helper method --- src/wp-includes/class-wp-query.php | 32 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index f4c57a9fdd491..3d12336a619f1 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -2414,7 +2414,7 @@ public function get_posts() { // Author stuff for nice URLs. - if ( '' !== $query_vars['author_name'] && is_string( $query_vars['author_name'] ) ) { + if ( $this->is_non_empty_string( $query_vars['author_name'] ) ) { if ( str_contains( $query_vars['author_name'], '/' ) ) { $query_vars['author_name'] = explode( '/', $query_vars['author_name'] ); if ( $query_vars['author_name'][ count( $query_vars['author_name'] ) - 1 ] ) { @@ -3978,18 +3978,18 @@ public function get_queried_object() { $cat = $this->get( 'cat' ); $category_name = $this->get( 'category_name' ); - if ( $cat ) { + if ( $this->is_non_empty_string( $cat ) ) { $term = get_term( $cat, 'category' ); - } elseif ( $category_name ) { + } elseif ( $this->is_non_empty_string( $category_name ) ) { $term = get_term_by( 'slug', $category_name, 'category' ); } } elseif ( $this->is_tag ) { $tag_id = $this->get( 'tag_id' ); $tag = $this->get( 'tag' ); - if ( $tag_id ) { + if ( $this->is_non_empty_string( $tag_id ) ) { $term = get_term( $tag_id, 'post_tag' ); - } elseif ( $tag ) { + } elseif ( $this->is_non_empty_string( $tag ) ) { $term = get_term_by( 'slug', $tag, 'post_tag' ); } } else { @@ -4021,7 +4021,7 @@ public function get_queried_object() { $post_type = $this->get( 'post_type' ); if ( is_array( $post_type ) ) { - $post_type = reset( $post_type ); + $post_type = array_first( $post_type ); } $this->queried_object = get_post_type_object( $post_type ); @@ -4034,12 +4034,12 @@ public function get_queried_object() { $this->queried_object = $this->post; $this->queried_object_id = (int) $this->post->ID; } elseif ( $this->is_author ) { - $author = (int) $this->get( 'author' ); + $author = $this->get( 'author' ); $author_name = $this->get( 'author_name' ); - if ( $author ) { - $this->queried_object_id = $author; - } elseif ( is_string( $author_name ) && '' !== $author_name ) { + if ( $this->is_non_empty_string( $author ) ) { + $this->queried_object_id = (int) $author; + } elseif ( $this->is_non_empty_string( $author_name ) ) { $user = get_user_by( 'slug', $author_name ); if ( $user ) { @@ -4053,6 +4053,18 @@ public function get_queried_object() { return $this->queried_object; } + /** + * Determines whether the provided value is a non-empty string. + * + * @since n.e.x.t + * + * @param mixed $value Value. + * @return bool + */ + private function is_non_empty_string( $value ): bool { + return is_string( $value ) && '' !== $value; + } + /** * Retrieves the ID of the currently queried object. *