jeudi 29 janvier 2015

User registration and activation email in custom form


I have implemented a custom login and registration form in WP as mentioned here. User can now register but can not login until admin approves that user from backend.


I need to implement admin notification email for new user registration as well as user notification email admin approves it from backend. I have tried below code in my registration form to send email but that does not seem to work. Moreover the standard email keeps sending.



/ Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
$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);

if ( empty($plaintext_pass) )
return;

$message = __('Hi there,') . "\r\n\r\n";
$message .= sprintf(__("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n";
$message .= wp_login_url() . "\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n\r\n";
$message .= sprintf(__('If you have any problems, please contact me at %s.'), get_option('admin_email')) . "\r\n\r\n";
$message .= __('Adios!');

wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);

}
}


For user registration approval I am using this plugin.


How can I send email when user registers using my custom form and notify user when admin approves.


Thanks.





Aucun commentaire:

Enregistrer un commentaire