The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Search
Close
AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Overriding user ava...
 
Share:
Notifications
Clear all

Limited Support

Our support team is currently on holiday from December 25, 2025 to January 7, 2026, and replies may be delayed during this period.

We appreciate your patience and understanding while our team is away. Thank you for being part of the wpDiscuz community!

Merry Christmas and Happy Holidays! 🎄

[Solved] Overriding user avatar

3 Posts
2 Users
0 Reactions
2,483 Views
Posts: 2
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@antinopol)
New Member
Joined: 4 years ago
[#2686]

Hello!

The site has an LMS plugin into which users upload their avatars. I want them to appear in comments, I was able to replace wordpress avatars with LMS avatars using a hook, but wpDiscuz won't load them. Help me find a solution.

Standard comments

image

After installing wpDiscuz

image

Here is the hook by which I will successfully override the Wordpress avatars:

add_filter('get_avatar_data', 'lms_avatar', 10, 2);
function lms_avatar($args, $id_or_email){
    $lmsUrl = get_user_meta($id_or_email->user_id, 'stm_lms_user_avatar', true);
    if ($id_or_email->user_id >= null && $lmsUrl != null){
        $args['url'] = $lmsUrl;
        return $args;
    } else {
        $args['url'] = get_stylesheet_directory_uri() . '/img/avatar-user.jpg';
        return $args;
    }
}

Topic Tags
2 Replies
Posts: 2
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@antinopol)
New Member
Joined: 4 years ago

I figured out, it turns out that the plugin overrides the function and the $ id_or_email argument is already an ID.

add_filter('get_avatar_data', 'lms_avatar', 10, 2);
function lms_avatar($args, $userId){
    //Получаем путь к аватару, загруженному через lms
    $lmsUrl = get_user_meta($userId, 'stm_lms_user_avatar', true);
    //Если Id пользователя больше или равно 0 и путь к аватару lms существет, то заменяем на этот путь к аватару
    if ($userId >= null && $lmsUrl != null){
        $args['url'] = $lmsUrl;
        return $args;
    } 
    //Иначе применяем картинку аватара по умолчанию, которая лежит внутри папки темы ../img/avatar.jpg
    else {
        $args['url'] = get_stylesheet_directory_uri() . '/img/avatar-user.jpg';
        return $args;
    }
}

1 Reply
Asti
 Asti
Support
(@asti)
Joined: 8 years ago

Illustrious Member
Posts: 8205
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

Thank you for letting us know. Glad to hear that the issue is fixed.


Share: