admin管理员组文章数量:1279235
Is there any possibility to replace gravatar session in profile page with an custom image with their image. Which can be uploaded from their PC while creation of the account is is possible to do with coding in wordpress.
Is there any possibility to replace gravatar session in profile page with an custom image with their image. Which can be uploaded from their PC while creation of the account is is possible to do with coding in wordpress.
Share Improve this question asked Nov 19, 2018 at 7:07 James PaulJames Paul 3711 bronze badges1 Answer
Reset to default 2Yes you can use ACF Pro to achieve that
First create a field for user image (here: tsm_local_avatar)
then filter the get_gravatar function:
<?php
/**
* Use ACF image field as avatar
* @author Mike Hemberger
* @link http://thestizmedia/acf-pro-simple-local-avatars/
* @uses ACF Pro image field (tested return value set as Array )
*/
add_filter('get_avatar', 'tsm_acf_profile_avatar', 10, 5);
function tsm_acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
$user = '';
// Get user by id or email
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 ) {
return $avatar;
}
// Get the user id
$user_id = $user->ID;
// Get the file id
$image_id = get_user_meta($user_id, 'tsm_local_avatar', true); // CHANGE TO YOUR FIELD NAME
// Bail if we don't have a local avatar
if ( ! $image_id ) {
return $avatar;
}
// Get the file size
$image_url = wp_get_attachment_image_src( $image_id, 'thumbnail' ); // Set image size by name
// Get the file url
$avatar_url = $image_url[0];
// Get the img markup
$avatar = '<img alt="' . $alt . '" src="' . $avatar_url . '" class="avatar avatar-' . $size . '" height="' . $size . '" width="' . $size . '"/>';
// Return our new avatar
return $avatar;
}
More info here: https://thestizmedia/acf-pro-simple-local-avatars/
本文标签: customizationIs there a possiblity to replace profile image gravatar with custom user images
版权声明:本文标题:customization - Is there a possiblity to replace profile image gravatar with custom user images 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741268142a2368859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论