• 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?

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author wordplus

    (@wordplus)

    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.

    Thread Starter enkoes

    (@enkoes)

    I did a comparison toggling between UM gravatar options. Here is the results I get:

    If I turn on gravatar,

    https://paste.pics/M42SX

    If I turn off gravatar,

    https://paste.pics/M42WK

    Either way is also not up to my expectation. Pls advise.

    Plugin Author wordplus

    (@wordplus)

    @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_item

    Hello 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?

    Thread Starter enkoes

    (@enkoes)

    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;
    }
    • This reply was modified 3 years, 2 months ago by Omtesla. Reason: additional info
    • This reply was modified 3 years, 2 months ago by Omtesla.
    • This reply was modified 3 years, 2 months ago by Omtesla.
    WordPlus CLPTE

    (@wordplustranslate)

    @itesla that seems to be correct! but I still not understand why do you use both BuddyPress and UM at the same time πŸ˜€

    @enkoes you can use @itesla way or you can reinstall the plugin, where I updated the logic for um avatar abit.

    @wordplustranslate

    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!

    Thread Starter enkoes

    (@enkoes)

    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.

    Plugin Author wordplus

    (@wordplus)

    @itesla proper filter would be bp_better_messages_display_name and not better_messages_author_name

    Thread Starter enkoes

    (@enkoes)

    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. πŸ™‚

    @wordplus Yes agree, ChatGPT can make mistakes if he does not know proper syntaxes of the plugin, but overall it can help with fine tunning a code if you provide it with a sample.

    @enkoes glad the issue is resolved!

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Custom avatar no show up’ is closed to new replies.