diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index ef33b24e..09cf948a 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -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() ) {