Created
June 29, 2023 12:23
-
-
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!
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 | |
// 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