strangerstudios / basic-user-avatars

Add an avatar upload field on frontend pages and on the Edit Profile screen so users and admins can manage custom profile pictures without Gravatar.
https://wordpress.org/plugins/basic-user-avatars/
39 stars 34 forks source link

delete old image and gif not playing #69

Open Rise-KuN opened 1 year ago

Rise-KuN commented 1 year ago

i noticed that there is no filters for image size also the resize is making the gif not playing and if i change the image or back to Gavatar the images that i uploaded doesn't get deleted from media.

in "public function avatar_delete( $user_id )" i added this line "wp_delete_attachment( $user_id, $old_avatars );" before "delete_user_meta( $user_id, 'basic_user_avatar' );" now when i check "delete avatar": all the image that i uploaded gets deleted but... if i upload another avatar without checking "delete avatar" the old image doesn't get deleted from media.

Rise-KuN commented 1 year ago

now i commented these to disable the resize that making gif not work properly if ( ! is_wp_error( $image ) ) { //$image->resize( $size, $size, true ); //$image_sized = $image->save(); }

Rise-KuN commented 1 year ago

to be able to delete old images i had to override the images so i removed the $number from $base_name and removed the $ext so the name will be same no matter what the type of the image is :)

andrewlimaza commented 7 months ago

Thanks for sharing this with us @Rise-KuN, would it be possible for you to submit a Pull Request for these changes so we may overlook it and try get it merged in?

Rise-KuN commented 4 months ago

Thanks for sharing this with us @Rise-KuN, would it be possible for you to submit a Pull Request for these changes so we may overlook it and try get it merged in?

Sure, and sorry for late reply, first i disable the resize like i said to keep the original size and make the size full $size = 'full'; if ( ! is_wp_error( $image ) ) { //$image->resize( $size, $size, true ); //$image_sized = $image->save(); }

then i added support for webp: // Allowed file extensions/types $mimes = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'webp' => 'image/webp', );

also in public function avatar_delete( $user_id ) i added this line wp_delete_attachment( $user_id, $old_avatars ); to delete the image file itself, also in public function unique_filename_callback( $dir, $name, $ext ) i removed the image extension so that the user can only have 1 image and gets overridden each time the user upload a new image no matter what the extension is, and without it the image works fine

public function unique_filename_callback( $dir, $name, $ext ) { $user = get_user_by( 'id', (int) $this->user_id_being_edited ); $name = $base_name = sanitize_file_name( strtolower( $user->display_name ) . '_avatar' ); $number = 1; while ( file_exists( $dir . "/$name$ext" ) ) { //$name = $basename . '' . $number; $name = $base_name; $number++; } //return $name . $ext; return $name; }

Screenshot 2024-04-12 163622

this is the edited version i use right now basic-user-avatars.zip