Make WordPress Core

Changeset 12778


Ignore:
Timestamp:
01/20/2010 09:58:13 PM (15 years ago)
Author:
ryan
Message:

Add email and login dupe checking down into wp_insert_user(). Tidy up user-new.php. see #11644

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/menu.php

    r12757 r12778  
    131131    $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
    132132    $submenu['users.php'][5] = array(__('Authors & Users'), 'edit_users', 'users.php');
    133     if ( !is_multisite() )
    134         $submenu['users.php'][10] = array(_x('Add New', 'user'), 'create_users', 'user-new.php');
    135     elseif ( is_super_admin() || get_site_option( 'add_new_users' ) )
    136         $submenu['users.php'][10] = array(__('Add New') . ' <strong>*</strong>', 'create_users', 'ms-options.php#addnewusers');
     133    $submenu['users.php'][10] = array(_x('Add New', 'user'), 'create_users', 'user-new.php');
    137134
    138135    $submenu['users.php'][15] = array(__('Your Profile'), 'read', 'profile.php');
  • trunk/wp-admin/user-new.php

    r12764 r12778  
    6363            $username = $user_details->user_login;
    6464            $user_id = $user_details->ID;
    65             if ( ($username != null && is_site_admin( $username ) == false ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
     65            if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
    6666                $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
    6767            } else {
    68                 if ( isset( $_POST[ 'noconfirmation' ] ) && is_site_admin() ) {
     68                if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
    6969                    add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
    7070                    $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
     
    185185?>
    186186<table class="form-table">
    187 <?php if ( !is_multisite() ) { ?>
    188187    <tr class="form-field form-required">
    189188        <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label>
     
    191190        <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td>
    192191    </tr>
    193     <tr class="form-field">
    194         <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
    195         <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td>
    196     </tr>
    197     <tr class="form-field">
    198         <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
    199         <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td>
    200     </tr>
    201192    <tr class="form-field form-required">
    202193        <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
    203194        <td><input name="email" type="text" id="email" value="<?php echo esc_attr($new_user_email); ?>" /></td>
    204195    </tr>
     196<?php if ( !is_multisite() ) { ?>
     197    <tr class="form-field">
     198        <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
     199        <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td>
     200    </tr>
     201    <tr class="form-field">
     202        <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
     203        <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td>
     204    </tr>
    205205    <tr class="form-field">
    206206        <th scope="row"><label for="url"><?php _e('Website') ?></label></th>
    207207        <td><input name="url" type="text" id="url" class="code" value="<?php echo esc_attr($new_user_uri); ?>" /></td>
    208208    </tr>
    209 
    210209<?php if ( apply_filters('show_password_fields', true) ) : ?>
    211210    <tr class="form-field form-required">
     
    224223    </tr>
    225224<?php endif; ?>
    226 <?php } else { // multisite ?>
    227     <tr class="form-field form-required">
    228         <th scope="row"><label for="user_login"><?php _e('Username (required)') ?></label><input name="action" type="hidden" id="action" value="adduser" /></th>
    229         <td ><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" aria-required="true" /></td>
    230     </tr>
    231     <tr class="form-field form-required">
    232         <th scope="row"><label for="email"><?php _e('E-mail (required)') ?></label></th>
    233         <td><input name="email" type="text" id="email" value="<?php echo $new_user_email; ?>" /></td>
    234     </tr>
    235 <?php } ?>
     225<?php } // !is_multisite ?>
    236226    <tr class="form-field">
    237227        <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
     
    245235        </td>
    246236    </tr>
    247 
    248237    <?php if ( is_multisite() && is_super_admin() ) { ?>
    249     <tr class="form-field">
     238    <tr>
    250239        <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
    251         <td><input name="noconfirmation" type="checkbox" id="noconfirmation" value="1" /> <label for="noconfirmation"><?php _e( 'Site administrators can add a user without sending the confirmation email.' ); ?></label></td>
     240        <td><label for="noconfirmation"><input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" /> <?php _e( 'Site administrators can add a user without sending the confirmation email.' ); ?></label></td>
    252241    </tr>
    253242    <?php } ?>
  • trunk/wp-includes/capabilities.php

    r12770 r12778  
    981981            $caps[] = $cap;
    982982        break;
     983    case 'create_users':
     984        if ( is_multisite() && !get_site_option( 'add_new_users' ) )
     985            $caps[] = 'do_not_allow';
     986        else
     987            $caps[] = $cap;
     988        break;
    983989    default:
    984990        // If no meta caps match, return the original cap.
  • trunk/wp-includes/ms-functions.php

    r12776 r12778  
    12231223function wpmu_create_user( $user_name, $password, $email) {
    12241224    $user_name = preg_replace( "/\s+/", '', sanitize_user( $user_name, true ) );
    1225     if ( username_exists($user_name) )
     1225
     1226    $user_id = wp_create_user( $user_name, $password, $email );
     1227    if ( is_wp_error($user_id) )
    12261228        return false;
    12271229
    1228     // Check if the email address has been used already.
    1229     if ( email_exists($email) )
    1230         return false;
    1231 
    1232     $user_id = wp_create_user( $user_name, $password, $email );
    12331230    $user = new WP_User($user_id);
    12341231
  • trunk/wp-includes/registration.php

    r12733 r12778  
    123123    $user_login = trim($user_login);
    124124
    125     if ( empty($user_login) ) {
     125    if ( empty($user_login) )
    126126        return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
    127     }
     127
     128    if ( !$update && username_exists( $user_login ) )
     129        return new WP_Error('existing_user_login', __('This username is already registered.') );
    128130
    129131    if ( empty($user_nicename) )
     
    138140        $user_email = '';
    139141    $user_email = apply_filters('pre_user_email', $user_email);
     142
     143    if ( !$update && email_exists($user_email) )
     144        return new WP_Error('existing_user_email', __('This email address is already registered.') );
    140145
    141146    if ( empty($display_name) )
Note: See TracChangeset for help on using the changeset viewer.