Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbie4/f3ea09c9e3b8670598be1f89d70a7b4d to your computer and use it in GitHub Desktop.
Save herbie4/f3ea09c9e3b8670598be1f89d70a7b4d to your computer and use it in GitHub Desktop.
Bedrock mu-plugin: redirect all emails to specified email when on staging environment. Change the email as needed!
<?php
// Bedrock mu-plugin: redirect all emails to developer email on staging site
// Don't forget to set your email address!
add_filter( 'wp_mail', 'hhdev_staging_email_filter', 10, 1 );
function hhdev_staging_email_filter( $args ) {
if (getenv('WP_ENV') == 'staging') {
// Get original To address
$original_to = $args['to'];
// Send to developer only
$args['to'] = 'your@emailadres.nl';
// Show original To address in message for debug
$args['message'] = sprintf( "Staging environment: Message would originally be sent to: [%s]\n", $original_to ) . $args['message'];
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment