Make WordPress Core

Changeset 48315


Ignore:
Timestamp:
07/05/2020 11:19:35 AM (4 years ago)
Author:
ocean90
Message:

Multisite: Delete the signup entry when a user is deleted from the database.

When a user has registered with incorrect data and got the account deleted immediately, it currently wasn't possible to register with the same login or email address again due to the existing signup entry. They had to wait for two days until the entry gets automatically deleted. Now the associated signup entry gets deleted as part of the account deletion.

Fixes #43232.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-default-filters.php

    r48121 r48315  
    3232add_action( 'network_user_new_created_user', 'wp_send_new_user_notifications' );
    3333add_filter( 'sanitize_user', 'strtolower' );
     34add_action( 'deleted_user', 'wp_delete_signup_on_user_delete', 10, 3 );
    3435
    3536// Roles.
  • trunk/src/wp-includes/ms-functions.php

    r48121 r48315  
    12751275        'meta'     => $meta,
    12761276    );
     1277}
     1278
     1279/**
     1280 * Deletes am associated signup entry when a user is deleted from the database.
     1281 *
     1282 * @since 5.5.0
     1283 *
     1284 * @param int      $id       ID of the user to delete.
     1285 * @param int|null $reassign ID of the user to reassign posts and links to.
     1286 * @param WP_User  $user     User object.
     1287 */
     1288function wp_delete_signup_on_user_delete( $id, $reassign, $user ) {
     1289    global $wpdb;
     1290
     1291    $wpdb->delete( $wpdb->signups, array( 'user_login' => $user->user_login ) );
    12771292}
    12781293
  • trunk/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php

    r48121 r48315  
    8585        public function test_should_fail_for_existing_signup_with_same_username() {
    8686            // Don't send notifications.
    87             add_filter( 'wpmu_signup_user_notification', '__return_true' );
    88             wpmu_signup_user( 'foo123', 'foo@example.com' );
    89             remove_filter( 'wpmu_signup_user_notification', '__return_true' );
     87            add_filter( 'wpmu_signup_user_notification', '__return_false' );
     88            wpmu_signup_user( 'foo123', 'foo@example.com' );
     89            remove_filter( 'wpmu_signup_user_notification', '__return_false' );
    9090
    9191            $v = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
     
    9595        public function test_should_not_fail_for_existing_signup_with_same_username_if_signup_is_old() {
    9696            // Don't send notifications.
    97             add_filter( 'wpmu_signup_user_notification', '__return_true' );
    98             wpmu_signup_user( 'foo123', 'foo@example.com' );
    99             remove_filter( 'wpmu_signup_user_notification', '__return_true' );
     97            add_filter( 'wpmu_signup_user_notification', '__return_false' );
     98            wpmu_signup_user( 'foo123', 'foo@example.com' );
     99            remove_filter( 'wpmu_signup_user_notification', '__return_false' );
    100100
    101101            global $wpdb;
     
    109109        public function test_should_fail_for_existing_signup_with_same_email() {
    110110            // Don't send notifications.
    111             add_filter( 'wpmu_signup_user_notification', '__return_true' );
    112             wpmu_signup_user( 'foo123', 'foo@example.com' );
    113             remove_filter( 'wpmu_signup_user_notification', '__return_true' );
     111            add_filter( 'wpmu_signup_user_notification', '__return_false' );
     112            wpmu_signup_user( 'foo123', 'foo@example.com' );
     113            remove_filter( 'wpmu_signup_user_notification', '__return_false' );
    114114
    115115            $v = wpmu_validate_user_signup( 'foo2', 'foo@example.com' );
     
    119119        public function test_should_not_fail_for_existing_signup_with_same_email_if_signup_is_old() {
    120120            // Don't send notifications.
    121             add_filter( 'wpmu_signup_user_notification', '__return_true' );
    122             wpmu_signup_user( 'foo123', 'foo@example.com' );
    123             remove_filter( 'wpmu_signup_user_notification', '__return_true' );
     121            add_filter( 'wpmu_signup_user_notification', '__return_false' );
     122            wpmu_signup_user( 'foo123', 'foo@example.com' );
     123            remove_filter( 'wpmu_signup_user_notification', '__return_false' );
    124124
    125125            global $wpdb;
     
    129129            $v = wpmu_validate_user_signup( 'foo2', 'foo2@example.com' );
    130130            $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() );
     131        }
     132
     133        /**
     134         * @ticket 43232
     135         */
     136        public function test_should_not_fail_for_data_used_by_a_deleted_user() {
     137            global $wpdb;
     138
     139            // Don't send notifications.
     140            add_filter( 'wpmu_signup_user_notification', '__return_false' );
     141            add_filter( 'wpmu_welcome_user_notification', '__return_false' );
     142
     143            // Signup, activate and delete new user.
     144            wpmu_signup_user( 'foo123', 'foo@example.com' );
     145            $key  = $wpdb->get_var( "SELECT activation_key FROM $wpdb->signups WHERE user_login = 'foo123'" );
     146            $user = wpmu_activate_signup( $key );
     147            wpmu_delete_user( $user['user_id'] );
     148
     149            $valid = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
     150
     151            remove_filter( 'wpmu_signup_user_notification', '__return_false' );
     152            remove_filter( 'wpmu_signup_user_notification', '__return_false' );
     153
     154            $this->assertNotContains( 'user_name', $valid['errors']->get_error_codes() );
     155            $this->assertNotContains( 'user_email', $valid['errors']->get_error_codes() );
    131156        }
    132157
Note: See TracChangeset for help on using the changeset viewer.