Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: WDW Disable Mail
- * Description: Disable email sending to all but a few emails. Helpful during development. The list of email ids allowed can be changed by editing plugin file
- * Author: ckchaudhary
- */
- add_filter( "wp_mail", "wdw_disable_wp_mail");
- function wdw_disable_wp_mail($details) {
- $allowed_emails = array(
- "developer@site.com",
- );
- $to = $details["to"];
- if(!is_array($to)) {
- $to = explode(",",$to);
- }
- $_to = array();
- foreach($to as $t) {
- if(in_array($t,$allowed_emails)){
- $_to[] = $t;
- }
- }
- $header = $details["headers"];
- $_header = array();
- if( !empty( $header ) ){
- //filter bbc
- foreach($header as $h) {
- $pos = strpos($h, "Bcc:");
- if($pos !== false) {
- $hh = str_replace("Bcc:","",$h);
- $hh = trim($hh);
- if(in_array($hh,$allowed_emails)){ // if this is in whitelist
- $_header[] = $h;
- }
- } else {
- $_header[] = $h;
- }
- }
- }
- $to = implode(",",$_to);
- $details["to"] = $to;
- $details["headers"] = $_header;
- return $details;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement