Make WordPress Core

Ticket #31127: 31127.diff

File 31127.diff, 4.0 KB (added by ericlewis, 8 years ago)
  • src/wp-includes/ms-functions.php

     
    480480                // If registered more than two days ago, cancel registration and let this signup go through.
    481481                if ( $diff > 2 * DAY_IN_SECONDS )
    482482                        $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) );
    483                 else
    484                         $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.'));
     483                else {
     484                        // If the username has already been used for a signup on this site, disallow it.
     485                        $meta = maybe_unserialize($signup->meta);
     486                        if ( $meta['add_to_blog'] === get_current_blog_id() ) {
     487                                $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.'));
     488                        }
     489                }
    485490        }
    486491
    487492        $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) );
     
    490495                // If registered more than two days ago, cancel registration and let this signup go through.
    491496                if ( $diff > 2 * DAY_IN_SECONDS )
    492497                        $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) );
    493                 else
    494                         $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.'));
     498                else {
     499                        // If the email address has already been used for a signup on this site, disallow it.
     500                        $meta = maybe_unserialize($signup->meta);
     501                        if ( $meta['add_to_blog'] === get_current_blog_id() ) {
     502                                $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.'));
     503                        }
     504                }
     505
    495506        }
    496507
    497508        $result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors);
     
    719730        $key = substr( md5( time() . rand() . $user_email ), 0, 16 );
    720731        $meta = serialize($meta);
    721732
    722         $wpdb->insert( $wpdb->signups, array(
    723                 'domain' => '',
    724                 'path' => '',
    725                 'title' => '',
    726                 'user_login' => $user,
    727                 'user_email' => $user_email,
    728                 'registered' => current_time('mysql', true),
    729                 'activation_key' => $key,
    730                 'meta' => $meta
    731         ) );
     733        $existing_signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) );
    732734
     735        if ( $existing_signup === null ) {
     736                $wpdb->insert( $wpdb->signups, array(
     737                        'domain' => '',
     738                        'path' => '',
     739                        'title' => '',
     740                        'user_login' => $user,
     741                        'user_email' => $user_email,
     742                        'registered' => current_time('mysql', true),
     743                        'activation_key' => $key,
     744                        'meta' => $meta
     745                ) );
     746        } else {
     747
     748                // If there's already a signup for this email address,
     749                // note if the user should be signed up for another site.
     750                $diff = current_time( 'timestamp', true ) - mysql2date('U', $existing_signup->registered);
     751                // If registered less than two days ago, add another signup for the user.
     752                if ( $diff <= 2 * DAY_IN_SECONDS ) {
     753                        $new_signup_meta = maybe_unserialize( $existing_signup->meta );
     754                        if ( $new_signup_meta['add_to_blog'] != get_current_blog_id() ) {
     755                                if ( isset ( $new_signup_meta['other_blogs'] ) ) {
     756                                        $new_signup_meta['other_blogs'] = array();
     757                                }
     758                                $new_signup_meta['other_blogs'][] = maybe_unserialize( $meta );
     759                                $wpdb->update(
     760                                        $wpdb->signups,
     761                                        array( 'meta' => maybe_serialize( $new_signup_meta ) ),
     762                                        array( 'signup_id' => $existing_signup->signup_id )
     763                                );
     764                        }
     765                }
     766        }
     767
    733768        /**
    734769         * Fires after a user's signup information has been written to the database.
    735770         *
     
    20182053                add_user_to_blog( $blog_id, $user_id, $role );
    20192054                update_user_meta( $user_id, 'primary_blog', $blog_id );
    20202055        }
     2056        if ( ! empty( $meta['other_blogs'] ) ) {
     2057                foreach( $meta['other_blogs'] as $add_to_blog_info ) {
     2058                        $blog_id = $add_to_blog_info[ 'add_to_blog' ];
     2059                        $role = $add_to_blog_info[ 'new_role' ];
     2060                        add_user_to_blog( $blog_id, $user_id, $role );
     2061                }
     2062        }
    20212063}
    20222064
    20232065/**