Skip to content

Commit

Permalink
Deploying version 3.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmjones committed Dec 12, 2024
1 parent 7a01bcd commit 8d4f315
Show file tree
Hide file tree
Showing 716 changed files with 73,204 additions and 2,715 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
**Contributors:** wpengine, deliciousbrains, ianmjones, eriktorsner, kevinwhoffman, tysonreeder, dalewilliams, lewisia32, mattshaw, aaemnnosttv, a5hleyrich, polevaultweb, bradt, joetan \
**Tags:** uploads, amazon, s3, amazon s3, digitalocean, digitalocean spaces, google cloud storage, gcs, mirror, admin, media, cdn, cloudfront \
**Requires at least:** 5.5 \
**Tested up to:** 6.6 \
**Tested up to:** 6.7 \
**Requires PHP:** 7.2 \
**Stable tag:** 3.2.9 \
**Stable tag:** 3.2.10 \
**License:** GPLv3

Copies files to Amazon S3, DigitalOcean Spaces or Google Cloud Storage as they are uploaded to the Media Library. Optionally configure Amazon CloudFront or another CDN for faster delivery.
Expand Down Expand Up @@ -103,6 +103,13 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin

## Changelog

### WP Offload Media Lite 3.2.10 - 2024-12-12

* New: DigitalOcean regions Toronto (TOR1) and London (LON1) are now selectable
* New: Google Cloud Storage regions Africa (Johannesburg), Dual-Region (Belgium/London), Dual-Region (London/Frankfurt) and Dual-Region (Frankfurt/Zürich) are now selectable
* New: Google Cloud Storage SDK has been updated to v1.39.0 (requires PHP 7.4+)
* Bug fix: Speed of adding new media is no longer affected by the number of records in the postmeta table

### WP Offload Media Lite 3.2.9 - 2024-10-04

* Security: The plugin now uses its own update mechanism from WP Engine servers
Expand Down
18 changes: 2 additions & 16 deletions classes/amazon-s3-and-cloudfront.php
Original file line number Diff line number Diff line change
Expand Up @@ -1554,16 +1554,14 @@ function does_file_exist( $filename, $time ) {
}

/**
* Does file exist local
* Does file exist locally.
*
* @param string $filename
* @param string $time
*
* @return bool
*/
function does_file_exist_local( $filename, $time ) {
global $wpdb;

public function does_file_exist_local( $filename, $time ) {
$path = wp_upload_dir( $time );
$path = ltrim( $path['subdir'], '/' );

Expand All @@ -1572,18 +1570,6 @@ function does_file_exist_local( $filename, $time ) {
}
$file = $path . $filename;

// WordPress doesn't check its own basic record, so we will.
$sql = $wpdb->prepare( "
SELECT COUNT(*)
FROM $wpdb->postmeta
WHERE meta_key = %s
AND meta_value = %s
", '_wp_attached_file', $file );

if ( (bool) $wpdb->get_var( $sql ) ) {
return true;
}

// Check our records of local source path as it also covers original_image.
if ( ! empty( Media_Library_Item::get_by_source_path( array( $file ), array(), true, true ) ) ) {
return true;
Expand Down
44 changes: 27 additions & 17 deletions classes/as3cf-plugin-updater.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* The PluginUpdater class which can be used to pull plugin updates from a new location.
*
* @package amazon-s3-and-cloudfront
*/

Expand All @@ -19,33 +20,38 @@
class AS3CF_Plugin_Updater {
/**
* The URL where the api is located.
* @var ApiUrl
*
* @var string
*/
private $api_url;

/**
* The amount of time to wait before checking for new updates.
* @var CacheTime
*
* @var int
*/
private $cache_time;

/**
* These properties are passed in when instantiating to identify the plugin and it's update location.
* @var Properties
*
* @var array
*/
private $properties;

/**
* Get the class constructed.
*
* @param Properties $properties These properties are passed in when instantiating to identify the plugin and it's update location.
* @param array $properties These properties are passed in when instantiating to identify the plugin and it's update location.
*/
public function __construct( $properties ) {
if (
empty( $properties['plugin_slug'] ) ||
empty( $properties['plugin_basename'] )
) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( 'WPE Secure Plugin Updater received a malformed request.' );

return;
}

Expand All @@ -65,8 +71,10 @@ public function __construct( $properties ) {
/**
* Get the full plugin properties, including the directory name, version, basename, and add a transient name.
*
* @param Properties $properties These properties are passed in when instantiating to identify the plugin and it's update location.
* @param ApiUrl $api_url The URL where the api is located.
* @param array $properties These properties are passed in when instantiating to identify the plugin and it's update location.
* @param string $api_url The URL where the api is located.
*
* @return array|null
*/
public function get_full_plugin_properties( $properties, $api_url ) {
$plugins = \get_plugins();
Expand Down Expand Up @@ -103,30 +111,33 @@ public function register() {
/**
* Filter the plugin update transient to take over update notifications.
*
* @param object $transient The site_transient_update_plugins transient.
* @param ?object $transient_value The value of the `site_transient_update_plugins` transient.
*
* @handles site_transient_update_plugins
* @return object
* @return object|null
*/
public function filter_plugin_update_transient( $transient ) {
public function filter_plugin_update_transient( $transient_value ) {
// No update object exists. Return early.
if ( empty( $transient ) ) {
return $transient;
if ( empty( $transient_value ) ) {
return $transient_value;
}

$result = $this->fetch_plugin_info();

if ( false === $result ) {
return $transient;
return $transient_value;
}

$res = $this->parse_plugin_info( $result );

if ( version_compare( $this->properties['plugin_version'], $result->version, '<' ) ) {
$res = $this->parse_plugin_info( $result );
$transient->response[ $res->plugin ] = $res;
$transient->checked[ $res->plugin ] = $result->version;
$transient_value->response[ $res->plugin ] = $res;
$transient_value->checked[ $res->plugin ] = $result->version;
} else {
$transient_value->no_update[ $res->plugin ] = $res;
}

return $transient;
return $transient_value;
}

/**
Expand Down Expand Up @@ -213,7 +224,6 @@ private function fetch_plugin_info() {
* @return stdClass
*/
private function parse_plugin_info( $response ) {

global $wp_version;

$res = new stdClass();
Expand Down
2 changes: 2 additions & 0 deletions classes/providers/storage/digitalocean-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class DigitalOcean_Provider extends AWS_Provider {
'fra1' => 'Frankfurt',
'blr1' => 'Bangalore',
'syd1' => 'Sydney',
'lon1' => 'London',
'tor1' => 'Toronto',
);

/**
Expand Down
62 changes: 51 additions & 11 deletions classes/providers/storage/gcp-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ class GCP_Provider extends Storage_Provider {
'me-west1' => 'Middle East (Tel Aviv)',
'australia-southeast1' => 'Australia (Sydney)',
'australia-southeast2' => 'Australia (Melbourne)',
'africa-south1' => 'Africa (Johannesburg)',
'asia1' => 'Dual-Region (Tokyo/Osaka)',
'eur4' => 'Dual-Region (Finland/Netherlands)',
'eur5' => 'Dual-Region (Belgium/London)',
'eur7' => 'Dual-Region (London/Frankfurt)',
'eur8' => 'Dual-Region (Frankfurt/Zürich)',
'nam4' => 'Dual-Region (Iowa/South Carolina)',
);

Expand Down Expand Up @@ -528,7 +532,10 @@ public function list_keys( array $locations ) {
$keys = array();

$results = array_map( function ( $location ) {
return $this->storage->bucket( $location['Bucket'] )->objects( array( 'prefix' => $location['Prefix'], 'fields' => 'items/name' ) );
return $this->storage->bucket( $location['Bucket'] )->objects( array(
'prefix' => $location['Prefix'],
'fields' => 'items/name',
) );
}, $locations );

foreach ( $results as $attachment_id => $objects ) {
Expand Down Expand Up @@ -672,7 +679,12 @@ protected function url_prefix( $region = '', $expires = null ) {
* @return string
*/
protected function url_domain( $domain, $bucket, $region = '', $expires = null, $args = array() ) {
if ( apply_filters( 'as3cf_' . static::get_provider_key_name() . '_' . static::get_service_key_name() . '_bucket_in_path', false !== strpos( $bucket, '.' ) ) ) {
if (
apply_filters(
'as3cf_' . static::get_provider_key_name() . '_' . static::get_service_key_name() . '_bucket_in_path',
false !== strpos( $bucket, '.' )
)
) {
$domain = $domain . '/' . $bucket;
} else {
// TODO: Is this mode allowed for GCS native URLs?
Expand All @@ -691,7 +703,11 @@ protected function url_domain( $domain, $bucket, $region = '', $expires = null,
*
* @return string
*/
protected function get_console_url_suffix_param( string $bucket = '', string $prefix = '', string $region = '' ): string {
protected function get_console_url_suffix_param(
string $bucket = '',
string $prefix = '',
string $region = ''
): string {
if ( ! empty( $this->get_project_id() ) ) {
return '?project=' . $this->get_project_id();
}
Expand Down Expand Up @@ -753,7 +769,10 @@ protected function get_key_file_path_contents( string $path ) {
$content = json_decode( file_get_contents( $path ), true );

if ( empty( $content ) ) {
$this->as3cf->notices->add_notice( __( 'Media cannot be offloaded due to invalid JSON in the key file.', 'amazon-s3-and-cloudfront' ), $notice_args );
$this->as3cf->notices->add_notice(
__( 'Media cannot be offloaded due to invalid JSON in the key file.', 'amazon-s3-and-cloudfront' ),
$notice_args
);

return false;
}
Expand Down Expand Up @@ -783,7 +802,10 @@ public function validate_key_file_content( $key_file_content ): bool {
if ( ! isset( $key_file_content['project_id'] ) ) {
$this->as3cf->notices->add_notice(
sprintf(
__( 'Media cannot be offloaded due to a missing <code>project_id</code> field which may be the result of an old or obsolete key file. <a href="%1$s" target="_blank">Create a new key file</a>', 'amazon-s3-and-cloudfront' ),
__(
'Media cannot be offloaded due to a missing <code>project_id</code> field which may be the result of an old or obsolete key file. <a href="%1$s" target="_blank">Create a new key file</a>',
'amazon-s3-and-cloudfront'
),
static::get_provider_service_quick_start_url() . '#service-account-key-file'
),
$notice_args
Expand All @@ -795,7 +817,10 @@ public function validate_key_file_content( $key_file_content ): bool {
if ( ! isset( $key_file_content['private_key'] ) ) {
$this->as3cf->notices->add_notice(
sprintf(
__( 'Media cannot be offloaded due to a missing <code>private_key</code> field in the key file. <a href="%1$s" target="_blank"">Create a new key file</a>', 'amazon-s3-and-cloudfront' ),
__(
'Media cannot be offloaded due to a missing <code>private_key</code> field in the key file. <a href="%1$s" target="_blank"">Create a new key file</a>',
'amazon-s3-and-cloudfront'
),
static::get_provider_service_quick_start_url() . '#service-account-key-file'
),
$notice_args
Expand All @@ -807,7 +832,10 @@ public function validate_key_file_content( $key_file_content ): bool {
if ( ! isset( $key_file_content['type'] ) ) {
$this->as3cf->notices->add_notice(
sprintf(
__( 'Media cannot be offloaded due to a missing <code>type</code> field in the key file. <a href="%1$s" target="_blank">Create a new key file</a>', 'amazon-s3-and-cloudfront' ),
__(
'Media cannot be offloaded due to a missing <code>type</code> field in the key file. <a href="%1$s" target="_blank">Create a new key file</a>',
'amazon-s3-and-cloudfront'
),
static::get_provider_service_quick_start_url() . '#service-account-key-file'
),
$notice_args
Expand All @@ -819,7 +847,10 @@ public function validate_key_file_content( $key_file_content ): bool {
if ( ! isset( $key_file_content['client_email'] ) ) {
$this->as3cf->notices->add_notice(
sprintf(
__( 'Media cannot be offloaded due to a missing <code>client_email</code> field in the key file. <a href="%1$s" target="_blank">Create a new key file</a>', 'amazon-s3-and-cloudfront' ),
__(
'Media cannot be offloaded due to a missing <code>client_email</code> field in the key file. <a href="%1$s" target="_blank">Create a new key file</a>',
'amazon-s3-and-cloudfront'
),
static::get_provider_service_quick_start_url() . '#service-account-key-file'
),
$notice_args
Expand All @@ -842,7 +873,10 @@ public function validate_key_file_content( $key_file_content ): bool {
public function prepare_bucket_error( WP_Error $object, bool $single = true ): string {
if ( false !== strpos( $object->get_error_message(), "OpenSSL unable to sign" ) ) {
return sprintf(
__( 'Media cannot be offloaded due to an invalid OpenSSL Private Key. <a href="%1$s" target="_blank">Update the key file</a>', 'amazon-s3-and-cloudfront' ),
__(
'Media cannot be offloaded due to an invalid OpenSSL Private Key. <a href="%1$s" target="_blank">Update the key file</a>',
'amazon-s3-and-cloudfront'
),
static::get_provider_service_quick_start_url() . '#service-account-key-file'
);
}
Expand All @@ -852,14 +886,20 @@ public function prepare_bucket_error( WP_Error $object, bool $single = true ): s
if ( ! is_null( $message ) ) {
if ( isset( $message->error ) && 'invalid_grant' === $message->error ) {
return sprintf(
__( 'Media cannot be offloaded using the provided service account. <a href="%1$s" target="_blank">Read more</a>', 'amazon-s3-and-cloudfront' ),
__(
'Media cannot be offloaded using the provided service account. <a href="%1$s" target="_blank">Read more</a>',
'amazon-s3-and-cloudfront'
),
static::get_provider_service_quick_start_url() . '#service-account-key-file'
);
}

if ( isset( $message->error->code ) && 404 === $message->error->code ) {
return sprintf(
__( 'Media cannot be offloaded because a bucket with the configured name does not exist. <a href="%1$s">Enter a different bucket</a>', 'amazon-s3-and-cloudfront' ),
__(
'Media cannot be offloaded because a bucket with the configured name does not exist. <a href="%1$s">Enter a different bucket</a>',
'amazon-s3-and-cloudfront'
),
'#/storage/bucket'
);
}
Expand Down
Loading

0 comments on commit 8d4f315

Please sign in to comment.