pre_get_avatar
Filter HookDescription
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 {@see 'get_avatar'} filter and returning early.Hook Information
File Location |
wp-includes/pluggable.php
View on GitHub
|
Hook Type | Filter |
Line Number | 3146 |
Hook Parameters
Type | Name | Description |
---|---|---|
string|null
|
$avatar
|
HTML for the user's avatar. Default null. |
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. |
array
|
$args
|
Arguments passed to get_avatar_url(), after processing. |
Usage Examples
Basic Usage
<?php
// Hook into pre_get_avatar
add_filter('pre_get_avatar', 'my_custom_filter', 10, 3);
function my_custom_filter($avatar, $id_or_email, $args) {
// Your custom filtering logic here
return $avatar;
}
Source Code Context
wp-includes/pluggable.php:3146
- How this hook is used in WordPress core
<?php
3141 * @param string|null $avatar HTML for the user's avatar. Default null.
3142 * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
3143 * user email, WP_User object, WP_Post object, or WP_Comment object.
3144 * @param array $args Arguments passed to get_avatar_url(), after processing.
3145 */
3146 $avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args );
3147
3148 if ( ! is_null( $avatar ) ) {
3149 /** This filter is documented in wp-includes/pluggable.php */
3150 return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args );
3151 }
PHP Documentation
<?php
/**
* 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 {@see 'get_avatar'} filter and returning early.
*
* @since 4.2.0
*
* @param string|null $avatar HTML for the user's avatar. Default null.
* @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.
*/
Quick Info
- Hook Type: Filter
- Parameters: 3
- File: wp-includes/pluggable.php
Related Hooks
Related hooks will be displayed here in future updates.