Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose filter to allow injecting S3 StreamWrapper cache instance #451

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion inc/class-s3-uploads.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,24 @@ public function register_stream_wrapper() {
if ( defined( 'S3_UPLOADS_USE_LOCAL' ) && S3_UPLOADS_USE_LOCAL ) {
stream_wrapper_register( 's3', 'S3_Uploads_Local_Stream_Wrapper', STREAM_IS_URL );
} else {
S3_Uploads_Stream_Wrapper::register( $this->s3() );
/**
* Filter: 's3_uploads_stream_wrapper_cache' - Filter S3 stream wrapper instance.
*
* Allow injecting custom cache services to S3 stream wrapper.
*
* @api \Aws\CacheInterface|null Current stream wrapper caching instance
* @api S3_Uploads Instance of this class.
*/
$s3_uploads_stream_wrapper_cache = apply_filters( 's3_uploads_stream_wrapper_cache', null, $this );

/**
* Ensure that filter returns usable class otherwise ignore it.
*/
if ( ! $s3_uploads_stream_wrapper_cache instanceof \Aws\CacheInterface || ! $s3_uploads_stream_wrapper_cache instanceof \Countable ) {
$s3_uploads_stream_wrapper_cache = null;
}

S3_Uploads_Stream_Wrapper::register( $this->s3(), 's3', $s3_uploads_stream_wrapper_cache );
$acl = defined( 'S3_UPLOADS_OBJECT_ACL' ) ? S3_UPLOADS_OBJECT_ACL : 'public-read';
stream_context_set_option( stream_context_get_default(), 's3', 'ACL', $acl );
}
Expand Down