Skip to content

Commit 872c287

Browse files
Users: Preserve entered values on Network Add User form after validation errors
1 parent 94cab03 commit 872c287

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@
7777
}
7878
}
7979

80+
$username = '';
81+
$email = '';
82+
if ( isset( $_REQUEST['action'] ) && 'add-user' === $_REQUEST['action'] && ! empty( $add_user_errors ) && is_wp_error( $add_user_errors ) ) {
83+
if ( isset( $_POST['user'] ) && is_array( $_POST['user'] ) ) {
84+
$username = isset( $_POST['user']['username'] ) ? wp_unslash( $_POST['user']['username'] ) : '';
85+
$email = isset( $_POST['user']['email'] ) ? wp_unslash( $_POST['user']['email'] ) : '';
86+
}
87+
}
88+
8089
$message = '';
8190
if ( isset( $_GET['update'] ) ) {
8291
if ( 'added' === $_GET['update'] ) {
@@ -139,11 +148,11 @@
139148
<table class="form-table" role="presentation">
140149
<tr class="form-field form-required">
141150
<th scope="row"><label for="username"><?php _e( 'Username' ); ?> <?php echo wp_required_field_indicator(); ?></label></th>
142-
<td><input type="text" class="regular-text" name="user[username]" id="username" autocapitalize="none" autocorrect="off" maxlength="60" required="required" /></td>
151+
<td><input type="text" class="regular-text" name="user[username]" id="username" autocapitalize="none" autocorrect="off" maxlength="60" required="required" value="<?php echo esc_attr( $username ); ?>" /></td>
143152
</tr>
144153
<tr class="form-field form-required">
145154
<th scope="row"><label for="email"><?php _e( 'Email' ); ?> <?php echo wp_required_field_indicator(); ?></label></th>
146-
<td><input type="email" class="regular-text" name="user[email]" id="email" required="required" /></td>
155+
<td><input type="email" class="regular-text" name="user[email]" id="email" required="required" value="<?php echo esc_attr( $email ); ?>" /></td>
147156
</tr>
148157
<tr class="form-field">
149158
<td colspan="2" class="td-full"><?php _e( 'A password reset link will be sent to the user via email.' ); ?></td>

0 commit comments

Comments
 (0)