WordPress.org

Make WordPress Core

Ticket #17239: 17239.diff

File 17239.diff, 1.9 KB (added by sorich87, 7 years ago)

Use wpmu_validate_user_signup() in network/user-new.php

  • wp-admin/network/user-new.php

     
    3333        if ( is_array( $_POST['user'] ) == false )
    3434                wp_die( __( 'Cannot create an empty user.' ) );
    3535        $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.' ) );
    4236
    43         $password = wp_generate_password( 12, false);
     37        $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
     38
     39        if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) {
     40                $messages = implode( "<br />\n", $user_details[ 'errors' ]->get_error_messages() );
     41                wp_die( $messages );
     42        }
     43
     44        $password = wp_generate_password( 12, false );
    4445        $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
     46        wp_new_user_notification( $user_id, $password );
    4547
    46         if ( false == $user_id )
    47                 wp_die( __( 'Duplicated username or email address.' ) );
    48         else
    49                 wp_new_user_notification( $user_id, $password );
    50 
    5148        wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) );
    5249        exit;
    5350}
     
    7168        foreach ( $messages as $msg )
    7269                echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
    7370} ?>
    74         <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post">
     71        <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post">
    7572        <table class="form-table">
    7673                <tr class="form-field form-required">
    7774                        <th scope="row"><?php _e( 'Username' ) ?></th>
     
    9188</div>
    9289<?php
    9390require('../admin-footer.php');
    94 ?>
    95  No newline at end of file
     91?>