Skip to content

Commit

Permalink
Users: In wp_insert_user(), account for the `wp_pre_insert_user_dat…
Browse files Browse the repository at this point in the history
…a` filter returning empty data.

Props juliobox, SergeyBiryukov.
Fixes #47902.

git-svn-id: https://develop.svn.wordpress.org/trunk@45858 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Aug 20, 2019
1 parent 051aa38 commit 31a6309
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/user.php
Expand Up @@ -1794,6 +1794,10 @@ function wp_insert_user( $userdata ) {
*/ */
$data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null ); $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null );


if ( empty( $data ) || ! is_array( $data ) ) {
return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) );
}

if ( $update ) { if ( $update ) {
if ( $user_email !== $old_user_data->user_email ) { if ( $user_email !== $old_user_data->user_email ) {
$data['user_activation_key'] = ''; $data['user_activation_key'] = '';
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/tests/user.php
Expand Up @@ -961,6 +961,23 @@ public function test_wp_insert_user_with_invalid_user_id() {
); );


$this->assertWPError( $u ); $this->assertWPError( $u );
$this->assertSame( 'invalid_user_id', $u->get_error_code() );
}

/**
* @ticket 47902
*/
public function test_wp_insert_user_with_empty_data() {
global $wpdb;

add_filter( 'wp_pre_insert_user_data', '__return_empty_array' );

$u = self::factory()->user->create();

remove_filter( 'wp_pre_insert_user_data', '__return_empty_array' );

$this->assertWPError( $u );
$this->assertSame( 'empty_data', $u->get_error_code() );
} }


/** /**
Expand Down

0 comments on commit 31a6309

Please sign in to comment.