wp/wp-admin/user-new.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    32 if ( isset( $_REQUEST['action'] ) && 'adduser' === $_REQUEST['action'] ) {
    32 if ( isset( $_REQUEST['action'] ) && 'adduser' === $_REQUEST['action'] ) {
    33 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
    33 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
    34 
    34 
    35 	$user_details = null;
    35 	$user_details = null;
    36 	$user_email   = wp_unslash( $_REQUEST['email'] );
    36 	$user_email   = wp_unslash( $_REQUEST['email'] );
    37 	if ( false !== strpos( $user_email, '@' ) ) {
    37 	if ( str_contains( $user_email, '@' ) ) {
    38 		$user_details = get_user_by( 'email', $user_email );
    38 		$user_details = get_user_by( 'email', $user_email );
    39 	} else {
    39 	} else {
    40 		if ( current_user_can( 'manage_network_users' ) ) {
    40 		if ( current_user_can( 'manage_network_users' ) ) {
    41 			$user_details = get_user_by( 'login', $user_email );
    41 			$user_details = get_user_by( 'login', $user_email );
    42 		} else {
    42 		} else {
   108 			 * @param array  $role        Array containing role information for the invited user.
   108 			 * @param array  $role        Array containing role information for the invited user.
   109 			 * @param string $newuser_key The key of the invitation.
   109 			 * @param string $newuser_key The key of the invitation.
   110 			 */
   110 			 */
   111 			do_action( 'invite_user', $user_id, $role, $newuser_key );
   111 			do_action( 'invite_user', $user_id, $role, $newuser_key );
   112 
   112 
   113 			$switched_locale = switch_to_locale( get_user_locale( $user_details ) );
   113 			$switched_locale = switch_to_user_locale( $user_id );
   114 
   114 
   115 			if ( '' !== get_option( 'blogname' ) ) {
   115 			if ( '' !== get_option( 'blogname' ) ) {
   116 				$site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
   116 				$site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
   117 			} else {
   117 			} else {
   118 				$site_title = parse_url( home_url(), PHP_URL_HOST );
   118 				$site_title = parse_url( home_url(), PHP_URL_HOST );
   296 	)
   296 	)
   297 );
   297 );
   298 
   298 
   299 get_current_screen()->set_help_sidebar(
   299 get_current_screen()->set_help_sidebar(
   300 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   300 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   301 	'<p>' . __( '<a href="https://wordpress.org/support/article/users-add-new-screen/">Documentation on Adding New Users</a>' ) . '</p>' .
   301 	'<p>' . __( '<a href="https://wordpress.org/documentation/article/users-add-new-screen/">Documentation on Adding New Users</a>' ) . '</p>' .
   302 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   302 	'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
   303 );
   303 );
   304 
   304 
   305 wp_enqueue_script( 'wp-ajax-response' );
   305 wp_enqueue_script( 'wp-ajax-response' );
   306 wp_enqueue_script( 'user-profile' );
   306 wp_enqueue_script( 'user-profile' );
   307 
   307 
   379 	_e( 'Add Existing User' );
   379 	_e( 'Add Existing User' );
   380 }
   380 }
   381 ?>
   381 ?>
   382 </h1>
   382 </h1>
   383 
   383 
   384 <?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?>
   384 <?php
   385 	<div class="error">
   385 if ( isset( $errors ) && is_wp_error( $errors ) ) :
   386 		<ul>
   386 	$error_message = '';
   387 		<?php
   387 	foreach ( $errors->get_error_messages() as $err ) {
   388 		foreach ( $errors->get_error_messages() as $err ) {
   388 		$error_message .= "<li>$err</li>\n";
   389 			echo "<li>$err</li>\n";
   389 	}
   390 		}
   390 	wp_admin_notice(
   391 		?>
   391 		'<ul>' . $error_message . '</ul>',
   392 		</ul>
   392 		array(
   393 	</div>
   393 			'additional_classes' => array( 'error' ),
   394 	<?php
   394 			'paragraph_wrap'     => false,
       
   395 		)
       
   396 	);
   395 endif;
   397 endif;
   396 
   398 
   397 if ( ! empty( $messages ) ) {
   399 if ( ! empty( $messages ) ) {
   398 	foreach ( $messages as $msg ) {
   400 	foreach ( $messages as $msg ) {
   399 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
   401 		wp_admin_notice(
       
   402 			$msg,
       
   403 			array(
       
   404 				'id'                 => 'message',
       
   405 				'additional_classes' => array( 'updated' ),
       
   406 				'dismissible'        => true,
       
   407 			)
       
   408 		);
   400 	}
   409 	}
   401 }
   410 }
   402 ?>
   411 ?>
   403 
   412 
   404 <?php if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) : ?>
   413 <?php
   405 	<div class="error">
   414 if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) :
   406 		<?php
   415 	$error_message = '';
   407 		foreach ( $add_user_errors->get_error_messages() as $message ) {
   416 	foreach ( $add_user_errors->get_error_messages() as $message ) {
   408 			echo "<p>$message</p>";
   417 		$error_message .= "<p>$message</p>\n";
   409 		}
   418 	}
   410 		?>
   419 	wp_admin_notice(
   411 	</div>
   420 		$error_message,
   412 <?php endif; ?>
   421 		array(
       
   422 			'additional_classes' => array( 'error' ),
       
   423 			'paragraph_wrap'     => false,
       
   424 		)
       
   425 	);
       
   426 endif;
       
   427 ?>
   413 <div id="ajax-response"></div>
   428 <div id="ajax-response"></div>
   414 
   429 
   415 <?php
   430 <?php
   416 if ( is_multisite() && current_user_can( 'promote_users' ) ) {
   431 if ( is_multisite() && current_user_can( 'promote_users' ) ) {
   417 	if ( $do_both ) {
   432 	if ( $do_both ) {
   440 <input name="action" type="hidden" value="adduser" />
   455 <input name="action" type="hidden" value="adduser" />
   441 	<?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?>
   456 	<?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?>
   442 
   457 
   443 <table class="form-table" role="presentation">
   458 <table class="form-table" role="presentation">
   444 	<tr class="form-field form-required">
   459 	<tr class="form-field form-required">
   445 		<th scope="row"><label for="adduser-email"><?php echo $label; ?></label></th>
   460 		<th scope="row"><label for="adduser-email"><?php echo esc_html( $label ); ?></label></th>
   446 		<td><input name="email" type="<?php echo $type; ?>" id="adduser-email" class="wp-suggest-user" value="" /></td>
   461 		<td><input name="email" type="<?php echo esc_attr( $type ); ?>" id="adduser-email" class="wp-suggest-user" value="" /></td>
   447 	</tr>
   462 	</tr>
   448 	<tr class="form-field">
   463 	<tr class="form-field">
   449 		<th scope="row"><label for="adduser-role"><?php _e( 'Role' ); ?></label></th>
   464 		<th scope="row"><label for="adduser-role"><?php _e( 'Role' ); ?></label></th>
   450 		<td><select name="role" id="adduser-role">
   465 		<td><select name="role" id="adduser-role">
   451 			<?php wp_dropdown_roles( get_option( 'default_role' ) ); ?>
   466 			<?php wp_dropdown_roles( get_option( 'default_role' ) ); ?>
   455 	<?php if ( current_user_can( 'manage_network_users' ) ) { ?>
   470 	<?php if ( current_user_can( 'manage_network_users' ) ) { ?>
   456 	<tr>
   471 	<tr>
   457 		<th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
   472 		<th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
   458 		<td>
   473 		<td>
   459 			<input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" />
   474 			<input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" />
   460 			<label for="adduser-noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label>
   475 			<label for="adduser-noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation' ); ?></label>
   461 		</td>
   476 		</td>
   462 	</tr>
   477 	</tr>
   463 	<?php } ?>
   478 	<?php } ?>
   464 </table>
   479 </table>
   465 	<?php
   480 	<?php
   564 				<?php _e( 'Password' ); ?>
   579 				<?php _e( 'Password' ); ?>
   565 				<span class="description hide-if-js"><?php _e( '(required)' ); ?></span>
   580 				<span class="description hide-if-js"><?php _e( '(required)' ); ?></span>
   566 			</label>
   581 			</label>
   567 		</th>
   582 		</th>
   568 		<td>
   583 		<td>
   569 			<input class="hidden" value=" " /><!-- #24364 workaround -->
   584 			<input type="hidden" value=" " /><!-- #24364 workaround -->
   570 			<button type="button" class="button wp-generate-pw hide-if-no-js"><?php _e( 'Generate password' ); ?></button>
   585 			<button type="button" class="button wp-generate-pw hide-if-no-js"><?php _e( 'Generate password' ); ?></button>
   571 			<div class="wp-pwd">
   586 			<div class="wp-pwd">
   572 				<?php $initial_password = wp_generate_password( 24 ); ?>
   587 				<?php $initial_password = wp_generate_password( 24 ); ?>
   573 				<span class="password-input-wrapper">
   588 				<div class="password-input-wrapper">
   574 					<input type="password" name="pass1" id="pass1" class="regular-text" autocomplete="new-password" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
   589 					<input type="password" name="pass1" id="pass1" class="regular-text" autocomplete="new-password" spellcheck="false" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
   575 				</span>
   590 					<div style="display:none" id="pass-strength-result" aria-live="polite"></div>
       
   591 				</div>
   576 				<button type="button" class="button wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
   592 				<button type="button" class="button wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
   577 					<span class="dashicons dashicons-hidden" aria-hidden="true"></span>
   593 					<span class="dashicons dashicons-hidden" aria-hidden="true"></span>
   578 					<span class="text"><?php _e( 'Hide' ); ?></span>
   594 					<span class="text"><?php _e( 'Hide' ); ?></span>
   579 				</button>
   595 				</button>
   580 				<div style="display:none" id="pass-strength-result" aria-live="polite"></div>
       
   581 			</div>
   596 			</div>
   582 		</td>
   597 		</td>
   583 	</tr>
   598 	</tr>
   584 	<tr class="form-field form-required user-pass2-wrap hide-if-js">
   599 	<tr class="form-field form-required user-pass2-wrap hide-if-js">
   585 		<th scope="row"><label for="pass2"><?php _e( 'Repeat Password' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
   600 		<th scope="row"><label for="pass2"><?php _e( 'Repeat Password' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
   586 		<td>
   601 		<td>
   587 		<input name="pass2" type="password" id="pass2" autocomplete="new-password" aria-describedby="pass2-desc" />
   602 		<input type="password" name="pass2" id="pass2" autocomplete="new-password" spellcheck="false" aria-describedby="pass2-desc" />
   588 		<p class="description" id="pass2-desc"><?php _e( 'Type the password again.' ); ?></p>
   603 		<p class="description" id="pass2-desc"><?php _e( 'Type the password again.' ); ?></p>
   589 		</td>
   604 		</td>
   590 	</tr>
   605 	</tr>
   591 	<tr class="pw-weak">
   606 	<tr class="pw-weak">
   592 		<th><?php _e( 'Confirm Password' ); ?></th>
   607 		<th><?php _e( 'Confirm Password' ); ?></th>
   599 	</tr>
   614 	</tr>
   600 	<tr>
   615 	<tr>
   601 		<th scope="row"><?php _e( 'Send User Notification' ); ?></th>
   616 		<th scope="row"><?php _e( 'Send User Notification' ); ?></th>
   602 		<td>
   617 		<td>
   603 			<input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> />
   618 			<input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> />
   604 			<label for="send_user_notification"><?php _e( 'Send the new user an email about their account.' ); ?></label>
   619 			<label for="send_user_notification"><?php _e( 'Send the new user an email about their account' ); ?></label>
   605 		</td>
   620 		</td>
   606 	</tr>
   621 	</tr>
   607 	<?php } // End if ! is_multisite(). ?>
   622 	<?php } // End if ! is_multisite(). ?>
   608 	<?php if ( current_user_can( 'promote_users' ) ) { ?>
   623 	<?php if ( current_user_can( 'promote_users' ) ) { ?>
   609 	<tr class="form-field">
   624 	<tr class="form-field">
   622 	<?php if ( is_multisite() && current_user_can( 'manage_network_users' ) ) { ?>
   637 	<?php if ( is_multisite() && current_user_can( 'manage_network_users' ) ) { ?>
   623 	<tr>
   638 	<tr>
   624 		<th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
   639 		<th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
   625 		<td>
   640 		<td>
   626 			<input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" <?php checked( $new_user_ignore_pass ); ?> />
   641 			<input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" <?php checked( $new_user_ignore_pass ); ?> />
   627 			<label for="noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label>
   642 			<label for="noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation' ); ?></label>
   628 		</td>
   643 		</td>
   629 	</tr>
   644 	</tr>
   630 	<?php } ?>
   645 	<?php } ?>
   631 </table>
   646 </table>
   632 
   647