0

I need to update custom image for users avatar on the time of registrations.

I've using Pie-register plugin and it will allow upload profile picture but saving image url in user_meta and when try to get using get_avatar it returning default avatar, but I need upload image as user avatar on all places. Like user profile page , in comment section etc.

Is this possible to display user meta value (image url) as user avatar for all users?

Any help will be appreciated.

1 Answer 1

2

We can use the get_avatar_url filter to modify the avatar's url.

If all the relevant get_avatar() calls, have user id as an input argument, then it's easy to get the corresponding user's meta value, with get_user_meta(), within the filter's callback.

Otherwise we need to handle all possible input cases, for get_avatar( $some_input ), as it supports:

  • user id,
  • user email,
  • gravatar md5 hash,
  • WP_User object,
  • WP_Post object
  • WP_Comment object.

We can look into the get_avatar_data() function, to get an idea how to write such checks.

An alternative, to determine the user id from the get_avatar() input, we might try to fetch the md5 hash from the generated gravatar url and use it to determine the user id from it. Maybe store the md5 email hash for each user. The found_avatar argument might also help, as it's true if the avatar was found for the given user.

Hope it helps!

1
  • But I think in this case I need to pass user ID in get_avatar() ? I've different profile picture for each users saved in user meta and I want to use those images for each user as profile picture. Jun 21, 2017 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.