diff --git a/includes/avatar-privacy/class-user-avatar-upload.php b/includes/avatar-privacy/class-user-avatar-upload.php index 576203ad..cc547f4c 100644 --- a/includes/avatar-privacy/class-user-avatar-upload.php +++ b/includes/avatar-privacy/class-user-avatar-upload.php @@ -99,6 +99,13 @@ class User_Avatar_Upload { */ private $base_url; + /** + * The core API. + * + * @var \Avatar_Privacy_Core + */ + private $core; + /** * Creates a new instance. * @@ -110,6 +117,15 @@ public function __construct( $plugin_file, Filesystem_Cache $file_cache ) { $this->file_cache = $file_cache; } + /** + * Sets the core API instance to use. + * + * @param \Avatar_Privacy_Core $core The core API. + */ + public function set_core( \Avatar_Privacy_Core $core ) { + $this->core = $core; + } + /** * Retrieves the markup for uploading user avatars. * @@ -264,7 +280,7 @@ public function get_unique_filename( $directory, $filename, $extension ) { * @param int $user_id The user ID. */ public function delete_uploaded_avatar( $user_id ) { - $hash = \get_user_meta( $user_id, \Avatar_Privacy_Core::EMAIL_HASH_META_KEY, true ); + $hash = $this->core->get_user_hash( $user_id ); $this->file_cache->invalidate( 'user', "#/{$hash}-[1-9][0-9]*\.[a-z]{3}\$#" ); @@ -277,21 +293,20 @@ public function delete_uploaded_avatar( $user_id ) { /** * Retrieves the URL for the given default icon type. * - * @param string[] $avatar The full-size avatar image information. - * @param string $email The mail address used to generate the identity hash. - * @param int $size The requested size in pixels. - * @param \Avatar_Privacy_Core $core The core API. - * @param bool $force Optional. Whether to force the regeneration of the icon. Default false. + * @param string[] $avatar The full-size avatar image information. + * @param string $email The mail address used to generate the identity hash. + * @param int $size The requested size in pixels. + * @param bool $force Optional. Whether to force the regeneration of the icon. Default false. * * @return string */ - public function get_icon_url( array $avatar, $email, $size, \Avatar_Privacy_Core $core, $force = false ) { + public function get_icon_url( array $avatar, $email, $size, $force = false ) { if ( empty( $this->base_dir ) || empty( $this->base_url ) ) { $this->base_url = $this->file_cache->get_base_url(); $this->base_dir = $this->file_cache->get_base_dir(); } - $hash = $core->get_hash( $email ); + $hash = $this->core->get_hash( $email ); $extension = \Avatar_Privacy\Components\Images::FILE_EXTENSION[ $avatar['type'] ]; $filename = "user/{$this->get_sub_dir( $hash )}/{$hash}-{$size}.{$extension}"; $target = "{$this->base_dir}{$filename}"; diff --git a/includes/avatar-privacy/components/class-images.php b/includes/avatar-privacy/components/class-images.php index 72f60b71..f3565f08 100644 --- a/includes/avatar-privacy/components/class-images.php +++ b/includes/avatar-privacy/components/class-images.php @@ -415,7 +415,7 @@ public function gravatar_icon_url( $url, $email, $size, $user_id = false, $ratin * @return string */ public function user_avatar_icon_url( array $avatar, $email, $size, $force = false ) { - return $this->user_avatar->get_icon_url( $avatar, $email, $size, $this->core, $force ); + return $this->user_avatar->get_icon_url( $avatar, $email, $size, $force ); } diff --git a/includes/avatar-privacy/components/class-user-profile.php b/includes/avatar-privacy/components/class-user-profile.php index e4617fe4..e371fdd8 100644 --- a/includes/avatar-privacy/components/class-user-profile.php +++ b/includes/avatar-privacy/components/class-user-profile.php @@ -92,6 +92,8 @@ public function __construct( $plugin_file, User_Avatar_Upload $upload ) { * @return void */ public function run( \Avatar_Privacy_Core $core ) { + $this->upload->set_core( $core ); + if ( \is_admin() ) { \add_action( 'admin_init', [ $this, 'admin_init' ] ); }