Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,7 @@ function wp_password_change_notification( $user ) {
* @since 4.3.0 The `$plaintext_pass` parameter was changed to `$notify`.
* @since 4.3.1 The `$plaintext_pass` parameter was deprecated. `$notify` added as a third parameter.
* @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created.
* @since 7.3.0 No notifications are sent if the user does not exist.
*
* @param int $user_id User ID.
* @param mixed $deprecated Not used.
Expand All @@ -2321,6 +2322,10 @@ function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' )

$user = get_userdata( $user_id );

if ( ! $user ) {
return;
}

/*
* 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.
Expand Down
47 changes: 47 additions & 0 deletions tests/phpunit/tests/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,53 @@ static function ( $email ) use ( &$message ) {
$this->assertFalse( str_ends_with( $reset_link_line, '>' ), 'The reset password link should not end with an angle bracket.' );
}

/**
* No email is sent, and the admin send filter does not run, for an ID that has no user.
*
* @ticket 66872
*
* @covers ::wp_new_user_notification
*/
public function test_wp_new_user_notification_does_nothing_for_nonexistent_user_id() {
$admin_filter = new MockAction();

add_filter( 'wp_send_new_user_notification_to_admin', array( $admin_filter, 'filter' ) );

wp_new_user_notification( PHP_INT_MAX, null, 'both' );

$this->assertSame( array(), tests_retrieve_phpmailer_instance()->mock_sent, 'No email should be sent.' );
$this->assertSame( 0, $admin_filter->get_call_count(), 'The admin send filter should not run.' );
}

/**
* No email is sent when edit_user() fails to create a user.
*
* @ticket 66872
*
* @covers ::edit_user
* @covers ::wp_new_user_notification
*/
public function test_edit_user_sends_no_notification_when_user_creation_fails() {
wp_set_current_user( self::$admin_id );

$_POST = array();
$_GET = array();
$_REQUEST = array();
$_POST['user_login'] = '@';
$_POST['email'] = 'empty-nicename@example.com';
$_POST['pass1'] = 'password';
$_POST['pass2'] = 'password';
$_POST['role'] = 'subscriber';

$response = edit_user();

$_POST = array();

$this->assertWPError( $response );
$this->assertSame( 'empty_user_nicename', $response->get_error_code() );
$this->assertSame( array(), tests_retrieve_phpmailer_instance()->mock_sent, 'No email should be sent.' );
}

/**
* Callback that returns 0.0.
*
Expand Down
Loading