|
33 | 33 | check_admin_referer( 'add-user', '_wpnonce_add-user' );
|
34 | 34 |
|
35 | 35 | $user_details = null;
|
36 |
| - $user_email = wp_unslash( $_REQUEST['email'] ); |
| 36 | + $redirect_args = array(); |
| 37 | + foreach ( array( 'email', 'role', 'noconfirmation' ) as $redirect_arg ) { |
| 38 | + if ( isset( $_REQUEST[ $redirect_arg ] ) ) { |
| 39 | + $redirect_args[ $redirect_arg ] = $_REQUEST[ $redirect_arg ]; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + $user_email = wp_unslash( $_REQUEST['email'] ); |
37 | 44 |
|
38 | 45 | if ( str_contains( $user_email, '@' ) ) {
|
39 | 46 | $user_details = get_user_by( 'email', $user_email );
|
40 | 47 | } else {
|
41 | 48 | if ( current_user_can( 'manage_network_users' ) ) {
|
42 | 49 | $user_details = get_user_by( 'login', $user_email );
|
43 | 50 | } else {
|
44 |
| - wp_redirect( add_query_arg( array( 'update' => 'enter_email' ), 'user-new.php' ) ); |
| 51 | + $redirect_args['update'] = 'enter_email'; |
| 52 | + wp_redirect( add_query_arg( $redirect_args, 'user-new.php' ) ); |
45 | 53 | die();
|
46 | 54 | }
|
47 | 55 | }
|
48 | 56 |
|
49 | 57 | if ( ! $user_details ) {
|
50 |
| - wp_redirect( add_query_arg( array( 'update' => 'does_not_exist' ), 'user-new.php' ) ); |
| 58 | + $redirect_args['update'] = 'does_not_exist'; |
| 59 | + wp_redirect( add_query_arg( $redirect_args, 'user-new.php' ) ); |
51 | 60 | die();
|
52 | 61 | }
|
53 | 62 |
|
|
469 | 478 | <input name="action" type="hidden" value="adduser" />
|
470 | 479 | <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?>
|
471 | 480 |
|
| 481 | +<?php |
| 482 | +$adduser_email = isset( $_GET['email'] ) ? wp_unslash( $_GET['email'] ) : ''; |
| 483 | +$adduser_role = isset( $_GET['role'] ) ? sanitize_text_field( wp_unslash( $_GET['role'] ) ) : ''; |
| 484 | +$adduser_noconfirmation = isset( $_GET['noconfirmation'] ) ? wp_unslash( $_GET['noconfirmation'] ) : ''; |
| 485 | +if ( $adduser_role && ! array_key_exists( $adduser_role, get_editable_roles() ) ) { |
| 486 | + $adduser_role = ''; |
| 487 | +} |
| 488 | +?> |
472 | 489 | <table class="form-table" role="presentation">
|
473 | 490 | <tr class="form-field form-required">
|
474 | 491 | <th scope="row"><label for="adduser-email"><?php echo esc_html( $label ); ?></label></th>
|
475 |
| - <td><input name="email" type="<?php echo esc_attr( $type ); ?>" id="adduser-email" class="wp-suggest-user" value="" /></td> |
| 492 | + <td><input name="email" type="<?php echo esc_attr( $type ); ?>" id="adduser-email" class="wp-suggest-user" value="<?php echo esc_attr( $adduser_email ); ?>" /></td> |
476 | 493 | </tr>
|
477 | 494 | <tr class="form-field">
|
478 | 495 | <th scope="row"><label for="adduser-role"><?php _e( 'Role' ); ?></label></th>
|
479 | 496 | <td><select name="role" id="adduser-role">
|
480 |
| - <?php wp_dropdown_roles( get_option( 'default_role' ) ); ?> |
| 497 | + <?php |
| 498 | + $adduser_role_default = $adduser_role ? $adduser_role : get_option( 'default_role' ); |
| 499 | + wp_dropdown_roles( $adduser_role_default ); |
| 500 | + ?> |
481 | 501 | </select>
|
482 | 502 | </td>
|
483 | 503 | </tr>
|
484 | 504 | <?php if ( current_user_can( 'manage_network_users' ) ) { ?>
|
485 | 505 | <tr>
|
486 | 506 | <th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
|
487 | 507 | <td>
|
488 |
| - <input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" /> |
| 508 | + <input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" <?php checked( $adduser_noconfirmation, '1' ); ?> /> |
489 | 509 | <label for="adduser-noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation' ); ?></label>
|
490 | 510 | </td>
|
491 | 511 | </tr>
|
|
0 commit comments