Skip to content

Commit

Permalink
When autocompress is activated and you wanted to restore a specific f…
Browse files Browse the repository at this point in the history
…ile, it was compressed again.
  • Loading branch information
teamcrombie committed Jul 16, 2024
1 parent 9402192 commit e2dfd4b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions admin/Ilove_Img_Wm_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ public function column_id_row( $column_name, $column_id ) {
public function process_attachment( $metadata, $attachment_id ) {
update_post_meta( $attachment_id, 'iloveimg_status_watermark', 0 ); // status no watermarked

if ( (int) Ilove_Img_Wm_Resources::is_auto_watermark() === 1 && Ilove_Img_Wm_Resources::is_loggued() && (int) Ilove_Img_Wm_Resources::is_activated() === 1 ) {
$images_restore = null !== get_option( 'iloveimg_images_to_restore', null ) ? json_decode( get_option( 'iloveimg_images_to_restore' ), true ) : array();

if ( (int) Ilove_Img_Wm_Resources::is_auto_watermark() === 1 && Ilove_Img_Wm_Resources::is_loggued() && (int) Ilove_Img_Wm_Resources::is_activated() === 1 && ! in_array( $attachment_id, $images_restore, true ) ) {
wp_update_attachment_metadata( $attachment_id, $metadata );
$this->async_watermark( $attachment_id );

Expand Down Expand Up @@ -520,8 +522,10 @@ public function ilove_img_restore() {
delete_post_meta( $attachment_id, 'iloveimg_status_compress' );
delete_post_meta( $attachment_id, 'iloveimg_compress' );

if ( ! $key_founded ) {
if ( false !== $key_founded ) {
unset( $images_restore[ $key_founded ] );
wp_delete_file( ILOVE_IMG_WM_BACKUP_FOLDER . basename( get_attached_file( $attachment_id ) ) );
update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore ) );
}

wp_send_json_success( __( 'It was restored correctly', 'iloveimg-watermark' ), 200 );
Expand Down

0 comments on commit e2dfd4b

Please sign in to comment.