Make WordPress Core

Ticket #20529: 20529.patch

File 20529.patch, 1.3 KB (added by johnjamesjacoby, 13 years ago)
  • wp-includes/author-template.php

     
    8989
    9090/**
    9191 * Retrieve the requested data of the author of the current post.
     92 *
    9293 * @link http://codex.wordpress.org/Template_Tags/the_author_meta
    9394 * @since 2.8.0
    94  * @uses $authordata The current author's DB object (if $user_id not specified).
     95 * @global $authordata The current author's DB object (if $user_id not specified).
    9596 * @param string $field selects the field of the users record.
    9697 * @param int $user_id Optional. User ID.
    9798 * @return string The author's field from the current author's DB object.
    9899 */
    99100function get_the_author_meta( $field = '', $user_id = false ) {
    100         if ( ! $user_id ) {
    101                 global $authordata;
    102                 $user_id = $authordata->ID;
     101        if ( ! is_int( $user_id ) ) {
     102                global $authordata, $post;
     103
     104                // Author data might not be available yet
     105                if ( empty( $authordata ) ) {
     106
     107                        // Post might have been manipulated
     108                        if ( empty( $post->post_author ) ) {
     109                                wp_reset_postdata();
     110                        }
     111
     112                        // Set author data according to the post author
     113                        $authordata = get_userdata( $post->post_author );
     114                }
     115
     116                // Set the user ID if we have one
     117                if ( ! empty( $authordata->ID ) ) {
     118                        $user_id = $authordata->ID;
     119                }
    103120        } else {
    104121                $authordata = get_userdata( $user_id );
    105122        }