• Hi,

    First of all congratulations on this plugin. It is absolutely fantastic !

    I have a question please. Is it possible to choose a specific background for one specific user?

    Thank you and again…amazing plugin!

Viewing 1 replies (of 1 total)
  • Plugin Author Ariel

    (@arielhr1987)

    Hi @clawduda
    Thanks for you kind words! glad you enjoy the plugin.

    I have a question please. Is it possible to choose a specific background for one specific user?

    You can achieve it if you know the email or the ID of the user for the one you want to create the custom background.
    This code will do the trick. A user with id “1” or email “[email protected]” will have an avatar with a red background. Modify it to fit your needs. I added some helpful comments.

    /**
     * Show custom background color for specific user
     *
     * @param $url_args
     * @param $id_or_email
     *
     * @return mixed
     */
    function custom_background_for_specific_user( $url_args, $id_or_email ) {
    	$user  = false;
    	$email = false;
    
    	if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
    		$id_or_email = get_comment( $id_or_email );
    	}
    
    	// Process the user identifier.
    	if ( is_numeric( $id_or_email ) ) {
    		$user = get_user_by( 'id', absint( $id_or_email ) );
    	} elseif ( is_string( $id_or_email ) ) {
    		if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) {
    			// MD5 hash.
    			list( $email_hash ) = explode( '@', $id_or_email );
    		} else {
    			// Email address.
    			$email = $id_or_email;
    		}
    		$user = get_user_by( 'email', $id_or_email );
    	} elseif ( $id_or_email instanceof WP_User ) {
    		// User object.
    		$user = $id_or_email;
    	} elseif ( $id_or_email instanceof WP_Post ) {
    		// Post object.
    		$user = get_user_by( 'id', (int) $id_or_email->post_author );
    	} elseif ( $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_email ) ) {
    			$email = $id_or_email->comment_author_email;
    		}
    	}
    
    	if ( $user ) {
    		$email = $user->user_email;
    	}
    
    	/**
    	 * Use this code if you want to show a custom background for a user with a known email
    	 */
    	if ( $email && $email == '[email protected]' ) {
    		$url_args['bg']    = 'ff0000';
    		$url_args['color'] = 'ffffff';
    	}
    
    	/**
    	 * Use this code if you want to show a custom background to user with ID = = 1
    	 */
    	if ( $user && $user->ID == 1 ) {
    		$url_args['background'] = 'ff0000';
    		$url_args['color']      = 'ffffff';
    	}
    
    	return $url_args;
    }
    
    add_filter( 'leira_letter_avatar_url_args', 'custom_background_for_specific_user', 10, 2 );

    Kind regards!

Viewing 1 replies (of 1 total)
  • The topic ‘Choose a specific background for a particular user’ is closed to new replies.