Make WordPress Core

Changeset 45858 for trunk


Ignore:
Timestamp:
08/20/2019 05:25:02 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Users: In wp_insert_user(), account for the wp_pre_insert_user_data filter returning empty data.

Props juliobox, SergeyBiryukov.
Fixes #47902.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r45825 r45858  
    17951795    $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null );
    17961796
     1797    if ( empty( $data ) || ! is_array( $data ) ) {
     1798        return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) );
     1799    }
     1800
    17971801    if ( $update ) {
    17981802        if ( $user_email !== $old_user_data->user_email ) {
  • trunk/tests/phpunit/tests/user.php

    r45607 r45858  
    962962
    963963        $this->assertWPError( $u );
     964        $this->assertSame( 'invalid_user_id', $u->get_error_code() );
     965    }
     966
     967    /**
     968     * @ticket 47902
     969     */
     970    public function test_wp_insert_user_with_empty_data() {
     971        global $wpdb;
     972
     973        add_filter( 'wp_pre_insert_user_data', '__return_empty_array' );
     974
     975        $u = self::factory()->user->create();
     976
     977        remove_filter( 'wp_pre_insert_user_data', '__return_empty_array' );
     978
     979        $this->assertWPError( $u );
     980        $this->assertSame( 'empty_data', $u->get_error_code() );
    964981    }
    965982
Note: See TracChangeset for help on using the changeset viewer.