| 1 | Index: wp-admin/network/user-new.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-admin/network/user-new.php (revision 18028) |
|---|
| 4 | +++ wp-admin/network/user-new.php (working copy) |
|---|
| 5 | @@ -33,21 +33,18 @@ |
|---|
| 6 | if ( is_array( $_POST['user'] ) == false ) |
|---|
| 7 | wp_die( __( 'Cannot create an empty user.' ) ); |
|---|
| 8 | $user = $_POST['user']; |
|---|
| 9 | - if ( empty($user['username']) && empty($user['email']) ) |
|---|
| 10 | - wp_die( __( 'Missing username and email.' ) ); |
|---|
| 11 | - elseif ( empty($user['username']) ) |
|---|
| 12 | - wp_die( __( 'Missing username.' ) ); |
|---|
| 13 | - elseif ( empty($user['email']) ) |
|---|
| 14 | - wp_die( __( 'Missing email.' ) ); |
|---|
| 15 | |
|---|
| 16 | - $password = wp_generate_password( 12, false); |
|---|
| 17 | + $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] ); |
|---|
| 18 | + |
|---|
| 19 | + if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) { |
|---|
| 20 | + $messages = implode( "<br />\n", $user_details[ 'errors' ]->get_error_messages() ); |
|---|
| 21 | + wp_die( $messages ); |
|---|
| 22 | + } |
|---|
| 23 | + |
|---|
| 24 | + $password = wp_generate_password( 12, false ); |
|---|
| 25 | $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) ); |
|---|
| 26 | + wp_new_user_notification( $user_id, $password ); |
|---|
| 27 | |
|---|
| 28 | - if ( false == $user_id ) |
|---|
| 29 | - wp_die( __( 'Duplicated username or email address.' ) ); |
|---|
| 30 | - else |
|---|
| 31 | - wp_new_user_notification( $user_id, $password ); |
|---|
| 32 | - |
|---|
| 33 | wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) ); |
|---|
| 34 | exit; |
|---|
| 35 | } |
|---|
| 36 | @@ -71,7 +68,7 @@ |
|---|
| 37 | foreach ( $messages as $msg ) |
|---|
| 38 | echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; |
|---|
| 39 | } ?> |
|---|
| 40 | - <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post"> |
|---|
| 41 | + <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post"> |
|---|
| 42 | <table class="form-table"> |
|---|
| 43 | <tr class="form-field form-required"> |
|---|
| 44 | <th scope="row"><?php _e( 'Username' ) ?></th> |
|---|
| 45 | @@ -91,4 +88,4 @@ |
|---|
| 46 | </div> |
|---|
| 47 | <?php |
|---|
| 48 | require('../admin-footer.php'); |
|---|
| 49 | -?> |
|---|
| 50 | \ No newline at end of file |
|---|
| 51 | +?> |
|---|