Skip to content

Commit

Permalink
Merge pull request #237 from johnbillion/get-url-filter
Browse files Browse the repository at this point in the history
Introduce a filter that short-circuits the avatar URL generation
  • Loading branch information
peterwilsoncc committed Nov 23, 2023
2 parents cda6fc8 + 20e5948 commit e09ab84
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 @@ -368,6 +368,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 esc_url( $url );
}

// handle "real" media
// If using shared avatars, make sure we validate the URL on the main site.
if ( $this->is_avatar_shared() ) {
Expand Down

0 comments on commit e09ab84

Please sign in to comment.