Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Resized images, with add the process of saving the resize path #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions aq_resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@ public function process( $url, $width = null, $height = null, $crop = null, $sin
if ( ! is_wp_error( $resized_file ) ) {
$resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
$img_url = $upload_url . $resized_rel_path;

/*
*update meta media
*/
//get ID media
$ID_data = attachment_url_to_postid($url);

//create name
$data_path = "{$dst_rel_path}-{$suffix}.{$ext}";
$metaname = '_attachment_aqresize_'.$ID_data;

///get option meta
$meta_media = get_option($metaname);
if ($meta_media) {
array_push($meta_media,$data_path);
$newdata = $meta_media;
} else {
$newdata = array($data_path);
}

//update option
update_option($metaname,$newdata,'');

} else {
throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
}
Expand Down Expand Up @@ -245,4 +268,24 @@ function aq_resize( $url, $width = null, $height = null, $crop = null, $single =
}
}

/**
* when delete attachment, get data option
*/
add_action('delete_attachment', 'delete_attachment_aq_resize', 10, 1);
function delete_attachment_aq_resize($id) {

$metaname = '_attachment_aqresize_'.$id;
$meta_media = get_option($metaname);
$upload_dir = wp_get_upload_dir()['basedir'];

if($meta_media){
foreach($meta_media as $path) {
$file_path = $upload_dir.$path; // path of the file which need to be deleted.
wp_delete_file( $file_path ); //delete file here.
}
}
//delete option
delete_option($metaname);
}