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
Conditionally chang...
 
Notifications
Clear all

Question [Solved] Conditionally changing comment avatar

4 Posts
2 Users
1 Reactions
5,375 Views
(@billy)
Posts: 6
Active Member
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
 
[#7842]

I'm using a custom field that I added to my comment form and I know from there I can target the meta key with a function. If the key equals a certain value, I want to change or hide that comment author's avatar. The following seems like it should work but it doesn't. Does anyone out there know how to hide or change the avatar within wpDiscuz comments if a custom meta key's value is detected? By the way, I know the custom field is set correctly because I'm able to change the author name, and I was able to add a class based on this custom field. Only the avatar gives me trouble. Also, changing the priority of get_avatar does nothing.

function change_comment_avatar($avatar, $id_or_email, $size, $default, $alt) {
    $comment = get_comment($id_or_email);
    $fun_comment = get_comment_meta($comment->comment_ID, 'the_fun_comment', true);
    if ($fun_comment == 'on') {
        $avatar = "<img alt='{$alt}' src='example.png' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
    }
    return $avatar;
}
add_filter('get_avatar', 'change_comment_avatar', 10, 5);

 
Posted : 16/01/2024 4:27 am
Asti
 Asti
(@asti)
Posts: 8260
Illustrious Member Support
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
 

I'll ask the developers and provide you with an update shortly. 


In case you want to say thank you! 🙂
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.

 
Posted : 16/01/2024 2:53 pm
Asti
 Asti
(@asti)
Posts: 8260
Illustrious Member Support
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
 

The get_avatar() function currently lacks a comment ID parameter, rendering the logic ineffective.

In the upcoming version of wpDiscuz, we'll add comments support, enabling you to achieve the desired functionality.

function change_comment_avatar( $avatar, $id_or_email, $size, $default, $alt, $args ) {
	$comment = empty($args['wpdiscuz_comment']) ? null : $args['wpdiscuz_comment'];
	if ( $comment instanceof WP_Comment) {
		$fun_comment = get_comment_meta($comment->comment_ID, 'the_fun_comment', true);
		if ($fun_comment == 'on') {
			$avatar = "<img alt='{$alt}' src='example.png' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
		}
	}
	return $avatar;
}

add_filter( 'get_avatar', 'change_comment_avatar', 99, 6 );

In case you want to say thank you! 🙂
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.

 
Posted : 18/01/2024 2:04 pm
Billy reacted
(@billy)
Posts: 6
Active Member
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
 

Thank you for looking into it and for future updates!


 
Posted : 19/01/2024 9:06 am