Advertisement
webdwall

WP Disable Emails

Sep 19th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: WDW Disable Mail
  4. * 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
  5. * Author: ckchaudhary
  6. */
  7.  
  8. add_filter( "wp_mail", "wdw_disable_wp_mail");
  9. function wdw_disable_wp_mail($details) {
  10.     $allowed_emails = array(   
  11.         "developer@site.com",
  12.     );
  13.    
  14.     $to = $details["to"];
  15.     if(!is_array($to)) {
  16.         $to = explode(",",$to);
  17.     }
  18.     $_to = array();
  19.     foreach($to as $t) {
  20.         if(in_array($t,$allowed_emails)){
  21.             $_to[] = $t;
  22.         }
  23.     }
  24.    
  25.     $header = $details["headers"];
  26.     $_header = array();
  27.     if( !empty( $header ) ){
  28.         //filter bbc
  29.         foreach($header as $h) {
  30.             $pos = strpos($h, "Bcc:");
  31.             if($pos !== false) {
  32.                 $hh = str_replace("Bcc:","",$h);
  33.                 $hh = trim($hh);
  34.                 if(in_array($hh,$allowed_emails)){ // if this is in whitelist
  35.                     $_header[] = $h;
  36.                 }
  37.             } else {
  38.                 $_header[] = $h;
  39.             }
  40.         }
  41.     }
  42.    
  43.     $to = implode(",",$_to);
  44.  
  45.     $details["to"] = $to;
  46.     $details["headers"] = $_header;
  47.    
  48.     return $details;
  49. }
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement