Wordpress - Disable user registration password email
You can intercept this email before it is sent using the phpmailer_init
hook.
By default, this hook fires before any email is sent. In the function below, $phpmailer
will be an instance of PHPMailer, and you can use its methods to remove the default recipient and manipulate the email before it is sent.
add_action('phpmailer_init', 'wse199274_intercept_registration_email');
function wse199274_intercept_registration_email($phpmailer){
$admin_email = get_option( 'admin_email' );
# Intercept username and password email by checking subject line
if( strpos($phpmailer->Subject, 'Your username and password info') ){
# clear the recipient list
$phpmailer->ClearAllRecipients();
# optionally, send the email to the WordPress admin email
$phpmailer->AddAddress($admin_email);
}else{
#not intercepted
}
}
Actually it depends how you create the new user. If you do it from administration - Users - Add New you are right. In 4.3 unfortunatelly you cannot disable sending the notification email. But if you really want to create a new user without the email, there is a way.
You can create a small plugin where you'd create a new account by yourself via wp_insert_user
function, which doesn't send any email by default.
This function can be called like this.
wp_insert_user( $userdata );
Where the userdata
parameter is an array where you can pass all needed information.
$userdata = array(
'user_login' => 'login',
'user_pass' => 'password',
);
$user_id = wp_insert_user( $userdata ) ;
//On success
if ( ! is_wp_error( $user_id ) ) {
echo "User created : ". $user_id;
}
For more informations check codex here.
The wp_new_user_notification
function is pluggable, so you can override it by defining your own. You should be able to copy the entire function from wp-includes/pluggable.php
into your plugin (or functions.php
) and remove the line that sends out the email.