Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

delete old image and gif not playing #69

Open
Rise-KuN opened this issue Apr 15, 2023 · 4 comments
Open

delete old image and gif not playing #69

Rise-KuN opened this issue Apr 15, 2023 · 4 comments

Comments

@Rise-KuN
Copy link

Rise-KuN commented Apr 15, 2023

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
Copy link
Author

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

Rise-KuN commented Apr 12, 2024

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 = $base_name . '
' . $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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants