Skip to content

Commit

Permalink
Deploying version 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmjones committed Jun 25, 2018
1 parent 357c07b commit 20d19b0
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 76 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Requires at least:** 4.6
**Tested up to:** 4.9
**Requires PHP:** 5.5
**Stable tag:** 1.4
**Stable tag:** 1.4.1
**License:** GPLv3

Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
Expand Down Expand Up @@ -71,6 +71,9 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin

## Changelog ##

### WP Offload S3 Lite 1.4.1 - 2018-06-21 ###
* Bug fix: Incorrect filesize saved to metadata when image removed from local server

### WP Offload S3 Lite 1.4 - 2018-06-12 ###
* New: Using AWS PHP SDK v3
* New: Requires PHP 5.5+
Expand Down
16 changes: 4 additions & 12 deletions classes/amazon-s3-and-cloudfront.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ public function upload_attachment_to_s3( $post_id, $data = null, $file_path = nu
return $this->return_upload_error( $error_msg, $return_metadata );
}

// Get original file's stats.
$filesize = filesize( $file_path );
$file_name = wp_basename( $file_path );
$type = get_post_mime_type( $post_id );
$allowed_types = $this->get_allowed_mime_types();
Expand Down Expand Up @@ -1163,7 +1165,7 @@ public function upload_attachment_to_s3( $post_id, $data = null, $file_path = nu
$files_to_remove = array_unique( $files_to_remove );

// Delete the files and record original file's size before removal.
$filesize = $this->remove_local_files( $files_to_remove, $post_id );
$this->remove_local_files( $files_to_remove, $post_id );

// Store filesize in the attachment meta data for use by WP
if ( 0 < $filesize ) {
Expand Down Expand Up @@ -1287,23 +1289,15 @@ protected function return_upload_error( $error_msg, $return = null ) {
*
* @param array $file_paths array of files to remove
* @param int $attachment_id
*
* @return int Original file's size if attachment ID given, otherwise always 0.
*/
function remove_local_files( $file_paths, $attachment_id = 0 ) {
$filesize = 0;
$filesize_total = 0;

foreach ( $file_paths as $index => $path ) {
if ( ! empty( $attachment_id ) && is_int( $attachment_id ) ) {
$bytes = filesize( $path );

if ( false !== $bytes ) {
$filesize_total += $bytes;

// Will return the original file's size.
$filesize = $bytes;
}
$filesize_total += ( false !== $bytes ) ? $bytes : 0;
}

// Individual files might still be kept local, but we're still going to count them towards total above.
Expand All @@ -1328,8 +1322,6 @@ function remove_local_files( $file_paths, $attachment_id = 0 ) {
if ( $filesize_total > 0 ) {
update_post_meta( $attachment_id, 'wpos3_filesize_total', $filesize_total );
}

return $filesize;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions classes/as3cf-plugin-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ function get_setting( $key, $default = '' ) {
return apply_filters( 'as3cf_get_setting', $setting, $key );
}

/**
* Get a specific setting from the core plugin.
*
* @param $key
* @param string $default
*
* @return string
*/
public function get_core_setting( $key, $default = '' ) {
return $this->get_setting( $key, $default );
}

/**
* Gets a single setting that has been defined in the plugin settings constant
*
Expand Down
4 changes: 2 additions & 2 deletions classes/providers/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function get_access_key_id() {
return $constant ? constant( $constant ) : '';
}

return $this->as3cf->get_setting( $this->access_key_id_setting_name );
return $this->as3cf->get_core_setting( $this->access_key_id_setting_name );
}

/**
Expand All @@ -127,7 +127,7 @@ public function get_secret_access_key() {
return $constant ? constant( $constant ) : '';
}

return $this->as3cf->get_setting( $this->secret_access_key_setting_name );
return $this->as3cf->get_core_setting( $this->secret_access_key_setting_name );
}

/**
Expand Down
Loading

0 comments on commit 20d19b0

Please sign in to comment.