WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#15056 closed enhancement (worksforme)

New hook for wp_new_user_notification()

Reported by: Veraxus Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: General Keywords: hook, filter, registration, email
Focuses: Cc:

Description (last modified by Denis-de-Bernardy)

I'd like to be able to customize the new user's registration email, but this requires an additional filter hook in wp_new_user_notification(). The hook could be something as straightforward as this:
==================================================================

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);

	// 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);

	$message  = sprintf(__('New user registration on your site %s:'), $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'), $blogname), $message);

	if ( empty($plaintext_pass) )
		return;

	$message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
	$message .= wp_login_url() . "\r\n";

        $message = apply_filters('new_user_email_message',$message);

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

}

Change History (3)

#1 @Denis-de-Bernardy
9 years ago

  • Description modified (diff)

#2 @scribu
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

wp_new_user_notification() is pluggable, which means you can redefine it and make it do whatever you want.

Note: See TracTickets for help on using tickets.