I add a new media image (using amazon-s3-and-cloudfront and amazon-web-services wordpress plugins) and I need to clear cache of this image.
I use smush PRO to compress image: it compress image only locally so I need to re-put images on S3.
This is my code
global $as3cf;
if ( ! $as3cf instanceof Amazon_S3_And_CloudFront ) return;
$results = new WP_Query( $query );
$attachments=(array)$results->get_posts();
if(!empty($attachments)){
foreach($attachments as $attachment){
$amazons3_info=get_post_meta($attachment->ID,'amazonS3_info');
@$as3cf->delete_attachment($attachment->ID);
$new_files = $as3cf->upload_attachment_to_s3($attachment->ID);
if(is_wp_error($new_files) && isset($amazons3_info) && !empty($amazons3_info)){
update_post_meta($attachment->ID,'amazonS3_info',$amazons3_info);
}
update_post_meta($attachment->ID,'my-smpro-smush',$new_files);
}
}
The variable $new_files contains something like that
a:3:{s:6:"bucket";s:21:"static.example.com";s:3:"key";s:63:"wp-content/uploads/2016/12/334ca0545d748d0fe135eb30212154db.jpg";s:6:"region";s:9:"eu-west-1";}
So now i need to clear image.
Someone can help me? I also try https://github.com/subchild/CloudFront-PHP-Invalidator/blob/master/CloudFront.php but it doesn't work.