Skip to content

Commit

Permalink
Introduce a filter that short-circuits the avatar URL generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Sep 21, 2023
1 parent 36e35c4 commit ad748e7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions includes/class-simple-local-avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,27 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) {
}
}

/**
* Filter the URL of an avatar for the given user and size.
*
* This filters is applied before Simple Local Avatars validates the value of the
* `$local_avatars` array which comes from the user meta field. This allows the URL
* to be short-circuited, for example by a dynamic image resizing service.
*
* @param string|null $url The URL of the avatar. If null, the URL will be
* generated by Simple Local Avatars.
* @param int $user_id The user ID.
* @param int $size Requested avatar size.
* @param array $local_avatars The local avatars for the user.
* @return string|null The URL of the avatar, or null to allow Simple Local Avatars to
* generate the URL.
*/
$url = apply_filters( 'pre_simple_local_avatar_url', null, $user_id, $size, $local_avatars );

if ( is_string( $url ) ) {
return $url;
}

// handle "real" media
if ( ! empty( $local_avatars['media_id'] ) ) {
// If using shared avatars, make sure we validate the URL on the main site.
Expand Down

0 comments on commit ad748e7

Please sign in to comment.