admin管理员组文章数量:1410674
I don't like the idea of using Gravatar, and I don't want my users to be able to change their avatar. However I want to replace the avatar for the admin role only. Is it possible to do this without using a plugin and without Gravatar?
I have found code snippets to replace the default gravatar, but that would be sitewide for all users. I only want to replace the admin avatar.
Thank you!
I don't like the idea of using Gravatar, and I don't want my users to be able to change their avatar. However I want to replace the avatar for the admin role only. Is it possible to do this without using a plugin and without Gravatar?
I have found code snippets to replace the default gravatar, but that would be sitewide for all users. I only want to replace the admin avatar.
Thank you!
Share Improve this question asked Nov 21, 2019 at 14:38 jockebqjockebq 4631 gold badge6 silver badges18 bronze badges 2- Do you want a specific image for the administrators of the website? – giannisrig Commented Nov 21, 2019 at 14:54
- Yes! Exactly, I want to specify it (in code) – jockebq Commented Nov 21, 2019 at 15:03
1 Answer
Reset to default 1I might have found a solution. It seems to work, but maybe I am missing something?
function custom_user_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 );
} else if ( 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 = sprintf( '%s/images/avatar/support-male.png', get_stylesheet_directory_uri() );
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
else if ( $user->data->ID == '200' ) {
$avatar = sprintf( '%s/images/avatar/support-female.png', get_stylesheet_directory_uri() );
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
else {
$avatar = sprintf( '%s/images/avatar/default.png', get_stylesheet_directory_uri() );
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
}
return $avatar;
}
add_filter( 'get_avatar' , 'custom_user_avatar' , 1 , 5 );
本文标签: customizationChange admin avatar only (without Gravatar or plugin)
版权声明:本文标题:customization - Change admin avatar only (without Gravatar or plugin)? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744982027a2635873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论