WordPress Environment Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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