Amazon_S3_And_CloudFront::remove_attachment_files_from_s3 PHP Method

remove_attachment_files_from_s3() public method

Removes an attachment's files from S3.
public remove_attachment_files_from_s3 ( integer $post_id, array $s3object, boolean $remove_backup_sizes = true, boolean $log_error = false, boolean $return_on_error = false, boolean $force_new_s3_client = false )
$post_id integer
$s3object array
$remove_backup_sizes boolean remove previous edited image versions
$log_error boolean
$return_on_error boolean
$force_new_s3_client boolean if we are deleting in bulk, force new S3 client to cope with possible different regions
    function remove_attachment_files_from_s3($post_id, $s3object, $remove_backup_sizes = true, $log_error = false, $return_on_error = false, $force_new_s3_client = false)
    {
        $prefix = $this->normalize_object_prefix($s3object['key']);
        $bucket = $s3object['bucket'];
        $region = $this->get_s3object_region($s3object);
        $paths = $this->get_attachment_file_paths($post_id, false, false, $remove_backup_sizes);
        if (is_wp_error($region)) {
            $region = '';
        }
        $objects_to_remove = array();
        foreach ($paths as $path) {
            $objects_to_remove[] = array('Key' => $prefix . basename($path));
        }
        // finally delete the objects from S3
        $this->delete_s3_objects($region, $bucket, $objects_to_remove, $log_error, $return_on_error, $force_new_s3_client);
    }

Usage Example

 /**
  * Allow the WordPress Image Editor to remove edited version of images
  * if the original image is being restored and 'IMAGE_EDIT_OVERWRITE' is set
  *
  * @param int    $post_id
  * @param array  $s3object
  * @param string $prefix
  * @param array  $args
  */
 function image_editor_remove_files($post_id, $s3object, $prefix, $args)
 {
     if (isset($_POST['do']) && 'restore' == $_POST['do'] && defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE) {
         $meta = get_post_meta($post_id, '_wp_attachment_metadata', true);
         $this->as3cf->remove_attachment_files_from_s3($post_id, $s3object, $meta['file']);
     }
 }
All Usage Examples Of Amazon_S3_And_CloudFront::remove_attachment_files_from_s3
Amazon_S3_And_CloudFront