Make WordPress Core

Ticket #44183: 44183.3.diff

File 44183.3.diff, 1.8 KB (added by johnbillion, 5 years ago)
  • src/wp-includes/class-wp.php

     
    597597                        $GLOBALS['single'] = 1;
    598598                }
    599599
    600                 if ( $wp_query->is_author() && isset( $wp_query->post ) ) {
    601                         $GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
     600                if ( $wp_query->is_author() ) {
     601                        $GLOBALS['authordata'] = get_userdata( get_queried_object_id() );
    602602                }
    603603        }
    604604
  • tests/phpunit/tests/general/template.php

     
    589589                        array( 0, false ),
    590590                );
    591591        }
     592
     593        /**
     594         * @ticket 44183
     595         */
     596        function test_get_the_archive_title_is_correct_for_author_queries() {
     597                $user_with_posts = $this->factory()->user->create_and_get(
     598                        array(
     599                                'role' => 'author',
     600                        )
     601                );
     602                $user_with_no_posts = $this->factory()->user->create_and_get(
     603                        array(
     604                                'role' => 'author',
     605                        )
     606                );
     607
     608                $this->factory()->post->create( [
     609                        'post_author' => $user_with_posts->ID,
     610                ] );
     611
     612                // Simplify the assertion by removing the default archive title prefix:
     613                add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );
     614
     615                $this->go_to( get_author_posts_url( $user_with_posts->ID ) );
     616                $title_when_posts = get_the_archive_title();
     617
     618                $this->go_to( get_author_posts_url( $user_with_no_posts->ID ) );
     619                $title_when_no_posts = get_the_archive_title();
     620
     621                // Ensure the title is correct both when the user has posts and when they dont:
     622                $this->assertSame( $user_with_posts->display_name, $title_when_posts );
     623                $this->assertSame( $user_with_no_posts->display_name, $title_when_no_posts );
     624        }
    592625}