diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php index 2fe76fc8b7..78259defb5 100644 --- a/src/wp-includes/class-wp.php +++ b/src/wp-includes/class-wp.php @@ -568,8 +568,15 @@ class WP { // We will 404 for paged queries, as no posts were found. if ( ! is_paged() ) { + // Don't 404 for authors without posts as long as they matched an author on this site. + $author = get_query_var( 'author' ); + if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) { + status_header( 200 ); + return; + } + // Don't 404 for these queries if they matched an object. - if ( ( is_tag() || is_category() || is_tax() || is_author() || is_post_type_archive() ) && $wp_query->get_queried_object() ) { + if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) { status_header( 200 ); return; } diff --git a/tests/phpunit/tests/ms.php b/tests/phpunit/tests/ms.php index bcd597965b..f307ff735d 100644 --- a/tests/phpunit/tests/ms.php +++ b/tests/phpunit/tests/ms.php @@ -1219,6 +1219,48 @@ class Tests_MS extends WP_UnitTestCase { $this->assertEquals( $ids['wordpress.net/'], get_network_by_path( 'site1.wordpress.net', '/three/' )->id ); } + + /** + * @ticket 20601 + */ + function test_user_member_of_blog() { + global $wp_rewrite; + + $this->factory->blog->create(); + $user_id = $this->factory->user->create(); + $this->factory->blog->create( array( 'user_id' => $user_id ) ); + + $blogs = get_blogs_of_user( $user_id ); + $this->assertCount( 2, $blogs ); + $first = reset( $blogs )->userblog_id; + remove_user_from_blog( $user_id, $first ); + + $blogs = get_blogs_of_user( $user_id ); + $second = reset( $blogs )->userblog_id; + $this->assertCount( 1, $blogs ); + + switch_to_blog( $first ); + $wp_rewrite->init(); + + $this->go_to( get_author_posts_url( $user_id ) ); + $this->assertQueryTrue( 'is_404' ); + + switch_to_blog( $second ); + $wp_rewrite->init(); + + $this->go_to( get_author_posts_url( $user_id ) ); + $this->assertQueryTrue( 'is_author', 'is_archive' ); + + add_user_to_blog( $first, $user_id, 'administrator' ); + $blogs = get_blogs_of_user( $user_id ); + $this->assertCount( 2, $blogs ); + + switch_to_blog( $first ); + $wp_rewrite->init(); + + $this->go_to( get_author_posts_url( $user_id ) ); + $this->assertQueryTrue( 'is_author', 'is_archive' ); + } } endif;