Unverified Commit 84910f4e authored by Joe Hoyle's avatar Joe Hoyle
Browse files

Merge branch 'master' of https://github.com/humanmade/S3-Uploads

parents d3c8d81f 41373f7e
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -37,8 +37,9 @@ Once you have `git clone`d the repo, or added it as a Git Submodule, add the fol
define( 'S3_UPLOADS_BUCKET', 'my-bucket' );
define( 'S3_UPLOADS_KEY', '' );
define( 'S3_UPLOADS_SECRET', '' );
define( 'S3_UPLOADS_REGION', '' ); // the s3 bucket region, required for Frankfurt and Beijing.
define( 'S3_UPLOADS_REGION', '' ); // the s3 bucket region, required for Frankfurt, Beijing & Sydney.
```
Please refer to this region list http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region for the S3_UPLOADS_REGION values.

You must then enable the plugin. To do this via WP-CLI use command:

@@ -147,6 +148,26 @@ By default, S3 Uploads will use the canonical S3 URIs for referencing the upload
// Define the base bucket URL (without trailing slash)
define( 'S3_UPLOADS_BUCKET_URL', 'https://your.origin.url.example/path' );
```
S3 Uploads' URL rewriting feature can be disabled if the current website does not require it, nginx proxy to s3 etc. In this case the plugin will only upload files to the S3 bucket.
```PHP
// disable URL rewriting alltogether
define( 'S3_UPLOADS_DISABLE_REPLACE_UPLOAD_URL', true );
```

S3 Object Permissions
=======

The object permission of files uploaded to S3 by this plugin can be controlled by setting the `S3_UPLOADS_OBJECT_ACL`
constant. The default setting if not specified is `public-read` to allow objects to be read by anyone. If you don't
want the uploads to be publicly readable then you can define `S3_UPLOADS_OBJECT_ACL` as one of `private` or `authenticated-read` 
in you wp-config file:

```PHP
// Set the S3 object permission to private
define('S3_UPLOADS_OBJECT_ACL', 'private');
```

For more information on S3 permissions please see the Amazon S3 permissions documentation.

Offline Development
=======
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
	},
	"type": "wordpress-plugin",
	"require": {
		"composer/installers": "~1.0"
		"composer/installers": "~1.0",
		"aws/aws-sdk-php": "~3.18"
	 }
}
+3 −2
Original line number Diff line number Diff line
@@ -159,6 +159,7 @@ class S3_Uploads_Stream_Wrapper
					try {
						$p = $this->params;
						$p['Body'] = '';
						$p = apply_filters( 's3_uploads_putObject_params', $p );
						$this->getClient()->putObject($p);
					} catch (Exception $e) {
						return $this->triggerError($e->getMessage());
@@ -212,7 +213,7 @@ class S3_Uploads_Stream_Wrapper
		 * Theses are the parameters passed to S3Client::putObject()
		 * See; http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_putObject
		 *
		 * @param array $params S3Client::putObject paramteres.
		 * @param array $params S3Client::putObject parameters.
		 */
		$params = apply_filters( 's3_uploads_putObject_params',  $params );

@@ -223,7 +224,7 @@ class S3_Uploads_Stream_Wrapper
			/**
			 * Action when a new object has been uploaded to s3.
			 *
			 * @param array  $params S3Client::putObject paramteres.
			 * @param array  $params S3Client::putObject parameters.
			 */
			do_action( 's3_uploads_putObject', $params );

+6 −1
Original line number Diff line number Diff line
@@ -105,7 +105,12 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command {
		$old_upload_dir = $instance->get_original_upload_dir();
		$upload_dir = wp_upload_dir();

		$files = array( get_post_meta( $args[0], '_wp_attached_file', true ) );
		$files         = array();
		$attached_file = get_post_meta( $args[0], '_wp_attached_file', true );

		if ( ! empty( $attached_file ) ) {
			$files[] = $attached_file;
		}

		$meta_data = wp_get_attachment_metadata( $args[0] );

+18 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ class S3_Uploads {
		add_filter( 'wp_image_editors', array( $this, 'filter_editors' ), 9 );
		add_filter( 'wp_delete_file', array( $this, 'wp_filter_delete_file' ) );
		add_filter( 'wp_read_image_metadata', array( $this, 'wp_filter_read_image_metadata' ), 10, 2 );
		add_filter( 'wp_resource_hints', array( $this, 'wp_filter_resource_hints' ), 10, 2 );
		remove_filter( 'admin_notices', 'wpthumb_errors' );

		add_action( 'wp_handle_sideload_prefilter', array( $this, 'filter_sideload_move_temp_file_to_s3' ) );
@@ -73,7 +74,8 @@ class S3_Uploads {
			stream_wrapper_register( 's3', 'S3_Uploads_Local_Stream_Wrapper', STREAM_IS_URL );
		} else {
			S3_Uploads_Stream_Wrapper::register( $this->s3() );
			stream_context_set_option( stream_context_get_default(), 's3', 'ACL', 'public-read' );
			$objectAcl = defined( 'S3_UPLOADS_OBJECT_ACL' ) ? S3_UPLOADS_OBJECT_ACL : 'public-read';
			stream_context_set_option( stream_context_get_default(), 's3', 'ACL', $objectAcl );
		}

		stream_context_set_option( stream_context_get_default(), 's3', 'seekable', true );
@@ -236,6 +238,21 @@ class S3_Uploads {
		return $meta;
	}

	/**
	 * Add the DNS address for the S3 Bucket to list for DNS prefetch.
	 *
	 * @param $hints
	 * @param $relation_type
	 * @return array
	 */
	function wp_filter_resource_hints( $hints, $relation_type ) {
		if ( 'dns-prefetch' === $relation_type ) {
			$hints[] = $this->get_s3_url();
		}

		return $hints;
	}

	/**
	 * Get a local copy of the file.
	 *
Loading