WordPress.org

Make WordPress Core

Changeset 18131


Ignore:
Timestamp:
06/03/2011 06:59:12 PM (7 years ago)
Author:
ryan
Message:

Make user validation when adding a user via network admin consistent with adding a user elsewhere. Provide better feedback for validation problems. Props sorich87. fixes #17239

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/network/user-new.php

    r18092 r18131  
    3131        wp_die( __( 'You do not have permission to access this page.' ) );
    3232
    33     if ( is_array( $_POST['user'] ) == false )
     33    if ( ! is_array( $_POST['user'] ) )
    3434        wp_die( __( 'Cannot create an empty user.' ) );
     35
    3536    $user = $_POST['user'];
    36     if ( empty($user['username']) && empty($user['email']) )
    37         wp_die( __( 'Missing username and email.' ) );
    38     elseif ( empty($user['username']) )
    39         wp_die( __( 'Missing username.' ) );
    40     elseif ( empty($user['email']) )
    41         wp_die( __( 'Missing email.' ) );
    4237
    43     $password = wp_generate_password( 12, false);
    44     $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
     38    $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
     39    if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) {
     40        $add_user_errors = $user_details[ 'errors' ];
     41    } else {
     42        $password = wp_generate_password( 12, false);
     43        $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
    4544
    46     if ( false == $user_id )
    47         wp_die( __( 'Duplicated username or email address.' ) );
    48     else
    49         wp_new_user_notification( $user_id, $password );
    50        
    51     wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) );
    52     exit;
     45        if ( ! $user_id ) {
     46            $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
     47        } else {
     48            wp_new_user_notification( $user_id, $password );
     49            wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) );
     50            exit;
     51        }
     52    }
    5353}
    5454
     
    7171    foreach ( $messages as $msg )
    7272        echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
    73 } ?>
     73}
     74
     75if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { ?>
     76    <div class="error">
     77        <?php
     78            foreach ( $add_user_errors->get_error_messages() as $message )
     79                echo "<p>$message</p>";
     80        ?>
     81    </div>
     82<?php } ?>
    7483    <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post">
    7584    <table class="form-table">
Note: See TracChangeset for help on using the changeset viewer.