Return 404 when querying author's posts who is not a member and has no posts on the site
fixes #20601. props yoavf, nacin, SergeyBiryukov, wonderboymusic, markjaquith. git-svn-id: https://develop.svn.wordpress.org/trunk@27290 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
724ca13549
commit
1d91296b3b
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user