• Tony Bellardi

    (@chitarristiorg)


    Hi! First of all, thank you for your great work on the Advanced User Avatar plugin – it works perfectly on my WordPress site.

    I kindly wanted to ask if you might consider adding native compatibility with the Better Messages plugin.
    At the moment, Better Messages doesn’t automatically detect the custom avatars provided by Advanced User Avatar, so users see the default WordPress avatar inside the messaging interface.

    Better Messages allows developers to integrate third-party avatar systems through its better_messages_rest_user_item filter, which simply requires returning the avatar URL for each user.
    If Advanced User Avatar could expose the user’s custom avatar URL through this filter (or through a small compatibility add-on), it would make the two plugins work perfectly together and would definitely be appreciated by many users.

    Thank you for your time and for considering this improvement — and thanks again for your excellent plugin!

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter Tony Bellardi

    (@chitarristiorg)

    for now work with

    // Forza Better Messages a usare l’avatar restituito da get_avatar/get_avatar_url
    add_filter( ‘better_messages_rest_user_item’, ‘pm_use_wp_avatar_for_better_messages’, 50, 3 );

    function pm_use_wp_avatar_for_better_messages( $item, $user_id, $include_personal ) {

    // Proviamo prima con get_avatar (restituisce <img>)
    $avatar_html = get_avatar( $user_id );
    
    if ( ! empty( $avatar_html ) ) {
        // Estrai l'URL dall'HTML <img src="...">
        if ( preg_match( '/src=["\']([^"\']+)["\']/', $avatar_html, $m ) ) {
            $avatar_url = $m[1];
            // Assicuriamoci che sia https se il sito è in https
            if ( ! empty( $avatar_url ) && is_ssl() ) {
                $avatar_url = set_url_scheme( $avatar_url, 'https' );
            }
            $item['avatar'] = $avatar_url;
            return $item;
        }
    }
    
    // Fallback: get_avatar_url (ritorna solo URL)
    $avatar_url = get_avatar_url( $user_id );
    if ( ! empty( $avatar_url ) ) {
        if ( is_ssl() ) {
            $avatar_url = set_url_scheme( $avatar_url, 'https' );
        }
        $item['avatar'] = $avatar_url;
        return $item;
    }
    
    // Se proprio nulla, non tocchiamo $item (Better Messages userà il suo default)
    return $item;

    }

Viewing 1 replies (of 1 total)

The topic ‘Batter Message’ is closed to new replies.