From 93079b0266f0519890657908aee45ba585ee4c54 Mon Sep 17 00:00:00 2001 From: Adam Cassis Date: Wed, 28 Aug 2024 10:37:46 +0200 Subject: [PATCH] fix: user meta retrieval --- includes/class-simple-local-avatars.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index dd2de71..16ed153 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -326,6 +326,20 @@ public function get_user_id( $id_or_email ) { return $user_id; } + /** + * Get the local avatar user meta. + * + * @param int $user_id User ID. + * @return array Array with avatar data. + */ + public static function get_user_local_avatar( $user ) { + $local_avatars = get_user_meta( $user_id, $this->user_key, true ); + if ( ! is_array( $local_avatars ) || empty( $local_avatars ) ) { + return []; + } + return $local_avatars; + } + /** * Get local avatar url. * @@ -343,7 +357,7 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { } // Fetch local avatar from meta and make sure it's properly set. - $local_avatars = get_user_meta( $user_id, $this->user_key, true ); + $local_avatars = self::get_user_local_avatar( $user_id ); if ( empty( $local_avatars['full'] ) ) { return ''; } @@ -1181,7 +1195,7 @@ public function ajax_assign_simple_local_avatar_media() { * @param int $user_id User ID. */ public function avatar_delete( $user_id ) { - $old_avatars = (array) get_user_meta( $user_id, $this->user_key, true ); + $old_avatars = self::get_user_local_avatar( $user_id ); if ( empty( $old_avatars ) ) { return;