get_avatar
最后更新于:2021-11-26 11:02:28
apply_filters( ‘get_avatar’, string $avatar, mixed $id_or_email, int $size, string $default, string $alt, array $args )
Filters the HTML for a user’s avatar.
参数
- $avatar
-
(string)
HTML for the user’s avatar. - $id_or_email
-
(mixed)
The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash, user email, GC_User object, GC_Post object, or GC_Comment object. - $size
-
(int)
Square avatar width and height in pixels to retrieve. - $default
-
(string)
URL for the default image or a default type. Accepts ‘404’, ‘retro’, ‘monsterid’, ‘wavatar’, ‘indenticon’, ‘mystery’, ‘mm’, ‘mysteryman’, ‘blank’, or ‘gravatar_default’. Default is the value of the ‘avatar_default’ option, with a fallback of ‘mystery’. - $alt
-
(string)
Alternative text to use in the avatar image tag. Default empty. - $args
-
(array)
Arguments passed to get_avatar_data(), after processing.
源文件
文件: gc-includes/pluggable.php
// Apply filter add_filter( 'get_avatar' , 'my_custom_avatar' , 1 , 5 ); function my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt ) { $user = false; if ( is_numeric( $id_or_email ) ) { $id = (int) $id_or_email; $user = get_user_by( 'id' , $id ); } elseif ( is_object( $id_or_email ) ) { if ( ! empty( $id_or_email->user_id ) ) { $id = (int) $id_or_email->user_id; $user = get_user_by( 'id' , $id ); } } else { $user = get_user_by( 'email', $id_or_email ); } if ( $user && is_object( $user ) ) { if ( $user->data->ID == '1' ) { $avatar = 'YOUR_NEW_IMAGE_URL'; $avatar = "<img alt='{$alt}' src='https://docs.gechiui.com/hooks/get_avatar/{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; } } return $avatar; }