• Could you add the hook to get_avatar_url() as well.

    I wrote plugin that uses the avatar url rather than the avatar image and it returns the gravatar image instead. I was able to make a workaround function that parses the return value of get_avatar() and returns the src=’…’ contents, but I’d prefer not to have to do this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • +1 on this.

    Mind sharing your workaround @jottinger? I was going to implement a filter to adapt the get_avatar functionality. Might as well share a common solution.

    p.s. this was what I ended up using — makes some assumptions about the size param though.

    #
    # Added Author Image to Blog Posts
    #
    
    /**
     * WordPress Avatar URL Filter
     *
     * Replaces the WordPress avatar URL function with your custom photo, similar to get_avatar
     *
     * @param string $url         The URL of the avatar.
     * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
     *                            user email, WP_User object, WP_Post object, or WP_Comment object.
     * @param array  $args        Arguments passed to get_avatar_data(), after processing.
     */
    function shim_cupp_avatar_url( $url, $id_or_email, $args ) {
    	if ( $user = cupp_get_user_by_id_or_email( $id_or_email) ) {
    		$url = get_cupp_meta( $user->ID, $args['size'] );
    	}
    
    	return $url;
    }
    
    add_filter( 'get_avatar_url', 'shim_cupp_avatar_url', 1, 5 );
    Thread Starter jottinger

    (@jottinger)

    I literally just used a regex to grab the src=”” parameter from the get_avatar() function. Nothing elegant.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Could you add hook to get_avatar_url() as well’ is closed to new replies.