Skip to content

Instantly share code, notes, and snippets.

@aaemnnosttv
Created March 24, 2017 12:02
Show Gist options
  • Save aaemnnosttv/785ac5ab5c6efbf48cbfe9a9e5f32451 to your computer and use it in GitHub Desktop.
Save aaemnnosttv/785ac5ab5c6efbf48cbfe9a9e5f32451 to your computer and use it in GitHub Desktop.
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