Skip to content

Instantly share code, notes, and snippets.

Created November 18, 2017 12:19
Show Gist options
  • Save anonymous/9f22da1c3617a5393ade259d58108d99 to your computer and use it in GitHub Desktop.
Save anonymous/9f22da1c3617a5393ade259d58108d99 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Custom User Registration Notification
Description: Customized User registration notification
Version: 1.0
Author: Sarathlal N
Author URI: http://sarathlal.com
*/
// Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
global $wpdb, $wp_hasher;
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$message = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
// Generate something random for a password reset key.
$key = wp_generate_password( 20, false );
/** This action is documented in wp-login.php */
do_action( 'retrieve_password_key', $user->user_login, $key );
// Now insert the key, hashed, into the DB.
if ( empty( $wp_hasher ) ) {
require_once ABSPATH . WPINC . '/class-phpass.php';
$wp_hasher = new PasswordHash( 8, true );
}
$hashed = time() . ':' . $wp_hasher->HashPassword( $key );
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );
$message = __('Hi there,') . "\r\n\r\n";
$message .= sprintf(__("Welcome to %s & I have created an account for you."), get_option('blogname')) . "\r\n\r\n";
$message .= sprintf(__('Your Username : %s'), $user->user_login) . "\r\n\r\n";
$message .= __('To set your password, visit the following address:') . "\r\n\r\n";
$message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . "\r\n\r\n";
$message .= sprintf(__('If you face any problems, please contact me at %s.'), get_option('admin_email')) . "\r\n\r\n";
$message .= __('Thank You!');
wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment