pre_get_avatar
Allows the HTML for a user's avatar to be returned early.
Returning a non-null value will effectively short-circuit get_avatar(), passing the value through the get_avatar filter and returning early.
Usage
add_filter( 'pre_get_avatar', 'wp_kama_pre_get_avatar_filter', 10, 3 ); /** * Function for `pre_get_avatar` filter-hook. * * @param string|null $avatar HTML for the user's avatar. * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, user email, WP_User object, WP_Post object, or WP_Comment object. * @param array $args Arguments passed to get_avatar_url(), after processing. * * @return string|null */ function wp_kama_pre_get_avatar_filter( $avatar, $id_or_email, $args ){ // filter... return $avatar; }
- $avatar(string|null)
- HTML for the user's avatar.
Default: null - $id_or_email(mixed)
- The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, user email, WP_User object, WP_Post object, or WP_Comment object.
- $args(array)
- Arguments passed to get_avatar_url(), after processing.
Changelog
Since 4.2.0 | Introduced. |
Where the hook is called
pre_get_avatar
wp-includes/pluggable.php 2910
$avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args );