Skip to content

Commit

Permalink
Deploying version 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmjones committed Nov 20, 2017
1 parent 297cb20 commit 54b55db
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 71 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
**Contributors:** bradt, deliciousbrains
**Tags:** amazon, amazon web services
**Requires at least:** 4.6
**Tested up to:** 4.8
**Stable tag:** 1.0.3
**Tested up to:** 4.9
**Stable tag:** 1.0.4
**License:** GPLv3

Houses the Amazon Web Services (AWS) PHP libraries and manages access keys. Required by other AWS plugins.
Expand Down Expand Up @@ -35,6 +35,13 @@ This plugin is required by other plugins, which use its libraries and its settin

## Changelog ##

### 1.0.4 - 2017-11-20 ###
* Improvement: Compatibility with WordPress 4.9
* Improvement: Compatibility with WP Offload S3 1.5.1
* Bug fix: Reveal access keys form option shown when keys partially defined
* Bug fix: WP_Error being passed to AWS methods
* Bug fix: "More info" links can be broken across two lines

### 1.0.3 - 2017-06-19 ###
* Improvement: Compatibility with WP Offload S3 1.5

Expand Down
8 changes: 4 additions & 4 deletions amazon-web-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://wordpress.org/extend/plugins/amazon-web-services/
Description: Includes the Amazon Web Services PHP libraries, stores access keys, and allows other plugins to hook into it.
Author: Delicious Brains
Version: 1.0.3
Version: 1.0.4
Author URI: https://deliciousbrains.com/
Network: True
Text Domain: amazon-web-services
Expand All @@ -22,11 +22,11 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************

$GLOBALS['aws_meta']['amazon-web-services']['version'] = '1.0.3';
$GLOBALS['aws_meta']['amazon-web-services']['version'] = '1.0.4';

$GLOBALS['aws_meta']['amazon-web-services']['supported_addon_versions'] = array(
'amazon-s3-and-cloudfront' => '0.9',
'amazon-s3-and-cloudfront-pro' => '1.0b1',
'amazon-s3-and-cloudfront' => '1.2.1',
'amazon-s3-and-cloudfront-pro' => '1.5.1',
);

require dirname( __FILE__ ) . '/classes/aws-compatibility-check.php';
Expand Down
2 changes: 1 addition & 1 deletion assets/css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes
2 changes: 1 addition & 1 deletion assets/sass/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ body.toplevel_page_amazon-web-services .wrap {
}
}

.amazon-s3-and-cloudfront-assets > article {
.amazon-s3-and-cloudfront-assets-pull > article {
background-color: #0769ad;
margin-top: 0;
}
Expand Down
65 changes: 46 additions & 19 deletions classes/amazon-web-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function render_page() {
* @return bool
*/
function are_key_constants_set() {
return defined( 'AWS_ACCESS_KEY_ID' ) && defined( 'AWS_SECRET_ACCESS_KEY' );
return defined( 'AWS_ACCESS_KEY_ID' ) || defined( 'AWS_SECRET_ACCESS_KEY' );
}

/**
Expand All @@ -222,7 +222,22 @@ function are_key_constants_set() {
* @return bool
*/
function are_prefixed_key_constants_set() {
return defined( 'DBI_AWS_ACCESS_KEY_ID' ) && defined( 'DBI_AWS_SECRET_ACCESS_KEY' );
return defined( 'DBI_AWS_ACCESS_KEY_ID' ) || defined( 'DBI_AWS_SECRET_ACCESS_KEY' );
}

/**
* Whether or not IAM access keys are needed.
*
* Keys are needed if we are not using EC2 roles or not defined/set yet.
*
* @return bool
*/
public function needs_access_keys() {
if ( $this->use_ec2_iam_roles() ) {
return false;
}

return ! $this->are_access_keys_set();
}

/**
Expand All @@ -237,31 +252,43 @@ function are_access_keys_set() {
/**
* Get the AWS key from a constant or the settings
*
* Falls back to settings only if neither constant is defined.
*
* @return string
*/
function get_access_key_id() {
if ( defined( 'DBI_AWS_ACCESS_KEY_ID' ) ) {
return DBI_AWS_ACCESS_KEY_ID;
} elseif ( defined( 'AWS_ACCESS_KEY_ID' ) ) {
return AWS_ACCESS_KEY_ID; // Deprecated
if ( $this->are_prefixed_key_constants_set() || $this->are_key_constants_set() ) {
if ( defined( 'DBI_AWS_ACCESS_KEY_ID' ) ) {
return DBI_AWS_ACCESS_KEY_ID;
} elseif ( defined( 'AWS_ACCESS_KEY_ID' ) ) {
return AWS_ACCESS_KEY_ID; // Deprecated
}
} else {
return $this->get_setting( 'access_key_id' );
}

return $this->get_setting( 'access_key_id' );
return '';
}

/**
* Get the AWS secret from a constant or the settings
*
* Falls back to settings only if neither constant is defined.
*
* @return string
*/
function get_secret_access_key() {
if ( defined( 'DBI_AWS_SECRET_ACCESS_KEY' ) ) {
return DBI_AWS_SECRET_ACCESS_KEY;
} elseif ( defined( 'AWS_SECRET_ACCESS_KEY' ) ) {
return AWS_SECRET_ACCESS_KEY; // Deprecated
if ( $this->are_prefixed_key_constants_set() || $this->are_key_constants_set() ) {
if ( defined( 'DBI_AWS_SECRET_ACCESS_KEY' ) ) {
return DBI_AWS_SECRET_ACCESS_KEY;
} elseif ( defined( 'AWS_SECRET_ACCESS_KEY' ) ) {
return AWS_SECRET_ACCESS_KEY; // Deprecated
}
} else {
return $this->get_setting( 'secret_access_key' );
}

return $this->get_setting( 'secret_access_key' );
return '';
}

/**
Expand All @@ -283,15 +310,15 @@ function use_ec2_iam_roles() {
* Instantiate a new AWS service client for the AWS SDK
* using the defined AWS key and secret
*
* @return Aws|WP_Error
* @return Aws
* @throws Exception
*/
function get_client() {
if ( ! $this->use_ec2_iam_roles() && ( ! $this->get_access_key_id() || ! $this->get_secret_access_key() ) ) {
return new WP_Error( 'access_keys_missing', sprintf( __( 'You must first <a href="%s">set your AWS access keys</a> to use this addon.', 'amazon-web-services' ), 'admin.php?page=' . $this->plugin_slug ) ); // xss ok
if ( $this->needs_access_keys() ) {
throw new Exception( sprintf( __( 'You must first <a href="%s">set your AWS access keys</a> to use this addon.', 'amazon-web-services' ), 'admin.php?page=' . $this->plugin_slug ) );
}

if ( is_null( $this->client ) ) {

$args = array();

if ( ! $this->use_ec2_iam_roles() ) {
Expand Down Expand Up @@ -362,9 +389,9 @@ public function get_addons( $unfiltered = false ) {
'utm_campaign' => 'WP+Offload+S3',
) ),
'addons' => array(
'amazon-s3-and-cloudfront-assets' => array(
'title' => __( 'Assets', 'amazon-web-services' ),
'url' => $this->dbrains_url( '/wp-offload-s3/doc/assets-addon/', array(
'amazon-s3-and-cloudfront-assets-pull' => array(
'title' => __( 'Assets Pull', 'amazon-web-services' ),
'url' => $this->dbrains_url( '/wp-offload-s3/doc/assets-pull-addon/', array(
'utm_campaign' => 'addons+install',
) ),
'label' => __( 'Feature', 'amazon-web-services' ),
Expand Down
82 changes: 72 additions & 10 deletions classes/aws-plugin-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,15 @@ function get_settings( $force = false ) {
* @return array
*/
function get_defined_settings( $force = false ) {
if ( is_null( $this->defined_settings ) || $force ) {
if ( ! defined( static::SETTINGS_CONSTANT ) ) {
$this->defined_settings = array();
$unserialized = array();
$class = get_class( $this );

if ( defined( "$class::SETTINGS_CONSTANT" ) ) {
$constant = static::SETTINGS_CONSTANT;
if ( defined( $constant ) ) {
$unserialized = maybe_unserialize( constant( $constant ) );
}
}
return $this->defined_settings;
}

if ( is_null( $this->defined_settings ) || $force ) {
$this->defined_settings = array();
$unserialized = maybe_unserialize( constant( static::SETTINGS_CONSTANT ) );
$unserialized = is_array( $unserialized ) ? $unserialized : array();

foreach ( $unserialized as $key => $value ) {
Expand All @@ -126,11 +123,76 @@ function get_defined_settings( $force = false ) {

$this->defined_settings[ $key ] = $value;
}

$this->listen_for_settings_constant_changes();

// Normalize the defined settings before saving, so we can detect when a real change happens.
ksort( $this->defined_settings );
update_site_option( 'as3cf_constant_' . static::SETTINGS_CONSTANT, $this->defined_settings );
}

return $this->defined_settings;
}

/**
* Subscribe to changes of the site option used to store the constant-defined settings.
*/
protected function listen_for_settings_constant_changes() {
if ( ! has_action( 'update_site_option_' . 'as3cf_constant_' . static::SETTINGS_CONSTANT, array( $this, 'settings_constant_changed' ) ) ) {
add_action( 'add_site_option_' . 'as3cf_constant_' . static::SETTINGS_CONSTANT, array( $this, 'settings_constant_added' ), 10, 3 );
add_action( 'update_site_option_' . 'as3cf_constant_' . static::SETTINGS_CONSTANT, array( $this, 'settings_constant_changed' ), 10, 4 );
}
}

/**
* Translate a settings constant option addition into a change.
*
* @param string $option Name of the option.
* @param mixed $value Value the option is being initialized with.
* @param int $network_id ID of the network.
*/
public function settings_constant_added( $option, $value, $network_id ) {
$db_settings = get_site_option( static::SETTINGS_KEY, array() );
$this->settings_constant_changed( $option, $value, $db_settings, $network_id );
}

/**
* Callback for announcing when settings-defined values change.
*
* @param string $option Name of the option.
* @param mixed $new_settings Current value of the option.
* @param mixed $old_settings Old value of the option.
* @param int $network_id ID of the network.
*/
public function settings_constant_changed( $option, $new_settings, $old_settings, $network_id ) {
$old_settings = $old_settings ?: array();

foreach ( $this->get_settings_whitelist() as $setting ) {
$old_value = isset( $old_settings[ $setting ] ) ? $old_settings[ $setting ] : null;
$new_value = isset( $new_settings[ $setting ] ) ? $new_settings[ $setting ] : null;

if ( $old_value !== $new_value ) {
/**
* Setting-specific hook for setting change.
*
* @param mixed $new_value
* @param mixed $old_value
* @param string $setting
*/
do_action( 'as3cf_constant_' . static::SETTINGS_CONSTANT . '_changed_' . $setting, $new_value, $old_value, $setting );

/**
* Generic hook for setting change.
*
* @param mixed $new_value
* @param mixed $old_value
* @param string $setting
*/
do_action( 'as3cf_constant_' . static::SETTINGS_CONSTANT . '_changed', $new_value, $old_value, $setting );
}
}
}

/**
* Filter the plugin settings array
*
Expand Down Expand Up @@ -229,7 +291,7 @@ function remove_defined_setting( $key ) {
/**
* Render a view template file
*
* @param $view View filename without the extension
* @param string $view View filename without the extension
* @param array $args Arguments to pass to the view
*/
function render_view( $view, $args = array() ) {
Expand Down
4 changes: 2 additions & 2 deletions classes/wp-aws-compatibility-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function is_parent_plugin_at_version( $version ) {
/**
* Get the compatibility error message
*
* @return string|void
* @return string|bool
*/
function get_error_msg() {
if ( is_null( $this->parent_plugin_slug ) ) {
Expand Down Expand Up @@ -521,4 +521,4 @@ public static function is_installing_or_updating_plugins() {
return self::$is_installing_or_updating_plugins;
}
}
}
}
Loading

0 comments on commit 54b55db

Please sign in to comment.