get_avatar WordPress function and NextEnd
-
Hi again, another question π
I am testing the plugin with Google and it works well, however when creating a user it pulls in the avatar from Google which is great but when I try and use the WordPress get_avatar function this grabs the Gravatar image?
Not sure how to get the new image which is what I would expect and this also appears to be stored in a custom folder /nsl_avatars/
I have a custom profile page (not using standard WordPress user page) that when a user is created it copies the profile image to a custom field.
is there a way to do this?
-
This topic was modified 5 years, 4 months ago by
SuperStu.
-
This topic was modified 5 years, 4 months ago by
-
Hi @omgstu
I just checked it on my local test site and the get_avatar() function, e.g.:
<?php echo get_avatar(get_current_user_id()); ?>
worked fine for me, as it displayed the currently logged in users’s avatar that we stored with social login.If it didn’t work for you for some reason. Could you check please if the user that you checked the get_avatar() function with, indeed have an avatar stored by Nextend Social Login. E.g. in the users table ( /wp-admin/users.php ) we display the avatars by default. Can you see the social avatar appearing there?
Also does the get_avatar() function displays the social avatar, when you disable all plugins except Nextend Social Login and you change your theme to a WordPress default one like Twenty Twenty?I am using get_avatar_url (not get_avatar) and this seems to return the gravatar, rather than the local stored image url location…
not sure if its related to this (different plugin but same issue)
https://github.com/10up/simple-local-avatars/pull/40
cheers
Hi @omgstu
I am sorry, but currently the social avatars can only be retrieved over the get_avatar() function:
but not the get_avatar_url() function:
However it is on our To Do list, so we may make it in a future release. I will inform you here.
Best regards,
Laszlo.Cool thanks, this work out OK apart from. One thing.
I’ve created a shortcode to output the image, however I don’t seem to be able to set the size. It’s always 96 x 96 PX no matter the size I specify in the get_avitar size argument.
If I look in the library the images are pulled in at that size. Is there a way to get them at their Max size?
Hi @omgstu
Nextend Social Login stores the avatars only in one size, and you can find them in the wp-content/uploads/nsl_avatars folder.
This one size depends on the size of the image that the provider returns.So when you display the image with the get_avatar() function, it won’t create additional sub-sizes of the image, but it will simply get the image with the size that is available and that image will be displayed in an img element with the specified size.
So this is already the max size, I am sorry.
thats a shame looks like the Google people API doe let the option for specifying other sizes, but never mind ill just have to work with 96px
When using the get_avatar() function, you can go down in size, but unfortunately not up in size for the image.
Cheers.
-
This reply was modified 5 years, 4 months ago by
SuperStu.
Hi @omgstu
We use the OAuth2 REST API endpoint to get the basic profile information like name, email, avatar.
But returning to the problem with the scaling of the image:
In the current release we have a function hooked to the get_avatar filter, and in that function we are rendering the avatar, but it can not scale larger then that original size.
But starting from our next release ( version 3.0.27 ) we will rather use the “pre_get_avatar_data” filter:which means:
- you will be able to get the social avatars with the get_avatar_url() function
- we will no longer need to modify the avatars over the get_avatar filter, so the get_avatar() function will be able to render the image the same way as WordPress does. ( So the images will be able to be scaled up )
We will try to release a new version soon, hopefully before the end of this week.
Best regards,
Laszlo.You guys are doing great work, appreciate the updates.
Thanks again.
Hi @omgstu
I just wanted to let you know we have just released the version 3.0.27 which contains the modifications I described above.
Feel free to give it a try.Cool, so I can now use the get_avatar and the image scales up well.
However, I am still getting the same gravatar url returned when I use get_avatar_url and not the URL to the wp-content/uploads/nsl_avatars directory path – not that’s its an issue really with the previous step π
maybe I a missing something… anyway the first works.
this is my function
add_action(‘nsl_register_new_user’, ‘nsl_register_activated’, 10, 2);
function nsl_register_activated($user_id) {
$user = new WP_User($user_id);
// add_user_meta($user->ID, ‘wpcf-activated’, $user_id);{ // Edit form ID
//update to a MEMBER role type on Authentication and create PROFILE
wp_update_user( array( ‘ID’ => $user_id, ‘role’ => ‘member’ ) );
$user_info = get_userdata($user_id);
$user_first = ucfirst($user_info->first_name);
$user_last = ucfirst($user_info->last_name);
$avatar = get_avatar_url( $user_id );
$combined = $user_id.”-“.$user_first.”-“.$user_last;$my_post = array(
‘post_title’ => $user_first.” “.$user_last,
‘post_status’ => ‘publish’,
‘post_author’ => $user_id,
‘post_name’ => $combined,
‘post_type’ => ‘profile’,
// meta_input is array of meta fields when inserting into.
‘meta_input’ => array(
‘wpcf-member-profile-display-name’ => $user_first.” “.$user_last,
// adds profile URL to custom field.
‘wpcf-member-profile-picture’ => $avatar,
),
);// Insert the post into the database
wp_insert_post( $my_post );
}};
Hi @omgstu
Please note that, we can not provide support for custom coding. But I checked your codes and the problem is that, at the point where you are trying to get the avatar with get_avatar_url() function, we haven’t stored the avatar yet, as the avatars will be synchronized on login.
The second parameter of the “nsl_register_new_user” action is the instance of the provider that the user is trying to connect over. Using that you could run the functions of the provider, e.g. you could synchronizing the profile. That way you could get the avatars stored on registration, too.
Here you can find an example code for triggering the avatar synchronization on the action that you used:add_action('nsl_register_new_user', 'nsl_register_activated', 10, 2); function nsl_register_activated($user_id, $provider) { $provider->syncProfile($user_id, $provider, $provider->getAccessToken($user_id)); };So in your function, this syncProfile() method should be called before you use the get_avatar_url() and that will fix the problem!
Best regards,
Laszlo.you guys are awesome – appreciate you guiding me through this … looking forward to testing in a minute.
Works perfectly by the way. π appreciate the help
-
This reply was modified 5 years, 4 months ago by
The topic ‘get_avatar WordPress function and NextEnd’ is closed to new replies.