Gets an array of data about the avatar, by the provided email, ID, user object, post object, or comment object.
This function does not check if there is actually an avatar; it simply collects the URL from the gravatar.com service. To check if the email has an avatar, you need to separately process the obtained URL. You should specify 404 in default, then get the URL and try to fetch the image from that URL using get_headers(). If the response returns 404, then there is no avatar for the email.
Array. An array of data for the obtained avatar. The array will contain all the data passed in the $args parameter as well as additional fields:
'found_avatar' - (boolean) true - if the user's avatar was found, false or empty - if not found.
'url' - (string) URL of the found avatar.
The returned parameter 'found_avatar' is always defined when the avatar image was successfully obtained, even if the parameter default=404. 'found_avatar' does not indicate whether the user has a real avatar.
Usage
get_avatar_data( $id_or_email, $args );
$id_or_email(mixed) (required)
Identifier by which the avatar will be determined. It can be:
WP_User object - will get the user's avatar by email
WP_Post object - will get the avatar of the post author
WP_Comment object - will get the avatar of the commenter
$args(array)
Parameters for the obtained avatar. By default:
Default: null (presets)
size(int)
Height and width of the avatar in pixels. Default: 96
default(string)
URL for the default image - if the avatar could not be obtained. Instead of a URL, you can specify the following values:
404 - will return 404 instead of the default image.
retro - pixel image 8bit:
monsterid - monster:
wavatar - cartoon face:
indenticon - pattern image:
mystery, 'mm' or 'mysterman' - unknown person:
blank - transparent GIF image.
gravatar_default - Gravatar logo:
Default: value of the 'avatar_default' option or 'mystery'
force_default(boolean)
Set to true if you always want to show the default image and not show avatars at all. Default: false
rating(string)
The maximum allowable rating for the displayed avatar. It can be:
G — Suitable for any audience;
PG — May contain offensive elements, usually for audiences over 13 years old;
R — Intended for adult audiences over 17 years old;
X — For even more mature audiences;
Default: value of the 'avatar_rating' option
scheme(string)
URL scheme to be used. It can be: 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. See the function set_url_scheme() for more details. Default: null
processed_args(array)
Additional options to pass. When filtering and returning data from the get_avatar_data() function, these parameters will be added to the returned array. Default: null
extra_attr(string)
HTML attributes to add to the IMG element. Not sanitized. Default: ''
Examples
1
#1 Get the avatar data of the author of the current post