Skip to content

Commit 17e518a

Browse files
Docs: Improve documentation for get_avatar() and related functions.
Includes: * Expanding and synchronizing documentation for the `default` and `rating` arguments. * Adding `@since` entries for the `loading`, `fetchpriority`, and `decoding` arguments. * Wrapping long lines as per the documentation standards. * Fixing a typo in the `identicon` value. * Minor formatting edits for consistency. Follow-up to [31107], [45632], [47554], [53480], [56037]. See #58833. git-svn-id: https://develop.svn.wordpress.org/trunk@56767 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1a30f7d commit 17e518a

3 files changed

Lines changed: 102 additions & 55 deletions

File tree

src/wp-includes/link-template.php

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,27 +4250,37 @@ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
42504250
}
42514251
}
42524252

4253-
42544253
/**
42554254
* Retrieves the avatar URL.
42564255
*
42574256
* @since 4.2.0
42584257
*
4259-
* @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash,
4258+
* @param mixed $id_or_email The avatar to retrieve a URL for. Accepts a user ID, Gravatar MD5 hash,
42604259
* user email, WP_User object, WP_Post object, or WP_Comment object.
42614260
* @param array $args {
42624261
* Optional. Arguments to use instead of the default arguments.
42634262
*
42644263
* @type int $size Height and width of the avatar in pixels. Default 96.
4265-
* @type string $default URL for the default image or a default type. Accepts '404' (return
4266-
* a 404 instead of a default image), 'retro' (8bit), 'RoboHash' (robohash),
4267-
* 'monsterid' (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
4268-
* 'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF),
4269-
* or 'gravatar_default' (the Gravatar logo). Default is the value of the
4270-
* 'avatar_default' option, with a fallback of 'mystery'.
4271-
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false.
4272-
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
4273-
* judged in that order. Default is the value of the 'avatar_rating' option.
4264+
* @type string $default URL for the default image or a default type. Accepts:
4265+
* - '404' (return a 404 instead of a default image)
4266+
* - 'retro' (a 8-bit arcade-style pixelated face)
4267+
* - 'robohash' (a robot)
4268+
* - 'monsterid' (a monster)
4269+
* - 'wavatar' (a cartoon face)
4270+
* - 'identicon' (the "quilt", a geometric pattern)
4271+
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
4272+
* - 'blank' (transparent GIF)
4273+
* - 'gravatar_default' (the Gravatar logo)
4274+
* Default is the value of the 'avatar_default' option,
4275+
* with a fallback of 'mystery'.
4276+
* @type bool $force_default Whether to always show the default image, never the Gravatar.
4277+
* Default false.
4278+
* @type string $rating What rating to display avatars up to. Accepts:
4279+
* - 'G' (suitable for all audiences)
4280+
* - 'PG' (possibly offensive, usually for audiences 13 and above)
4281+
* - 'R' (intended for adult audiences above 17)
4282+
* - 'X' (even more mature than above)
4283+
* Default is the value of the 'avatar_rating' option.
42744284
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values.
42754285
* Default null.
42764286
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args
@@ -4283,7 +4293,6 @@ function get_avatar_url( $id_or_email, $args = null ) {
42834293
return $args['url'];
42844294
}
42854295

4286-
42874296
/**
42884297
* Check if this comment type allows avatars to be retrieved.
42894298
*
@@ -4305,7 +4314,6 @@ function is_avatar_comment_type( $comment_type ) {
43054314
return in_array( $comment_type, (array) $allowed_comment_types, true );
43064315
}
43074316

4308-
43094317
/**
43104318
* Retrieves default data about the avatar.
43114319
*
@@ -4316,23 +4324,35 @@ function is_avatar_comment_type( $comment_type ) {
43164324
* @param array $args {
43174325
* Optional. Arguments to use instead of the default arguments.
43184326
*
4319-
* @type int $size Height and width of the avatar image file in pixels. Default 96.
4327+
* @type int $size Height and width of the avatar in pixels. Default 96.
43204328
* @type int $height Display height of the avatar in pixels. Defaults to $size.
43214329
* @type int $width Display width of the avatar in pixels. Defaults to $size.
4322-
* @type string $default URL for the default image or a default type. Accepts '404' (return
4323-
* a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
4324-
* 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm',
4325-
* or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or
4326-
* 'gravatar_default' (the Gravatar logo). Default is the value of the
4327-
* 'avatar_default' option, with a fallback of 'mystery'.
4328-
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false.
4329-
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
4330-
* judged in that order. Default is the value of the 'avatar_rating' option.
4330+
* @type string $default URL for the default image or a default type. Accepts:
4331+
* - '404' (return a 404 instead of a default image)
4332+
* - 'retro' (a 8-bit arcade-style pixelated face)
4333+
* - 'robohash' (a robot)
4334+
* - 'monsterid' (a monster)
4335+
* - 'wavatar' (a cartoon face)
4336+
* - 'identicon' (the "quilt", a geometric pattern)
4337+
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
4338+
* - 'blank' (transparent GIF)
4339+
* - 'gravatar_default' (the Gravatar logo)
4340+
* Default is the value of the 'avatar_default' option,
4341+
* with a fallback of 'mystery'.
4342+
* @type bool $force_default Whether to always show the default image, never the Gravatar.
4343+
* Default false.
4344+
* @type string $rating What rating to display avatars up to. Accepts:
4345+
* - 'G' (suitable for all audiences)
4346+
* - 'PG' (possibly offensive, usually for audiences 13 and above)
4347+
* - 'R' (intended for adult audiences above 17)
4348+
* - 'X' (even more mature than above)
4349+
* Default is the value of the 'avatar_rating' option.
43314350
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values.
43324351
* Default null.
43334352
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args
43344353
* plus a "found_avatar" guess. Pass as a reference. Default null.
4335-
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
4354+
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized.
4355+
* Default empty.
43364356
* }
43374357
* @return array {
43384358
* Along with the arguments passed in `$args`, this will contain a couple of extra arguments.

src/wp-includes/pluggable.php

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,26 +2797,41 @@ function wp_set_password( $password, $user_id ) {
27972797
* Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post.
27982798
*
27992799
* @since 2.5.0
2800-
* @since 4.2.0 Optional `$args` parameter added.
2800+
* @since 4.2.0 Added the optional `$args` parameter.
2801+
* @since 5.5.0 Added the `loading` argument.
2802+
* @since 6.1.0 Added the `decoding` argument.
2803+
* @since 6.3.0 Added the `fetchpriority` argument.
28012804
*
2802-
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
2805+
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
28032806
* user email, WP_User object, WP_Post object, or WP_Comment object.
2804-
* @param int $size Optional. Height and width of the avatar image file in pixels. Default 96.
2805-
* @param string $default_value URL for the default image or a default type. Accepts '404' (return
2806-
* a 404 instead of a default image), 'retro' (8bit), 'RoboHash' (robohash),
2807-
* 'monsterid' (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
2808-
* 'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF),
2809-
* or 'gravatar_default' (the Gravatar logo). Default is the value of the
2810-
* 'avatar_default' option, with a fallback of 'mystery'.
2811-
* @param string $alt Optional. Alternative text to use in img tag. Default empty.
2807+
* @param int $size Optional. Height and width of the avatar in pixels. Default 96.
2808+
* @param string $default_value URL for the default image or a default type. Accepts:
2809+
* - '404' (return a 404 instead of a default image)
2810+
* - 'retro' (a 8-bit arcade-style pixelated face)
2811+
* - 'robohash' (a robot)
2812+
* - 'monsterid' (a monster)
2813+
* - 'wavatar' (a cartoon face)
2814+
* - 'identicon' (the "quilt", a geometric pattern)
2815+
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
2816+
* - 'blank' (transparent GIF)
2817+
* - 'gravatar_default' (the Gravatar logo)
2818+
* Default is the value of the 'avatar_default' option,
2819+
* with a fallback of 'mystery'.
2820+
* @param string $alt Optional. Alternative text to use in the avatar image tag.
2821+
* Default empty.
28122822
* @param array $args {
28132823
* Optional. Extra arguments to retrieve the avatar.
28142824
*
28152825
* @type int $height Display height of the avatar in pixels. Defaults to $size.
28162826
* @type int $width Display width of the avatar in pixels. Defaults to $size.
2817-
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false.
2818-
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
2819-
* judged in that order. Default is the value of the 'avatar_rating' option.
2827+
* @type bool $force_default Whether to always show the default image, never the Gravatar.
2828+
* Default false.
2829+
* @type string $rating What rating to display avatars up to. Accepts:
2830+
* - 'G' (suitable for all audiences)
2831+
* - 'PG' (possibly offensive, usually for audiences 13 and above)
2832+
* - 'R' (intended for adult audiences above 17)
2833+
* - 'X' (even more mature than above)
2834+
* Default is the value of the 'avatar_rating' option.
28202835
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values.
28212836
* Default null.
28222837
* @type array|string $class Array or string of additional classes to add to the img element.
@@ -2825,7 +2840,12 @@ function wp_set_password( $password, $user_id ) {
28252840
* Default false.
28262841
* @type string $loading Value for the `loading` attribute.
28272842
* Default null.
2828-
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
2843+
* @type string $fetchpriority Value for the `fetchpriority` attribute.
2844+
* Default null.
2845+
* @type string $decoding Value for the `decoding` attribute.
2846+
* Default null.
2847+
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized.
2848+
* Default empty.
28292849
* }
28302850
* @return string|false `<img>` tag for the user's avatar. False on failure.
28312851
*/
@@ -2844,8 +2864,8 @@ function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $
28442864
'force_display' => false,
28452865
'loading' => null,
28462866
'fetchpriority' => null,
2847-
'extra_attr' => '',
28482867
'decoding' => null,
2868+
'extra_attr' => '',
28492869
);
28502870

28512871
if ( empty( $args ) ) {
@@ -2883,7 +2903,7 @@ function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $
28832903
* @since 4.2.0
28842904
*
28852905
* @param string|null $avatar HTML for the user's avatar. Default null.
2886-
* @param mixed $id_or_email The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash,
2906+
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
28872907
* user email, WP_User object, WP_Post object, or WP_Comment object.
28882908
* @param array $args Arguments passed to get_avatar_url(), after processing.
28892909
*/
@@ -2922,7 +2942,7 @@ function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $
29222942
}
29232943
}
29242944

2925-
// Add `loading`, `fetchpriority` and `decoding` attributes.
2945+
// Add `loading`, `fetchpriority`, and `decoding` attributes.
29262946
$extra_attr = $args['extra_attr'];
29272947

29282948
if ( in_array( $args['loading'], array( 'lazy', 'eager' ), true )
@@ -2935,25 +2955,24 @@ function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $
29352955
$extra_attr .= "loading='{$args['loading']}'";
29362956
}
29372957

2938-
if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ), true )
2939-
&& ! preg_match( '/\bdecoding\s*=/', $extra_attr )
2958+
if ( in_array( $args['fetchpriority'], array( 'high', 'low', 'auto' ), true )
2959+
&& ! preg_match( '/\bfetchpriority\s*=/', $extra_attr )
29402960
) {
29412961
if ( ! empty( $extra_attr ) ) {
29422962
$extra_attr .= ' ';
29432963
}
29442964

2945-
$extra_attr .= "decoding='{$args['decoding']}'";
2965+
$extra_attr .= "fetchpriority='{$args['fetchpriority']}'";
29462966
}
29472967

2948-
// Add support for `fetchpriority`.
2949-
if ( in_array( $args['fetchpriority'], array( 'high', 'low', 'auto' ), true )
2950-
&& ! preg_match( '/\bfetchpriority\s*=/', $extra_attr )
2968+
if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ), true )
2969+
&& ! preg_match( '/\bdecoding\s*=/', $extra_attr )
29512970
) {
29522971
if ( ! empty( $extra_attr ) ) {
29532972
$extra_attr .= ' ';
29542973
}
29552974

2956-
$extra_attr .= "fetchpriority='{$args['fetchpriority']}'";
2975+
$extra_attr .= "decoding='{$args['decoding']}'";
29572976
}
29582977

29592978
$avatar = sprintf(
@@ -2971,14 +2990,22 @@ function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $
29712990
* Filters the HTML for a user's avatar.
29722991
*
29732992
* @since 2.5.0
2974-
* @since 4.2.0 The `$args` parameter was added.
2993+
* @since 4.2.0 Added the `$args` parameter.
29752994
*
29762995
* @param string $avatar HTML for the user's avatar.
2977-
* @param mixed $id_or_email The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash,
2996+
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
29782997
* user email, WP_User object, WP_Post object, or WP_Comment object.
2979-
* @param int $size Square avatar width and height in pixels to retrieve.
2980-
* @param string $default_value URL for the default image or a default type. Accepts '404', 'retro', 'monsterid',
2981-
* 'wavatar', 'indenticon', 'mystery', 'mm', 'mysteryman', 'blank', or 'gravatar_default'.
2998+
* @param int $size Height and width of the avatar in pixels.
2999+
* @param string $default_value URL for the default image or a default type. Accepts:
3000+
* - '404' (return a 404 instead of a default image)
3001+
* - 'retro' (a 8-bit arcade-style pixelated face)
3002+
* - 'robohash' (a robot)
3003+
* - 'monsterid' (a monster)
3004+
* - 'wavatar' (a cartoon face)
3005+
* - 'identicon' (the "quilt", a geometric pattern)
3006+
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
3007+
* - 'blank' (transparent GIF)
3008+
* - 'gravatar_default' (the Gravatar logo)
29823009
* @param string $alt Alternative text to use in the avatar image tag.
29833010
* @param array $args Arguments passed to get_avatar_data(), after processing.
29843011
*/

src/wp-includes/rest-api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,13 +1215,13 @@ function rest_add_application_passwords_to_index( $response ) {
12151215
}
12161216

12171217
/**
1218-
* Retrieves the avatar urls in various sizes.
1218+
* Retrieves the avatar URLs in various sizes.
12191219
*
12201220
* @since 4.7.0
12211221
*
12221222
* @see get_avatar_url()
12231223
*
1224-
* @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash,
1224+
* @param mixed $id_or_email The avatar to retrieve a URL for. Accepts a user ID, Gravatar MD5 hash,
12251225
* user email, WP_User object, WP_Post object, or WP_Comment object.
12261226
* @return (string|false)[] Avatar URLs keyed by size. Each value can be a URL string or boolean false.
12271227
*/

0 commit comments

Comments
 (0)