WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp new user notification

Description

Notify the blog admin of a new user, normally via email and also send an email with login/password to the new user.

This function can be replaced via plugins. If plugins do not redefine these functions, then this will be used instead.

Usage

<?php wp_new_user_notification$user_id$plaintext_pass ?>

Parameters

$user_id
(integer) (required) User ID
Default: None
$plaintext_pass
(string) (optional) The user's plaintext password
Default: ''

Note: If password is not passed to function, the newly registered user will not receive their welcome email.

Return Values

(void) 
This function does not return a value.

Examples

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

Notes

  • This function can be replaced via plugins. If plugins do not redefine these functions, then this will be used instead.

Change Log

Source File

wp_new_user_notification() is located in wp-includes/pluggable.php.

Related

See also index of Function Reference and index of Template Tags.