Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Offload S3 Environment-Based Configuration
<?php
/**
* There are many possible ways to set this, but it can only be defined once.
*
* Using an environment variable by the same name
* define( 'WP_ENV', getenv( 'WP_ENV' ) );
*
* Matching the hostname
* define( 'WP_ENV', 'example.com' == $_SERVER['SERVER_NAME'] ? 'production' : 'staging' );
*/
// These settings will take effect if the current environment is not production.
if ( defined( 'WP_ENV' ) && WP_ENV != 'production' ) {
/**
* ALTERNATE/NON-EXISTENT CREDENTIALS
*
* Use alternate IAM credentials for limited permissions or use a placeholder to prevent Offload S3 from being able to upload new objects, remove existing objects, or read private objects.
*/
define( 'DBI_AWS_ACCESS_KEY_ID', 'ASDFASDFASDFASDFASDF' );
define( 'DBI_AWS_SECRET_ACCESS_KEY', 'ZXCVZXCVZXCVZXCVZXCVZXCVZXCVZXCVZXCVZXCV' );
/**
* ALTERNATE BUCKET
* Simply use a different bucket than is used in production.
*/
define( 'AS3CF_BUCKET', 'dev.media.example.com' );
/**
* Override any of the Offload S3 settings.
*/
define( 'WPOS3_SETTINGS', serialize( array(
// ONLY WRITE FROM PRODUCTION
// Prevent new objects from being automatically uploaded to S3.
'copy-to-s3' => false,
// ALTERNATE PATH
// Prefix the path in S3 with the current environment.
'object-prefix' => WP_ENV . '/wp-content/uploads/',
) ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment