Skip to content

Instantly share code, notes, and snippets.

@einkoro
Last active January 29, 2020 15:32
Show Gist options
  • Save einkoro/4d702aaa930feb01ef98 to your computer and use it in GitHub Desktop.
Save einkoro/4d702aaa930feb01ef98 to your computer and use it in GitHub Desktop.
Must-use plugin to disable new user and password reset email notifications to administrators.
<?php
/**
* Plugin Name: WP Disable Admin User Notifications
* Plugin URI: http://bitpiston.com/
* Description: Disables new user and password reset notification emails sent to administrators.
* Author: BitPiston Studios
* Author URI: http://bitpiston.com/
* Version: 1.0
* Licence: BSD
*/
// Disable password reset emails
function wp_password_change_notification() {}
// Disable new user emails
/**
* Email login credentials to a newly-registered user.
*
* @since 2.0.0
*
* @param int $user_id User ID.
* @param string $plaintext_pass Optional. The user's plaintext password. Default empty.
*/
function wp_new_user_notification($user_id, $plaintext_pass = '') {
$user = get_userdata( $user_id );
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
if ( empty($plaintext_pass) )
return;
$message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
$message .= wp_login_url() . "\r\n";
wp_mail($user->user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment