Skip to content

Instantly share code, notes, and snippets.

@aaemnnosttv
Created January 27, 2020 09:06
Show Gist options
  • Save aaemnnosttv/5c34946182386c32a2196d3425049801 to your computer and use it in GitHub Desktop.
Save aaemnnosttv/5c34946182386c32a2196d3425049801 to your computer and use it in GitHub Desktop.
WordPress Environment Configuration
<?php
/**
* Plugin Name: Environment Configuration
* Description: Enforces environment-specific settings for the current environment.
*/
namespace App\Environment;
function disable_plugins( $disable_plugins ) {
add_filter(
'option_active_plugins',
function ( $active_plugins ) use ( $disable_plugins ) {
return array_diff( $active_plugins, (array) $disable_plugins );
}
);
}
function use_mailtrap( \PHPMailer $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.mailtrap.io';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 2525;
$phpmailer->Username = getenv( 'MAILTRAP_USER' );
$phpmailer->Password = getenv( 'MAILTRAP_PASS' );
}
call_user_func(
function ( $env ) {
if ( 'production' !== $env ) {
// Disable transactional email plugin.
disable_plugins( 'mailgun/mailgun.php' );
// Send emails to Mailtrap.
add_action( 'phpmailer_init', __NAMESPACE__ . '\\use_mailtrap' );
}
},
defined( 'WP_ENV' ) ? WP_ENV : 'development'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment