user-new.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <?php
  2. /**
  3. * New User Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once __DIR__ . '/admin.php';
  10. if ( is_multisite() ) {
  11. if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) ) {
  12. wp_die(
  13. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  14. '<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>',
  15. 403
  16. );
  17. }
  18. } elseif ( ! current_user_can( 'create_users' ) ) {
  19. wp_die(
  20. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  21. '<p>' . __( 'Sorry, you are not allowed to create users.' ) . '</p>',
  22. 403
  23. );
  24. }
  25. if ( is_multisite() ) {
  26. add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
  27. }
  28. if ( isset( $_REQUEST['action'] ) && 'adduser' === $_REQUEST['action'] ) {
  29. check_admin_referer( 'add-user', '_wpnonce_add-user' );
  30. $user_details = null;
  31. $user_email = wp_unslash( $_REQUEST['email'] );
  32. if ( false !== strpos( $user_email, '@' ) ) {
  33. $user_details = get_user_by( 'email', $user_email );
  34. } else {
  35. if ( current_user_can( 'manage_network_users' ) ) {
  36. $user_details = get_user_by( 'login', $user_email );
  37. } else {
  38. wp_redirect( add_query_arg( array( 'update' => 'enter_email' ), 'user-new.php' ) );
  39. die();
  40. }
  41. }
  42. if ( ! $user_details ) {
  43. wp_redirect( add_query_arg( array( 'update' => 'does_not_exist' ), 'user-new.php' ) );
  44. die();
  45. }
  46. if ( ! current_user_can( 'promote_user', $user_details->ID ) ) {
  47. wp_die(
  48. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  49. '<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>',
  50. 403
  51. );
  52. }
  53. // Adding an existing user to this blog.
  54. $new_user_email = array();
  55. $redirect = 'user-new.php';
  56. $username = $user_details->user_login;
  57. $user_id = $user_details->ID;
  58. if ( null != $username && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) {
  59. $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' );
  60. } else {
  61. if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
  62. $result = add_existing_user_to_blog(
  63. array(
  64. 'user_id' => $user_id,
  65. 'role' => $_REQUEST['role'],
  66. )
  67. );
  68. if ( ! is_wp_error( $result ) ) {
  69. $redirect = add_query_arg(
  70. array(
  71. 'update' => 'addnoconfirmation',
  72. 'user_id' => $user_id,
  73. ),
  74. 'user-new.php'
  75. );
  76. } else {
  77. $redirect = add_query_arg( array( 'update' => 'could_not_add' ), 'user-new.php' );
  78. }
  79. } else {
  80. $newuser_key = wp_generate_password( 20, false );
  81. add_option(
  82. 'new_user_' . $newuser_key,
  83. array(
  84. 'user_id' => $user_id,
  85. 'email' => $user_details->user_email,
  86. 'role' => $_REQUEST['role'],
  87. )
  88. );
  89. $roles = get_editable_roles();
  90. $role = $roles[ $_REQUEST['role'] ];
  91. /**
  92. * Fires immediately after an existing user is invited to join the site, but before the notification is sent.
  93. *
  94. * @since 4.4.0
  95. *
  96. * @param int $user_id The invited user's ID.
  97. * @param array $role Array containing role information for the invited user.
  98. * @param string $newuser_key The key of the invitation.
  99. */
  100. do_action( 'invite_user', $user_id, $role, $newuser_key );
  101. $switched_locale = switch_to_locale( get_user_locale( $user_details ) );
  102. if ( '' !== get_option( 'blogname' ) ) {
  103. $site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  104. } else {
  105. $site_title = parse_url( home_url(), PHP_URL_HOST );
  106. }
  107. /* translators: 1: Site title, 2: Site URL, 3: User role, 4: Activation URL. */
  108. $message = __(
  109. 'Hi,
  110. You\'ve been invited to join \'%1$s\' at
  111. %2$s with the role of %3$s.
  112. Please click the following link to confirm the invite:
  113. %4$s'
  114. );
  115. $new_user_email['to'] = $user_details->user_email;
  116. $new_user_email['subject'] = sprintf(
  117. /* translators: Joining confirmation notification email subject. %s: Site title. */
  118. __( '[%s] Joining Confirmation' ),
  119. $site_title
  120. );
  121. $new_user_email['message'] = sprintf(
  122. $message,
  123. get_option( 'blogname' ),
  124. home_url(),
  125. wp_specialchars_decode( translate_user_role( $role['name'] ) ),
  126. home_url( "/newbloguser/$newuser_key/" )
  127. );
  128. $new_user_email['headers'] = '';
  129. /**
  130. * Filters the contents of the email sent when an existing user is invited to join the site.
  131. *
  132. * @since 5.6.0
  133. *
  134. * @param array $new_user_email {
  135. * Used to build wp_mail().
  136. *
  137. * @type string $to The email address of the invited user.
  138. * @type string $subject The subject of the email.
  139. * @type string $message The content of the email.
  140. * @type string $headers Headers.
  141. * }
  142. * @param int $user_id The invited user's ID.
  143. * @param array $role Array containing role information for the invited user.
  144. * @param string $newuser_key The key of the invitation.
  145. *
  146. */
  147. $new_user_email = apply_filters( 'invited_user_email', $new_user_email, $user_id, $role, $newuser_key );
  148. wp_mail(
  149. $new_user_email['to'],
  150. $new_user_email['subject'],
  151. $new_user_email['message'],
  152. $new_user_email['headers']
  153. );
  154. if ( $switched_locale ) {
  155. restore_previous_locale();
  156. }
  157. $redirect = add_query_arg( array( 'update' => 'add' ), 'user-new.php' );
  158. }
  159. }
  160. wp_redirect( $redirect );
  161. die();
  162. } elseif ( isset( $_REQUEST['action'] ) && 'createuser' === $_REQUEST['action'] ) {
  163. check_admin_referer( 'create-user', '_wpnonce_create-user' );
  164. if ( ! current_user_can( 'create_users' ) ) {
  165. wp_die(
  166. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  167. '<p>' . __( 'Sorry, you are not allowed to create users.' ) . '</p>',
  168. 403
  169. );
  170. }
  171. if ( ! is_multisite() ) {
  172. $user_id = edit_user();
  173. if ( is_wp_error( $user_id ) ) {
  174. $add_user_errors = $user_id;
  175. } else {
  176. if ( current_user_can( 'list_users' ) ) {
  177. $redirect = 'users.php?update=add&id=' . $user_id;
  178. } else {
  179. $redirect = add_query_arg( 'update', 'add', 'user-new.php' );
  180. }
  181. wp_redirect( $redirect );
  182. die();
  183. }
  184. } else {
  185. // Adding a new user to this site.
  186. $new_user_email = wp_unslash( $_REQUEST['email'] );
  187. $user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email );
  188. if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) {
  189. $add_user_errors = $user_details['errors'];
  190. } else {
  191. /** This filter is documented in wp-includes/user.php */
  192. $new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) );
  193. if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
  194. add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email.
  195. add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email.
  196. }
  197. wpmu_signup_user(
  198. $new_user_login,
  199. $new_user_email,
  200. array(
  201. 'add_to_blog' => get_current_blog_id(),
  202. 'new_role' => $_REQUEST['role'],
  203. )
  204. );
  205. if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
  206. $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) );
  207. $new_user = wpmu_activate_signup( $key );
  208. if ( is_wp_error( $new_user ) ) {
  209. $redirect = add_query_arg( array( 'update' => 'addnoconfirmation' ), 'user-new.php' );
  210. } elseif ( ! is_user_member_of_blog( $new_user['user_id'] ) ) {
  211. $redirect = add_query_arg( array( 'update' => 'created_could_not_add' ), 'user-new.php' );
  212. } else {
  213. $redirect = add_query_arg(
  214. array(
  215. 'update' => 'addnoconfirmation',
  216. 'user_id' => $new_user['user_id'],
  217. ),
  218. 'user-new.php'
  219. );
  220. }
  221. } else {
  222. $redirect = add_query_arg( array( 'update' => 'newuserconfirmation' ), 'user-new.php' );
  223. }
  224. wp_redirect( $redirect );
  225. die();
  226. }
  227. }
  228. }
  229. // Used in the HTML title tag.
  230. $title = __( 'Add New User' );
  231. $parent_file = 'users.php';
  232. $do_both = false;
  233. if ( is_multisite() && current_user_can( 'promote_users' ) && current_user_can( 'create_users' ) ) {
  234. $do_both = true;
  235. }
  236. $help = '<p>' . __( 'To add a new user to your site, fill in the form on this screen and click the Add New User button at the bottom.' ) . '</p>';
  237. if ( is_multisite() ) {
  238. $help .= '<p>' . __( 'Because this is a multisite installation, you may add accounts that already exist on the Network by specifying a username or email, and defining a role. For more options, such as specifying a password, you have to be a Network Administrator and use the hover link under an existing user&#8217;s name to Edit the user profile under Network Admin > All Users.' ) . '</p>' .
  239. '<p>' . __( 'New users will receive an email letting them know they&#8217;ve been added as a user for your site. This email will also contain their password. Check the box if you do not want the user to receive a welcome email.' ) . '</p>';
  240. } else {
  241. $help .= '<p>' . __( 'New users are automatically assigned a password, which they can change after logging in. You can view or edit the assigned password by clicking the Show Password button. The username cannot be changed once the user has been added.' ) . '</p>' .
  242. '<p>' . __( 'By default, new users will receive an email letting them know they&#8217;ve been added as a user for your site. This email will also contain a password reset link. Uncheck the box if you do not want to send the new user a welcome email.' ) . '</p>';
  243. }
  244. $help .= '<p>' . __( 'Remember to click the Add New User button at the bottom of this screen when you are finished.' ) . '</p>';
  245. get_current_screen()->add_help_tab(
  246. array(
  247. 'id' => 'overview',
  248. 'title' => __( 'Overview' ),
  249. 'content' => $help,
  250. )
  251. );
  252. get_current_screen()->add_help_tab(
  253. array(
  254. 'id' => 'user-roles',
  255. 'title' => __( 'User Roles' ),
  256. 'content' => '<p>' . __( 'Here is a basic overview of the different user roles and the permissions associated with each one:' ) . '</p>' .
  257. '<ul>' .
  258. '<li>' . __( 'Subscribers can read comments/comment/receive newsletters, etc. but cannot create regular site content.' ) . '</li>' .
  259. '<li>' . __( 'Contributors can write and manage their posts but not publish posts or upload media files.' ) . '</li>' .
  260. '<li>' . __( 'Authors can publish and manage their own posts, and are able to upload files.' ) . '</li>' .
  261. '<li>' . __( 'Editors can publish posts, manage posts as well as manage other people&#8217;s posts, etc.' ) . '</li>' .
  262. '<li>' . __( 'Administrators have access to all the administration features.' ) . '</li>' .
  263. '</ul>',
  264. )
  265. );
  266. get_current_screen()->set_help_sidebar(
  267. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  268. '<p>' . __( '<a href="https://wordpress.org/support/article/users-add-new-screen/">Documentation on Adding New Users</a>' ) . '</p>' .
  269. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  270. );
  271. wp_enqueue_script( 'wp-ajax-response' );
  272. wp_enqueue_script( 'user-profile' );
  273. /**
  274. * Filters whether to enable user auto-complete for non-super admins in Multisite.
  275. *
  276. * @since 3.4.0
  277. *
  278. * @param bool $enable Whether to enable auto-complete for non-super admins. Default false.
  279. */
  280. if ( is_multisite() && current_user_can( 'promote_users' ) && ! wp_is_large_network( 'users' )
  281. && ( current_user_can( 'manage_network_users' ) || apply_filters( 'autocomplete_users_for_site_admins', false ) )
  282. ) {
  283. wp_enqueue_script( 'user-suggest' );
  284. }
  285. require_once ABSPATH . 'wp-admin/admin-header.php';
  286. if ( isset( $_GET['update'] ) ) {
  287. $messages = array();
  288. if ( is_multisite() ) {
  289. $edit_link = '';
  290. if ( ( isset( $_GET['user_id'] ) ) ) {
  291. $user_id_new = absint( $_GET['user_id'] );
  292. if ( $user_id_new ) {
  293. $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) );
  294. }
  295. }
  296. switch ( $_GET['update'] ) {
  297. case 'newuserconfirmation':
  298. $messages[] = __( 'Invitation email sent to new user. A confirmation link must be clicked before their account is created.' );
  299. break;
  300. case 'add':
  301. $messages[] = __( 'Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.' );
  302. break;
  303. case 'addnoconfirmation':
  304. $message = __( 'User has been added to your site.' );
  305. if ( $edit_link ) {
  306. $message .= sprintf( ' <a href="%s">%s</a>', $edit_link, __( 'Edit user' ) );
  307. }
  308. $messages[] = $message;
  309. break;
  310. case 'addexisting':
  311. $messages[] = __( 'That user is already a member of this site.' );
  312. break;
  313. case 'could_not_add':
  314. $add_user_errors = new WP_Error( 'could_not_add', __( 'That user could not be added to this site.' ) );
  315. break;
  316. case 'created_could_not_add':
  317. $add_user_errors = new WP_Error( 'created_could_not_add', __( 'User has been created, but could not be added to this site.' ) );
  318. break;
  319. case 'does_not_exist':
  320. $add_user_errors = new WP_Error( 'does_not_exist', __( 'The requested user does not exist.' ) );
  321. break;
  322. case 'enter_email':
  323. $add_user_errors = new WP_Error( 'enter_email', __( 'Please enter a valid email address.' ) );
  324. break;
  325. }
  326. } else {
  327. if ( 'add' === $_GET['update'] ) {
  328. $messages[] = __( 'User added.' );
  329. }
  330. }
  331. }
  332. ?>
  333. <div class="wrap">
  334. <h1 id="add-new-user">
  335. <?php
  336. if ( current_user_can( 'create_users' ) ) {
  337. _e( 'Add New User' );
  338. } elseif ( current_user_can( 'promote_users' ) ) {
  339. _e( 'Add Existing User' );
  340. }
  341. ?>
  342. </h1>
  343. <?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?>
  344. <div class="error">
  345. <ul>
  346. <?php
  347. foreach ( $errors->get_error_messages() as $err ) {
  348. echo "<li>$err</li>\n";
  349. }
  350. ?>
  351. </ul>
  352. </div>
  353. <?php
  354. endif;
  355. if ( ! empty( $messages ) ) {
  356. foreach ( $messages as $msg ) {
  357. echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  358. }
  359. }
  360. ?>
  361. <?php if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) : ?>
  362. <div class="error">
  363. <?php
  364. foreach ( $add_user_errors->get_error_messages() as $message ) {
  365. echo "<p>$message</p>";
  366. }
  367. ?>
  368. </div>
  369. <?php endif; ?>
  370. <div id="ajax-response"></div>
  371. <?php
  372. if ( is_multisite() && current_user_can( 'promote_users' ) ) {
  373. if ( $do_both ) {
  374. echo '<h2 id="add-existing-user">' . __( 'Add Existing User' ) . '</h2>';
  375. }
  376. if ( ! current_user_can( 'manage_network_users' ) ) {
  377. echo '<p>' . __( 'Enter the email address of an existing user on this network to invite them to this site. That person will be sent an email asking them to confirm the invite.' ) . '</p>';
  378. $label = __( 'Email' );
  379. $type = 'email';
  380. } else {
  381. echo '<p>' . __( 'Enter the email address or username of an existing user on this network to invite them to this site. That person will be sent an email asking them to confirm the invite.' ) . '</p>';
  382. $label = __( 'Email or Username' );
  383. $type = 'text';
  384. }
  385. ?>
  386. <form method="post" name="adduser" id="adduser" class="validate" novalidate="novalidate"
  387. <?php
  388. /**
  389. * Fires inside the adduser form tag.
  390. *
  391. * @since 3.0.0
  392. */
  393. do_action( 'user_new_form_tag' );
  394. ?>
  395. >
  396. <input name="action" type="hidden" value="adduser" />
  397. <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?>
  398. <table class="form-table" role="presentation">
  399. <tr class="form-field form-required">
  400. <th scope="row"><label for="adduser-email"><?php echo $label; ?></label></th>
  401. <td><input name="email" type="<?php echo $type; ?>" id="adduser-email" class="wp-suggest-user" value="" /></td>
  402. </tr>
  403. <tr class="form-field">
  404. <th scope="row"><label for="adduser-role"><?php _e( 'Role' ); ?></label></th>
  405. <td><select name="role" id="adduser-role">
  406. <?php wp_dropdown_roles( get_option( 'default_role' ) ); ?>
  407. </select>
  408. </td>
  409. </tr>
  410. <?php if ( current_user_can( 'manage_network_users' ) ) { ?>
  411. <tr>
  412. <th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
  413. <td>
  414. <input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" />
  415. <label for="adduser-noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label>
  416. </td>
  417. </tr>
  418. <?php } ?>
  419. </table>
  420. <?php
  421. /**
  422. * Fires at the end of the new user form.
  423. *
  424. * Passes a contextual string to make both types of new user forms
  425. * uniquely targetable. Contexts are 'add-existing-user' (Multisite),
  426. * and 'add-new-user' (single site and network admin).
  427. *
  428. * @since 3.7.0
  429. *
  430. * @param string $type A contextual string specifying which type of new user form the hook follows.
  431. */
  432. do_action( 'user_new_form', 'add-existing-user' );
  433. ?>
  434. <?php submit_button( __( 'Add Existing User' ), 'primary', 'adduser', true, array( 'id' => 'addusersub' ) ); ?>
  435. </form>
  436. <?php
  437. } // End if is_multisite().
  438. if ( current_user_can( 'create_users' ) ) {
  439. if ( $do_both ) {
  440. echo '<h2 id="create-new-user">' . __( 'Add New User' ) . '</h2>';
  441. }
  442. ?>
  443. <p><?php _e( 'Create a brand new user and add them to this site.' ); ?></p>
  444. <form method="post" name="createuser" id="createuser" class="validate" novalidate="novalidate"
  445. <?php
  446. /** This action is documented in wp-admin/user-new.php */
  447. do_action( 'user_new_form_tag' );
  448. ?>
  449. >
  450. <input name="action" type="hidden" value="createuser" />
  451. <?php wp_nonce_field( 'create-user', '_wpnonce_create-user' ); ?>
  452. <?php
  453. // Load up the passed data, else set to a default.
  454. $creating = isset( $_POST['createuser'] );
  455. $new_user_login = $creating && isset( $_POST['user_login'] ) ? wp_unslash( $_POST['user_login'] ) : '';
  456. $new_user_firstname = $creating && isset( $_POST['first_name'] ) ? wp_unslash( $_POST['first_name'] ) : '';
  457. $new_user_lastname = $creating && isset( $_POST['last_name'] ) ? wp_unslash( $_POST['last_name'] ) : '';
  458. $new_user_email = $creating && isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';
  459. $new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : '';
  460. $new_user_role = $creating && isset( $_POST['role'] ) ? wp_unslash( $_POST['role'] ) : '';
  461. $new_user_send_notification = $creating && ! isset( $_POST['send_user_notification'] ) ? false : true;
  462. $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unslash( $_POST['noconfirmation'] ) : '';
  463. ?>
  464. <table class="form-table" role="presentation">
  465. <tr class="form-field form-required">
  466. <th scope="row"><label for="user_login"><?php _e( 'Username' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
  467. <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr( $new_user_login ); ?>" aria-required="true" autocapitalize="none" autocorrect="off" autocomplete="off" maxlength="60" /></td>
  468. </tr>
  469. <tr class="form-field form-required">
  470. <th scope="row"><label for="email"><?php _e( 'Email' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
  471. <td><input name="email" type="email" id="email" value="<?php echo esc_attr( $new_user_email ); ?>" /></td>
  472. </tr>
  473. <?php if ( ! is_multisite() ) { ?>
  474. <tr class="form-field">
  475. <th scope="row"><label for="first_name"><?php _e( 'First Name' ); ?> </label></th>
  476. <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr( $new_user_firstname ); ?>" /></td>
  477. </tr>
  478. <tr class="form-field">
  479. <th scope="row"><label for="last_name"><?php _e( 'Last Name' ); ?> </label></th>
  480. <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr( $new_user_lastname ); ?>" /></td>
  481. </tr>
  482. <tr class="form-field">
  483. <th scope="row"><label for="url"><?php _e( 'Website' ); ?></label></th>
  484. <td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td>
  485. </tr>
  486. <?php
  487. $languages = get_available_languages();
  488. if ( $languages ) :
  489. ?>
  490. <tr class="form-field user-language-wrap">
  491. <th scope="row">
  492. <label for="locale">
  493. <?php /* translators: The user language selection field label. */ ?>
  494. <?php _e( 'Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span>
  495. </label>
  496. </th>
  497. <td>
  498. <?php
  499. wp_dropdown_languages(
  500. array(
  501. 'name' => 'locale',
  502. 'id' => 'locale',
  503. 'selected' => 'site-default',
  504. 'languages' => $languages,
  505. 'show_available_translations' => false,
  506. 'show_option_site_default' => true,
  507. )
  508. );
  509. ?>
  510. </td>
  511. </tr>
  512. <?php endif; ?>
  513. <tr class="form-field form-required user-pass1-wrap">
  514. <th scope="row">
  515. <label for="pass1">
  516. <?php _e( 'Password' ); ?>
  517. <span class="description hide-if-js"><?php _e( '(required)' ); ?></span>
  518. </label>
  519. </th>
  520. <td>
  521. <input class="hidden" value=" " /><!-- #24364 workaround -->
  522. <button type="button" class="button wp-generate-pw hide-if-no-js"><?php _e( 'Generate password' ); ?></button>
  523. <div class="wp-pwd">
  524. <?php $initial_password = wp_generate_password( 24 ); ?>
  525. <span class="password-input-wrapper">
  526. <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" />
  527. </span>
  528. <button type="button" class="button wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
  529. <span class="dashicons dashicons-hidden" aria-hidden="true"></span>
  530. <span class="text"><?php _e( 'Hide' ); ?></span>
  531. </button>
  532. <div style="display:none" id="pass-strength-result" aria-live="polite"></div>
  533. </div>
  534. </td>
  535. </tr>
  536. <tr class="form-field form-required user-pass2-wrap hide-if-js">
  537. <th scope="row"><label for="pass2"><?php _e( 'Repeat Password' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
  538. <td>
  539. <input name="pass2" type="password" id="pass2" autocomplete="new-password" aria-describedby="pass2-desc" />
  540. <p class="description" id="pass2-desc"><?php _e( 'Type the password again.' ); ?></p>
  541. </td>
  542. </tr>
  543. <tr class="pw-weak">
  544. <th><?php _e( 'Confirm Password' ); ?></th>
  545. <td>
  546. <label>
  547. <input type="checkbox" name="pw_weak" class="pw-checkbox" />
  548. <?php _e( 'Confirm use of weak password' ); ?>
  549. </label>
  550. </td>
  551. </tr>
  552. <tr>
  553. <th scope="row"><?php _e( 'Send User Notification' ); ?></th>
  554. <td>
  555. <input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> />
  556. <label for="send_user_notification"><?php _e( 'Send the new user an email about their account.' ); ?></label>
  557. </td>
  558. </tr>
  559. <?php } // End if ! is_multisite(). ?>
  560. <?php if ( current_user_can( 'promote_users' ) ) { ?>
  561. <tr class="form-field">
  562. <th scope="row"><label for="role"><?php _e( 'Role' ); ?></label></th>
  563. <td><select name="role" id="role">
  564. <?php
  565. if ( ! $new_user_role ) {
  566. $new_user_role = get_option( 'default_role' );
  567. }
  568. wp_dropdown_roles( $new_user_role );
  569. ?>
  570. </select>
  571. </td>
  572. </tr>
  573. <?php } ?>
  574. <?php if ( is_multisite() && current_user_can( 'manage_network_users' ) ) { ?>
  575. <tr>
  576. <th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
  577. <td>
  578. <input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" <?php checked( $new_user_ignore_pass ); ?> />
  579. <label for="noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label>
  580. </td>
  581. </tr>
  582. <?php } ?>
  583. </table>
  584. <?php
  585. /** This action is documented in wp-admin/user-new.php */
  586. do_action( 'user_new_form', 'add-new-user' );
  587. ?>
  588. <?php submit_button( __( 'Add New User' ), 'primary', 'createuser', true, array( 'id' => 'createusersub' ) ); ?>
  589. </form>
  590. <?php } // End if current_user_can( 'create_users' ). ?>
  591. </div>
  592. <?php
  593. require_once ABSPATH . 'wp-admin/admin-footer.php';