Custom avatar no show up
-
Hi there,
I’m using Ultimate Member with this awesome messaging plugin.
One issue I encounter is that user custom avatar (e.g. user’s own photo) doesn’t show up in the message. Whilst I suppose UM should integrate well in Better Messages, is it because of mere plugin setting?
-
As far as I can remember there is some option in um plugin settings related to gravatar, try to toggle it
Hello
I have similar issue only I have both BuddyPress and UM it takes me to BP profile instead of UM, wonder if UM can go over BP when using such combo.
Thanks.I did a comparison toggling between UM gravatar options. Here is the results I get:
If I turn on gravatar,
If I turn off gravatar,
Either way is also not up to my expectation. Pls advise.
@enkoes you can setup the avatar logic customly so you can make it meet your expectations using this hook:
https://www.better-messages.com/docs/development/php-filters/better_messages_rest_user_itemHello thanks for the code!
What should we add in those 3 places of the code so it will gather UM profile ids, avatars and names?
Thanks for the code!
Ya.. I also having problem on how to apply this code.What I actually want is very simple: If users donβt have custom avatar image, just show up the preset gravatar type (e.g. retro) in messages, otherwise, custom avatar will be used.
Can you show us how to use this code to achieve that?
Here is the code, with help of ChatGPT from AI.com I was able to fine tune it.
Add this to your child theme functions.php, this code will set URL and avatar to each UM member in Better Messages chat. If the user does not have UM avatar it will display default no person from UM image, maybe if you change settings in UltimateMember it will display as you need the gravatar.add_filter('better_messages_rest_user_item', 'custom_user_meta', 20, 3); function custom_user_meta($item, $user_id, $include_personal) { // Set custom profile URL $item['url'] = um_user_profile_url($user_id); // Set custom avatar URL $avatar_url = um_get_user_avatar_url($user_id); if ($avatar_url) { $item['avatar'] = $avatar_url; } // Set custom name // $item['name'] = 'Custom name'; return $item; }Because I not have money to buy premium addons of UM, one plugin has something for free what the other requires premium, maybe in future if will have enough money will upgrade, at the moment everyone is on low$ economy.
We tried also to implement if UM avatar is not present get BP avatar if BP avatar is not present get WP avatar, the code was not working for some reason, it was removing the UM avatars and displaying the BP or WP avatar.
Thanks!
Hi, thanks @itesla and @wordplustranslate for your positive solutions. I tested and both works well.
I still have one more question, I found that better messages generally use ‘UM nickname’ as author name, but sometime ‘username’ is being used for some strange reason. Do we have a way to force the plugin to use ‘UM nickname’ for consistency and security reason?
@itesla I guess probably still using the same hook provided by @wordplus ?
Set custom name
$item[‘name’] = ‘Custom name’;
Regards
Try add this in place of custom name to get user nickname from UM, I have asked ChatGPT bot again.
This filter hook is called every time the author name is displayed in Better Messages, and the code above checks if the user has a Ultimate Member nickname. If a nickname is found, it is returned, otherwise the original author name is returned. This way, you can ensure that UM nickname is always used if available.
Author: ChatGPT
// Use UM nickname as Better Messages author name add_filter( 'better_messages_author_name', 'custom_better_messages_author_name', 10, 2 ); function custom_better_messages_author_name( $author_name, $author_id ) { $nickname = um_get_display_name( $author_id ); if ( $nickname ) { return $nickname; } else { return $author_name; } }P.s. in my case I commented out custom name code.
@itesla proper filter would be bp_better_messages_display_name and not better_messages_author_name
The codes work like the way I want. Thanks all! This plugin is awesome to me!
p/s: I never knew ChatGPT can do this coding job. If got time I should try it myself. π
The topic ‘Custom avatar no show up’ is closed to new replies.