Make WordPress Core

Changeset 27290


Ignore:
Timestamp:
02/26/2014 06:11:36 PM (10 years ago)
Author:
markjaquith
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp.php

    r26644 r27290  
    569569        if ( ! is_paged() ) {
    570570
     571            // Don't 404 for authors without posts as long as they matched an author on this site.
     572            $author = get_query_var( 'author' );
     573            if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) {
     574                status_header( 200 );
     575                return;
     576            }
     577
    571578            // Don't 404 for these queries if they matched an object.
    572             if ( ( is_tag() || is_category() || is_tax() || is_author() || is_post_type_archive() ) && $wp_query->get_queried_object() ) {
     579            if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) {
    573580                status_header( 200 );
    574581                return;
  • trunk/tests/phpunit/tests/ms.php

    r27178 r27290  
    12201220            get_network_by_path( 'site1.wordpress.net', '/three/' )->id );
    12211221    }
     1222
     1223    /**
     1224     * @ticket 20601
     1225     */
     1226    function test_user_member_of_blog() {
     1227        global $wp_rewrite;
     1228
     1229        $this->factory->blog->create();
     1230        $user_id = $this->factory->user->create();
     1231        $this->factory->blog->create( array( 'user_id' => $user_id ) );
     1232
     1233        $blogs = get_blogs_of_user( $user_id );
     1234        $this->assertCount( 2, $blogs );
     1235        $first = reset( $blogs )->userblog_id;
     1236        remove_user_from_blog( $user_id, $first );
     1237
     1238        $blogs = get_blogs_of_user( $user_id );
     1239        $second = reset( $blogs )->userblog_id;
     1240        $this->assertCount( 1, $blogs );
     1241
     1242        switch_to_blog( $first );
     1243        $wp_rewrite->init();
     1244
     1245        $this->go_to( get_author_posts_url( $user_id ) );
     1246        $this->assertQueryTrue( 'is_404' );
     1247
     1248        switch_to_blog( $second );
     1249        $wp_rewrite->init();
     1250
     1251        $this->go_to( get_author_posts_url( $user_id ) );
     1252        $this->assertQueryTrue( 'is_author', 'is_archive' );
     1253
     1254        add_user_to_blog( $first, $user_id, 'administrator' );
     1255        $blogs = get_blogs_of_user( $user_id );
     1256        $this->assertCount( 2, $blogs );
     1257
     1258        switch_to_blog( $first );
     1259        $wp_rewrite->init();
     1260
     1261        $this->go_to( get_author_posts_url( $user_id ) );
     1262        $this->assertQueryTrue( 'is_author', 'is_archive' );
     1263    }
    12221264}
    12231265
Note: See TracChangeset for help on using the changeset viewer.