Make WordPress Core

Changeset 28362


Ignore:
Timestamp:
05/11/2014 12:25:29 AM (10 years ago)
Author:
wonderboymusic
Message:

In get_the_author_posts(), if there is no current $post, return 0 and bail.

Props krogsgard, aaroncampbell.
Fixes #27998.

Location:
trunk
Files:
2 edited

Legend:

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

    r28265 r28362  
    207207 */
    208208function get_the_author_posts() {
    209     return count_user_posts( get_post()->post_author );
     209    $post = get_post();
     210    if ( ! $post ) {
     211        return 0;
     212    }
     213    return count_user_posts( $post->post_author );
    210214}
    211215
  • trunk/tests/phpunit/tests/user/author.php

    r25002 r28362  
    7676        $this->assertEquals( '', get_the_author_meta( 'does_not_exist' ) );
    7777    }
     78
     79    function test_get_the_author_posts() {
     80        // Test with no global post, result should be 0 because no author is found
     81        $this->assertEquals( 0, get_the_author_posts() );
     82        $GLOBALS['post'] = $this->post_id;
     83        $this->assertEquals( 1, get_the_author_posts() );
     84    }
    7885}
Note: See TracChangeset for help on using the changeset viewer.