WordPress.org

Make WordPress Core

Changeset 16586


Ignore:
Timestamp:
11/25/2010 11:12:33 AM (7 years ago)
Author:
PeteMall
Message:

Create new user form for site-users. See #15558

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/network/site-users.php

    r16584 r16586  
    2323$action = $wp_list_table->current_action();
    2424
    25 $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
    26 
    27 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    28 $_SERVER['REQUEST_URI'] = remove_query_arg(array('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']);
    29 
    3025$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    3126
     
    5651   
    5752    switch ( $action ) {
     53        case 'newuser':
     54            $user = $_POST['user'];
     55            if ( !is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) {
     56                $update = 'err_new';
     57            } else {
     58                $password = wp_generate_password( 12, false);
     59                $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
     60
     61                if ( false == $user_id ) {
     62                    $update = 'err_new_dup';
     63                } else {
     64                    wp_new_user_notification( $user_id, $password );
     65                    add_user_to_blog( $id, $user_id, $_POST['new_role'] );
     66                    $update = 'newuser';
     67                }
     68            }
     69            break;
     70
    5871        case 'adduser':
    5972            if ( !empty( $_POST['newuser'] ) ) {
    60                 $update = 'add';
     73                $update = 'adduser';
    6174                $newuser = $_POST['newuser'];               
    6275                $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
     
    152165if ( isset($_GET['update']) ) :
    153166    switch($_GET['update']) {
    154     case 'add':
     167    case 'adduser':
    155168        echo '<div id="message" class="updated"><p>' . __( 'User added.' ) . '</p></div>';
    156169        break;
     
    168181        break;
    169182    case 'remove':
    170         echo '<div id="message" class="updated fade"><p>' . __( 'User removed from this site.' ) . '</p></div>';
     183        echo '<div id="message" class="updated"><p>' . __( 'User removed from this site.' ) . '</p></div>';
    171184        break;
    172185    case 'err_remove':
    173186        echo '<div id="message" class="error"><p>' . __( 'Select a user to remove.' ) . '</p></div>';
     187        break;
     188    case 'newuser':
     189        echo '<div id="message" class="updated"><p>' . __( 'User created.' ) . '</p></div>';
     190        break;
     191    case 'err_new':
     192        echo '<div id="message" class="error"><p>' . __( 'Enter the username and email.' ) . '</p></div>';
     193        break;
     194    case 'err_new_dup':
     195        echo '<div id="message" class="error"><p>' . __( 'Duplicated username or email address.' ) . '</p></div>';
    174196        break;
    175197    }
     
    194216</form>
    195217
    196 <h3 id="add-new-user"><?php _e('Add Existing User') ?></h3>
    197 <p class="description"><?php _e( 'Enter the username of an existing user.' ) ?></p>
    198     <form action="site-users.php?action=adduser" id="adduser" method="post">
     218<h3 id="add-existing-user"><?php _e('Add Existing User') ?></h3>
     219<p><?php _e( 'Enter the username of an existing user on this network.' ) ?></p>
     220<form action="site-users.php?action=adduser" id="adduser" method="post">
    199221    <?php wp_nonce_field( 'edit-site' ); ?>
    200222    <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
     
    202224        <tr>
    203225            <th scope="row"><?php _e( 'Username' ); ?></th>
    204             <td><input type="text" name="newuser" id="newuser" /></td>
     226            <td><input type="text" class="regular-text" name="newuser" id="newuser" /></td>
    205227        </tr>
    206228        <tr>
     
    220242    </table>
    221243    <?php submit_button( __('Add User'), 'primary', 'add-user' ); ?>
    222     </form>
     244</form>
     245
     246<h3 id="add-new-user"><?php _e('Create New User') ?></h3>
     247<p><?php _e( 'Create a brand new user and add it to this site.' ) ?></p>
     248<form action="<?php echo network_admin_url('site-users.php?action=newuser'); ?>" id="newuser" method="post">
     249    <?php wp_nonce_field( 'edit-site' ); ?>
     250    <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
     251    <table class="form-table">
     252        <tr>
     253            <th scope="row"><?php _e( 'Username' ) ?></th>
     254            <td><input type="text" class="regular-text" name="user[username]" /></td>
     255        </tr>
     256        <tr>
     257            <th scope="row"><?php _e( 'Email' ) ?></th>
     258            <td><input type="text" class="regular-text" name="user[email]" /></td>
     259        </tr>
     260        <tr>
     261            <th scope="row"><?php _e( 'Role'); ?></th>
     262            <td><select name="new_role" id="new_role_0">
     263            <?php
     264            reset( $editblog_roles );
     265            foreach ( $editblog_roles as $role => $role_assoc ){
     266                $name = translate_user_role( $role_assoc['name'] );
     267                $selected = ( $role == $default_role ) ? 'selected="selected"' : '';
     268                echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
     269            }
     270            ?>
     271            </select></td>
     272        </tr>
     273        <tr class="form-field">
     274            <td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
     275        </tr>
     276    </table>
     277    <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?>
     278    <?php submit_button( __('Add User'), 'primary', 'add-user' ); ?>
     279</form>
    223280</div>
    224281<?php
Note: See TracChangeset for help on using the changeset viewer.