Support » Plugin: Leira Letter Avatar » Blank Avatar as Default

  • Hello,

    Fantastic plugin. So useful for what I need on my website.

    I am currently facing a problem… If a user is not logged in, I want the avatar to show as blank (no avatar at all). And when the user is logged in, his letters avatar will display.

    In WP Admin > Settings > Discussion > Avatars, I have checked “Show Avatars” and selected “Blank” as a default avatar, however this unchecks the “Enable use of letter avatar” in the Letter Avatar settings.

    When I check “Enable use of letter avatar” again, it automatically selects Letters (Generated) in the Settings > Discussion again, and therefore the “Blank” option is not possible.

    Please can you advise.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ariel

    (@arielhr1987)

    Hi @caroltheo

    The behavior you describe with the settings is the correct one.
    The plugin setting “Enable use of letter avatar” acts as a shortcut for the setting in WP Admin > Settings > Discussion > Avatars > default avatar.
    So every time you select “Enable use of letter avatar” is like if you were checking “Letters” as the default avatar as you described.
    So you either use mystery or letters but not both at the same time.

    There is a way, however, to show the mystery avatar for the user if is logged out.
    This method depends on how the avatar is being show.
    For example if your theme is using this code to show the avatar:
    echo get_avatar( wp_get_current_user() );
    or something similar you could do something like this to show the mystery avatar(add it to your functions.php).

    function mystery_avatar_if_logged_out( $args, $id_or_email ) {
    
    	if ( ( $id_or_email instanceof WP_User && ! $id_or_email->exists() ) || ! $id_or_email ) {
    		$args['force_default'] = true;
    		$args['default']       = 'mystery';
    	}
    
    	return $args;
    }
    
    add_filter( 'pre_get_avatar_data', 'mystery_avatar_if_logged_out', 90, 2 );

    So it all depends on how the user avatar is shown…

    Let me know if it works for you

    Thread Starter caroltheo

    (@caroltheo)

    Thank you for your reply and solution. I will try with your code above.

    On this note, and I noticed in the last support question, how can I use both WP User Avatar and Letters?

    I basically want the function that if a user is not logged in, a default avatar (WP User Avatar) will appear, and once a user is logged in, his Letters avatar will display instead.

    I have saved the settings in Avatars > Settings (WP User Avatar settings) that causes Leira Letters Avatar setting “Enable use of letter avatar” get unchecked.
    I then go to Leira Letters Avatar settings page and enable the option but it still doesn’t allow me to use both WP Avatar and Leira Letter Avatar.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.