Pages

Jun 18, 2016

Prevent admin notification email for new registered users or user password changes

This is a simple method to prevent any mails to admin which normaly takes place on new user registration or user changes there password. Put this function on your Function.php file any where.

// prevent admin notification email for new registered users or user password changes



function conditional_mail_stop() {

    global $phpmailer;

    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $subject = array(
        sprintf(__('[%s] New User Registration'), $blogname),
        sprintf(__('[%s] Password Lost/Changed'), $blogname)
    );

    if ( in_array( $phpmailer->Subject, $subject ) )
        // empty $phpmailer class -> email cannot be send
        $phpmailer = new PHPMailer( true );

}

add_action( 'phpmailer_init', 'conditional_mail_stop' );

No comments: