• Resolved unbelievable

    (@unbelievable)


    I noticed that when i set my default WordPress avatar it doesn’t actually change it in the better messages live chat I was wondering if maybe you can add that as a feature so we are not forced to use third party avatar plugin as I use a plugin which allows users to change default avatar on frontend

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

    (@wordplus)

    Hi there!

    If you are using 3rd party plugin to set avatars, that may be not supported out of the box and you need to integrate it customly using this hook:

    https://www.better-messages.com/docs/development/php-filters/better_messages_rest_user_item

    Thanks!

    Thread Starter unbelievable

    (@unbelievable)

    I have no clue how to set the hook to use default wordpress avatar lol

    Plugin Author wordplus

    (@wordplus)

    Hi there!

    By default WordPress does not have functions to change avatars, so it does not makes sense that you are saying that you are using default wordpress avatar.

    Thanks!

    Thread Starter unbelievable

    (@unbelievable)

    Well i mean im using the default wordpress profile picture function not a custom one and i use a plugin to change your actual wordpress profile picture if that makes more sense and i have no idea how to write a code snippet which fetches avatars from wordpress itself

    • This reply was modified 6 months, 2 weeks ago by unbelievable.
    • This reply was modified 6 months, 2 weeks ago by unbelievable.
    Thread Starter unbelievable

    (@unbelievable)

    I managed to write a working functions snippet code which fetches original wordpress profile picture here is the code if anyone needs it

    add_filter('better_messages_rest_user_item', 'custom_user_meta', 50, 3);
    
    function custom_user_meta($item, $user_id, $include_personal) {
        
        // Fetch the avatar HTML for the user
        $avatar_html = get_avatar($user_id);
    
        // Check if the avatar HTML is not empty
        if (!empty($avatar_html)) {
            // Extract the URL from the avatar HTML
            preg_match('/src="(.*?)"/', $avatar_html, $matches);
            if (isset($matches[1])) {
                // Set custom avatar URL
                $item['avatar'] = $matches[1];
            }
        } else {
            // If no uploaded avatar is found, fall back to the default WordPress avatar
            $item['avatar'] = get_avatar_url($user_id);
        }
    
        return $item;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can I use the default wordpress avatar for the message plugin?’ is closed to new replies.