Make WordPress Core

Ticket #35428: ms-functions.php.2.patch

File ms-functions.php.2.patch, 2.5 KB (added by pbearne, 8 years ago)

moved filter to the setting of $user_already_exists

  • wp-includes/ms-functions.php

     
    952952function wpmu_activate_signup($key) {
    953953        global $wpdb;
    954954
    955         $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) );
     955        $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key ) );
    956956
    957         if ( empty( $signup ) )
     957        if ( empty( $signup ) ) {
    958958                return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) );
     959        }
    959960
    960961        if ( $signup->active ) {
    961                 if ( empty( $signup->domain ) )
     962                if ( empty( $signup->domain ) ) {
    962963                        return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup );
    963                 else
     964                } else {
    964965                        return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup );
     966                }
    965967        }
    966968
    967         $meta = maybe_unserialize($signup->meta);
     969        $meta     = maybe_unserialize( $signup->meta );
    968970        $password = wp_generate_password( 12, false );
    969971
    970         $user_id = username_exists($signup->user_login);
     972        $user_id = username_exists( $signup->user_login );
    971973
     974        if ( ! $user_id ) {
     975                $user_id = wpmu_create_user( $signup->user_login, $password, $signup->user_email );
     976        } else {
     977                $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) );
     978        }
     979                /**
     980                 * allow the suppression of errors if user already exists.
     981                 *
     982                 * @since 4.5
     983                 *
     984                 * @param WP_Error
     985                 */
     986                $user_already_exists = apply_filters('_wpmu_activate_existing_error_', true, $signup  );
     987        }
    972988        if ( ! $user_id )
    973                 $user_id = wpmu_create_user($signup->user_login, $password, $signup->user_email);
    974         else
    975                 $user_already_exists = true;
    976 
    977         if ( ! $user_id )
    978989                return new WP_Error('create_user', __('Could not create user'), $signup);
    979990
    980991        $now = current_time('mysql', true);
     
    981992
    982993        if ( empty($signup->domain) ) {
    983994                $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) );
     995               
     996                if ( isset( $user_already_exists ) ){
     997                        return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup, get_defined_vars() );
     998                }
    984999
    985                 if ( isset( $user_already_exists ) )
    986                         return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup);
    987 
    9881000                /**
    9891001                 * Fires immediately after a new user is activated.
    9901002                 *