Make WordPress Core

Ticket #51794: 51794.diff

File 51794.diff, 1.3 KB (added by trepmal, 5 years ago)

hacky patch

  • src/wp-includes/class-wp-query.php

     
    915915                        }
    916916
    917917                        if ( '' !== $qv['author_name'] ) {
    918                                 $this->is_author = true;
     918                                if ( get_user_by( 'slug', $qv['author_name'] ) ) {
     919                                        $this->is_author = true;
     920                                } else {
     921                                        $qv['error'] = '404';
     922                                        $qv['author'] = $qv['author_name'];
     923                                }
    919924                        }
    920925
    921926                        if ( ! empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
  • tests/phpunit/tests/query.php

     
    696696                $this->assertSame( 'tax1', get_query_var( 'taxonomy' ) );
    697697                $this->assertSame( 'term1', get_query_var( 'term' ) );
    698698        }
     699
     700        /**
     701         * @ticket 51794
     702         */
     703        public function test_nonexistent_author_query_should_not_return_results() {
     704                $p1 = self::factory()->post->create( array( 'post_author' => 0 ) );
     705
     706                $url = add_query_arg(
     707                        array(
     708                                'author_name' => 'thisuserdoesnotexist',
     709                        ),
     710                        '/'
     711                );
     712
     713                $this->go_to( $url );
     714
     715                $this->assertTrue( $GLOBALS['wp_query']->is_404() );
     716        }
     717
    699718}