Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a filter that short-circuits the avatar URL generation #237

Merged
merged 8 commits into from
Nov 23, 2023
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