Make WordPress Core

Changeset 45632


Ignore:
Timestamp:
07/14/2019 02:34:02 PM (5 years ago)
Author:
SergeyBiryukov
Message:

REST API: Allow rest_get_avatar_urls() to accept full user, post, or comment objects, rather than just an email address, to provide better flexibility for alternative avatar data.

Since the function uses get_avatar_url() internally, which already supports it, this should not have any backward compatibility concerns.

Props donmhico, dshanske, pputzer, joehoyle, TimothyBlynJacobs.
Fixes #40030.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

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

    r45566 r45632  
    10861086
    10871087/**
    1088  * Retrieves the avatar urls in various sizes based on a given email address.
     1088 * Retrieves the avatar urls in various sizes.
    10891089 *
    10901090 * @since 4.7.0
     
    10921092 * @see get_avatar_url()
    10931093 *
    1094  * @param string $email Email address.
     1094 * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash,
     1095 *                           user email, WP_User object, WP_Post object, or WP_Comment object.
    10951096 * @return array $urls Gravatar url for each size.
    10961097 */
    1097 function rest_get_avatar_urls( $email ) {
     1098function rest_get_avatar_urls( $id_or_email ) {
    10981099    $avatar_sizes = rest_get_avatar_sizes();
    10991100
    11001101    $urls = array();
    11011102    foreach ( $avatar_sizes as $size ) {
    1102         $urls[ $size ] = get_avatar_url( $email, array( 'size' => $size ) );
     1103        $urls[ $size ] = get_avatar_url( $id_or_email, array( 'size' => $size ) );
    11031104    }
    11041105
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r45267 r45632  
    950950
    951951        if ( in_array( 'author_avatar_urls', $fields, true ) ) {
    952             $data['author_avatar_urls'] = rest_get_avatar_urls( $comment->comment_author_email );
     952            $data['author_avatar_urls'] = rest_get_avatar_urls( $comment );
    953953        }
    954954
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r45590 r45632  
    939939
    940940        if ( in_array( 'avatar_urls', $fields, true ) ) {
    941             $data['avatar_urls'] = rest_get_avatar_urls( $user->user_email );
     941            $data['avatar_urls'] = rest_get_avatar_urls( $user );
    942942        }
    943943
Note: See TracChangeset for help on using the changeset viewer.