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

    (@arielhr1987)

    Hi @djoni7811

    If you select the option “Automatically determine background color for each user (Recommended)” the background of the image is determined from the user email. If the users have the same email, the background will be the same. There is also a remote possibility that different emails could have the same background color.
    If you can post here the emails, (or at least the generated images in .svg format) so i can check them that would be great.
    In case of the images without the letters,
    Are you using other plugins? which one?
    You “lose” the letters while showing comments? When you create the comment you fill the name and email of the commenter?

    kind regards

    Thread Starter djoni7811

    (@djoni7811)

    @arielhr1987
    I removed the ability to leave an email, left only the name field.

    How can I generate it only from the name?

    • This reply was modified 3 years, 11 months ago by djoni7811.
    • This reply was modified 3 years, 11 months ago by djoni7811.
    Plugin Author Ariel

    (@arielhr1987)

    @djoni7811

    This snippet should do the trick (add it to your functions.php).
    Keep in mind that your WP_Comment object most have comment_author field set. This is the default wp field for comments author, some plugins use a different field, if so, just make sure you use the correct one.
    Let me know if it work for you.

    function background_from_nickname( $url_args, $id_or_email ) {
    
    	$user = false;
    	if ( $id_or_email instanceof WP_Comment ) {
    
    		if ( ! empty( $id_or_email->user_id ) ) {
    			$user = get_user_by( 'id', (int) $id_or_email->user_id );
    		}
    		if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author ) ) {
    			$hash           = $id_or_email->comment_author . '@localhost.com';//add @localhost.com is optional
    			$hash           = md5( strtolower( trim( $hash ) ) );
    			$url_args['background'] = substr( $hash, 0, 6 );
    		}
    	}
    
    	return $url_args;
    }
    
    add_filter( 'leira_letter_avatar_url_args', 'background_from_nickname', 10, 2 );
    Thread Starter djoni7811

    (@djoni7811)

    thank you, now everything works

    Plugin Author Ariel

    (@arielhr1987)

    Thats great @djoni7811
    Please consider giving us a review. It will help us a lot to spread the word and make the plugin more popular.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘random color’ is closed to new replies.