wp/wp-admin/user-new.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     8 
     8 
     9 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 
    11 
    12 if ( is_multisite() ) {
    12 if ( is_multisite() ) {
    13 	if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) )
    13 	if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) ) {
    14 		wp_die( __( 'Cheatin’ uh?' ), 403 );
    14 		wp_die(
       
    15 			'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    16 			'<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>',
       
    17 			403
       
    18 		);
       
    19 	}
    15 } elseif ( ! current_user_can( 'create_users' ) ) {
    20 } elseif ( ! current_user_can( 'create_users' ) ) {
    16 	wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
    21 	wp_die(
       
    22 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    23 		'<p>' . __( 'Sorry, you are not allowed to create users.' ) . '</p>',
       
    24 		403
       
    25 	);
    17 }
    26 }
    18 
    27 
    19 if ( is_multisite() ) {
    28 if ( is_multisite() ) {
    20 	function admin_created_user_email( $text ) {
       
    21 		$roles = get_editable_roles();
       
    22 		$role = $roles[ $_REQUEST['role'] ];
       
    23 		/* translators: 1: Site name, 2: site URL, 3: role */
       
    24 		return sprintf( __( 'Hi,
       
    25 You\'ve been invited to join \'%1$s\' at
       
    26 %2$s with the role of %3$s.
       
    27 If you do not want to join this site please ignore
       
    28 this email. This invitation will expire in a few days.
       
    29 
       
    30 Please click the following link to activate your user account:
       
    31 %%s' ), get_bloginfo( 'name' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ) );
       
    32 	}
       
    33 	add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
    29 	add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
    34 }
    30 }
    35 
    31 
    36 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
    32 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
    37 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
    33 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
    39 	$user_details = null;
    35 	$user_details = null;
    40 	$user_email = wp_unslash( $_REQUEST['email'] );
    36 	$user_email = wp_unslash( $_REQUEST['email'] );
    41 	if ( false !== strpos( $user_email, '@' ) ) {
    37 	if ( false !== strpos( $user_email, '@' ) ) {
    42 		$user_details = get_user_by( 'email', $user_email );
    38 		$user_details = get_user_by( 'email', $user_email );
    43 	} else {
    39 	} else {
    44 		if ( is_super_admin() ) {
    40 		if ( current_user_can( 'manage_network_users' ) ) {
    45 			$user_details = get_user_by( 'login', $user_email );
    41 			$user_details = get_user_by( 'login', $user_email );
    46 		} else {
    42 		} else {
    47 			wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
    43 			wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
    48 			die();
    44 			die();
    49 		}
    45 		}
    52 	if ( !$user_details ) {
    48 	if ( !$user_details ) {
    53 		wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) );
    49 		wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) );
    54 		die();
    50 		die();
    55 	}
    51 	}
    56 
    52 
    57 	if ( ! current_user_can('promote_user', $user_details->ID) )
    53 	if ( ! current_user_can( 'promote_user', $user_details->ID ) ) {
    58 		wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
    54 		wp_die(
       
    55 			'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    56 			'<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>',
       
    57 			403
       
    58 		);
       
    59 	}
    59 
    60 
    60 	// Adding an existing user to this blog
    61 	// Adding an existing user to this blog
    61 	$new_user_email = $user_details->user_email;
    62 	$new_user_email = $user_details->user_email;
    62 	$redirect = 'user-new.php';
    63 	$redirect = 'user-new.php';
    63 	$username = $user_details->user_login;
    64 	$username = $user_details->user_login;
    64 	$user_id = $user_details->ID;
    65 	$user_id = $user_details->ID;
    65 	if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
    66 	if ( $username != null && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) {
    66 		$redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
    67 		$redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
    67 	} else {
    68 	} else {
    68 		if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
    69 		if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) {
    69 			add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
    70 			$result = add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
    70 			$redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
    71 
       
    72 			if ( ! is_wp_error( $result ) ) {
       
    73 				$redirect = add_query_arg( array( 'update' => 'addnoconfirmation', 'user_id' => $user_id ), 'user-new.php' );
       
    74 			} else {
       
    75 				$redirect = add_query_arg( array( 'update' => 'could_not_add' ), 'user-new.php' );
       
    76 			}
    71 		} else {
    77 		} else {
    72 			$newuser_key = substr( md5( $user_id ), 0, 5 );
    78 			$newuser_key = wp_generate_password( 20, false );
    73 			add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
    79 			add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
    74 
    80 
    75 			$roles = get_editable_roles();
    81 			$roles = get_editable_roles();
    76 			$role = $roles[ $_REQUEST['role'] ];
    82 			$role = $roles[ $_REQUEST['role'] ];
       
    83 
       
    84 			/**
       
    85 			 * Fires immediately after a user is invited to join a site, but before the notification is sent.
       
    86 			 *
       
    87 			 * @since 4.4.0
       
    88 			 *
       
    89 			 * @param int    $user_id     The invited user's ID.
       
    90 			 * @param array  $role        The role of invited user.
       
    91 			 * @param string $newuser_key The key of the invitation.
       
    92 			 */
       
    93 			do_action( 'invite_user', $user_id, $role, $newuser_key );
       
    94 
       
    95 			$switched_locale = switch_to_locale( get_user_locale( $user_details ) );
       
    96 
    77 			/* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
    97 			/* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
    78 			$message = __( 'Hi,
    98 			$message = __( 'Hi,
    79 
    99 
    80 You\'ve been invited to join \'%1$s\' at
   100 You\'ve been invited to join \'%1$s\' at
    81 %2$s with the role of %3$s.
   101 %2$s with the role of %3$s.
    82 
   102 
    83 Please click the following link to confirm the invite:
   103 Please click the following link to confirm the invite:
    84 %4$s' );
   104 %4$s' );
    85 			wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), sprintf( $message, get_option( 'blogname' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ), home_url( "/newbloguser/$newuser_key/" ) ) );
   105 			wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), sprintf( $message, get_option( 'blogname' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ), home_url( "/newbloguser/$newuser_key/" ) ) );
       
   106 
       
   107 			if ( $switched_locale ) {
       
   108 				restore_previous_locale();
       
   109 			}
       
   110 
    86 			$redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
   111 			$redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
    87 		}
   112 		}
    88 	}
   113 	}
    89 	wp_redirect( $redirect );
   114 	wp_redirect( $redirect );
    90 	die();
   115 	die();
    91 } elseif ( isset($_REQUEST['action']) && 'createuser' == $_REQUEST['action'] ) {
   116 } elseif ( isset($_REQUEST['action']) && 'createuser' == $_REQUEST['action'] ) {
    92 	check_admin_referer( 'create-user', '_wpnonce_create-user' );
   117 	check_admin_referer( 'create-user', '_wpnonce_create-user' );
    93 
   118 
    94 	if ( ! current_user_can('create_users') )
   119 	if ( ! current_user_can( 'create_users' ) ) {
    95 		wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
   120 		wp_die(
       
   121 			'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
   122 			'<p>' . __( 'Sorry, you are not allowed to create users.' ) . '</p>',
       
   123 			403
       
   124 		);
       
   125 	}
    96 
   126 
    97 	if ( ! is_multisite() ) {
   127 	if ( ! is_multisite() ) {
    98 		$user_id = edit_user();
   128 		$user_id = edit_user();
    99 
   129 
   100 		if ( is_wp_error( $user_id ) ) {
   130 		if ( is_wp_error( $user_id ) ) {
   113 		$user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email );
   143 		$user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email );
   114 		if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) {
   144 		if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) {
   115 			$add_user_errors = $user_details[ 'errors' ];
   145 			$add_user_errors = $user_details[ 'errors' ];
   116 		} else {
   146 		} else {
   117 			/**
   147 			/**
   118 			 * Filter the user_login, also known as the username, before it is added to the site.
   148 			 * Filters the user_login, also known as the username, before it is added to the site.
   119 			 *
   149 			 *
   120 			 * @since 2.0.3
   150 			 * @since 2.0.3
   121 			 *
   151 			 *
   122 			 * @param string $user_login The sanitized username.
   152 			 * @param string $user_login The sanitized username.
   123 			 */
   153 			 */
   124 			$new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) );
   154 			$new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) );
   125 			if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
   155 			if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) {
   126 				add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
   156 				add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
   127 				add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email
   157 				add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email
   128 			}
   158 			}
   129 			wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'] ) );
   159 			wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => get_current_blog_id(), 'new_role' => $_REQUEST['role'] ) );
   130 			if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
   160 			if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) {
   131 				$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 ) );
   161 				$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 ) );
   132 				wpmu_activate_signup( $key );
   162 				$new_user = wpmu_activate_signup( $key );
   133 				$redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
   163 				if ( is_wp_error( $new_user ) ) {
       
   164 					$redirect = add_query_arg( array( 'update' => 'addnoconfirmation' ), 'user-new.php' );
       
   165 				} elseif ( ! is_user_member_of_blog( $new_user['user_id'] ) ) {
       
   166 					$redirect = add_query_arg( array( 'update' => 'created_could_not_add' ), 'user-new.php' );
       
   167 				} else {
       
   168 					$redirect = add_query_arg( array( 'update' => 'addnoconfirmation', 'user_id' => $new_user['user_id'] ), 'user-new.php' );
       
   169 				}
   134 			} else {
   170 			} else {
   135 				$redirect = add_query_arg( array('update' => 'newuserconfirmation'), 'user-new.php' );
   171 				$redirect = add_query_arg( array('update' => 'newuserconfirmation'), 'user-new.php' );
   136 			}
   172 			}
   137 			wp_redirect( $redirect );
   173 			wp_redirect( $redirect );
   138 			die();
   174 			die();
   151 
   187 
   152 if ( is_multisite() ) {
   188 if ( is_multisite() ) {
   153 	$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>' .
   189 	$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>' .
   154 	'<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 don&#8217;t want the user to receive a welcome email.') . '</p>';
   190 	'<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 don&#8217;t want the user to receive a welcome email.') . '</p>';
   155 } else {
   191 } else {
   156 	$help .= '<p>' . __('You must assign a password to the new user, which they can change after logging in. The username, however, cannot be changed.') . '</p>' .
   192 	$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>' .
   157 	'<p>' . __('New users will receive an email letting them know they&#8217;ve been added as a user for your site. By default, this email will also contain their password. Uncheck the box if you don&#8217;t want the password to be included in the welcome email.') . '</p>';
   193 
       
   194 	'<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 don&#8217;t want to send the new user a welcome email.') . '</p>';
   158 }
   195 }
   159 
   196 
   160 $help .= '<p>' . __('Remember to click the Add New User button at the bottom of this screen when you are finished.') . '</p>';
   197 $help .= '<p>' . __('Remember to click the Add New User button at the bottom of this screen when you are finished.') . '</p>';
   161 
   198 
   162 get_current_screen()->add_help_tab( array(
   199 get_current_screen()->add_help_tab( array(
   178 				'</ul>'
   215 				'</ul>'
   179 ) );
   216 ) );
   180 
   217 
   181 get_current_screen()->set_help_sidebar(
   218 get_current_screen()->set_help_sidebar(
   182     '<p><strong>' . __('For more information:') . '</strong></p>' .
   219     '<p><strong>' . __('For more information:') . '</strong></p>' .
   183     '<p>' . __('<a href="https://codex.wordpress.org/Users_Add_New_Screen" target="_blank">Documentation on Adding New Users</a>') . '</p>' .
   220     '<p>' . __('<a href="https://codex.wordpress.org/Users_Add_New_Screen">Documentation on Adding New Users</a>') . '</p>' .
   184     '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   221     '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
   185 );
   222 );
   186 
   223 
   187 wp_enqueue_script('wp-ajax-response');
   224 wp_enqueue_script('wp-ajax-response');
   188 wp_enqueue_script('user-profile');
   225 wp_enqueue_script( 'user-profile' );
   189 
   226 
   190 /**
   227 /**
   191  * Filter whether to enable user auto-complete for non-super admins in Multisite.
   228  * Filters whether to enable user auto-complete for non-super admins in Multisite.
   192  *
   229  *
   193  * @since 3.4.0
   230  * @since 3.4.0
   194  *
   231  *
   195  * @param bool $enable Whether to enable auto-complete for non-super admins. Default false.
   232  * @param bool $enable Whether to enable auto-complete for non-super admins. Default false.
   196  */
   233  */
   197 if ( is_multisite() && current_user_can( 'promote_users' ) && ! wp_is_large_network( 'users' )
   234 if ( is_multisite() && current_user_can( 'promote_users' ) && ! wp_is_large_network( 'users' )
   198 	&& ( is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) )
   235 	&& ( current_user_can( 'manage_network_users' ) || apply_filters( 'autocomplete_users_for_site_admins', false ) )
   199 ) {
   236 ) {
   200 	wp_enqueue_script( 'user-suggest' );
   237 	wp_enqueue_script( 'user-suggest' );
   201 }
   238 }
   202 
   239 
   203 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   240 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   204 
   241 
   205 if ( isset($_GET['update']) ) {
   242 if ( isset($_GET['update']) ) {
   206 	$messages = array();
   243 	$messages = array();
   207 	if ( is_multisite() ) {
   244 	if ( is_multisite() ) {
       
   245 		$edit_link = '';
       
   246 		if ( ( isset( $_GET['user_id'] ) ) ) {
       
   247 			$user_id_new = absint( $_GET['user_id'] );
       
   248 			if ( $user_id_new ) {
       
   249 				$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) );
       
   250 			}
       
   251 		}
       
   252 
   208 		switch ( $_GET['update'] ) {
   253 		switch ( $_GET['update'] ) {
   209 			case "newuserconfirmation":
   254 			case "newuserconfirmation":
   210 				$messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.');
   255 				$messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.');
   211 				break;
   256 				break;
   212 			case "add":
   257 			case "add":
   213 				$messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.');
   258 				$messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.');
   214 				break;
   259 				break;
   215 			case "addnoconfirmation":
   260 			case "addnoconfirmation":
   216 				$messages[] = __('User has been added to your site.');
   261 				if ( empty( $edit_link ) ) {
       
   262 					$messages[] = __( 'User has been added to your site.' );
       
   263 				} else {
       
   264 					/* translators: %s: edit page url */
       
   265 					$messages[] = sprintf( __( 'User has been added to your site. <a href="%s">Edit user</a>' ), $edit_link );
       
   266 				}
   217 				break;
   267 				break;
   218 			case "addexisting":
   268 			case "addexisting":
   219 				$messages[] = __('That user is already a member of this site.');
   269 				$messages[] = __('That user is already a member of this site.');
   220 				break;
   270 				break;
       
   271 			case "could_not_add":
       
   272 				$add_user_errors = new WP_Error( 'could_not_add', __( 'That user could not be added to this site.' ) );
       
   273 				break;
       
   274 			case "created_could_not_add":
       
   275 				$add_user_errors = new WP_Error( 'created_could_not_add', __( 'User has been created, but could not be added to this site.' ) );
       
   276 				break;
   221 			case "does_not_exist":
   277 			case "does_not_exist":
   222 				$messages[] = __('The requested user does not exist.');
   278 				$add_user_errors = new WP_Error( 'does_not_exist', __( 'The requested user does not exist.' ) );
   223 				break;
   279 				break;
   224 			case "enter_email":
   280 			case "enter_email":
   225 				$messages[] = __('Please enter a valid email address.');
   281 				$add_user_errors = new WP_Error( 'enter_email', __( 'Please enter a valid email address.' ) );
   226 				break;
   282 				break;
   227 		}
   283 		}
   228 	} else {
   284 	} else {
   229 		if ( 'add' == $_GET['update'] )
   285 		if ( 'add' == $_GET['update'] )
   230 			$messages[] = __('User added.');
   286 			$messages[] = __('User added.');
   231 	}
   287 	}
   232 }
   288 }
   233 ?>
   289 ?>
   234 <div class="wrap">
   290 <div class="wrap">
   235 <h2 id="add-new-user"> <?php
   291 <h1 id="add-new-user"><?php
   236 if ( current_user_can( 'create_users' ) ) {
   292 if ( current_user_can( 'create_users' ) ) {
   237 	echo _x( 'Add New User', 'user' );
   293 	_e( 'Add New User' );
   238 } elseif ( current_user_can( 'promote_users' ) ) {
   294 } elseif ( current_user_can( 'promote_users' ) ) {
   239 	echo _x( 'Add Existing User', 'user' );
   295 	_e( 'Add Existing User' );
   240 } ?>
   296 } ?>
   241 </h2>
   297 </h1>
   242 
   298 
   243 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
   299 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
   244 	<div class="error">
   300 	<div class="error">
   245 		<ul>
   301 		<ul>
   246 		<?php
   302 		<?php
   265 	</div>
   321 	</div>
   266 <?php endif; ?>
   322 <?php endif; ?>
   267 <div id="ajax-response"></div>
   323 <div id="ajax-response"></div>
   268 
   324 
   269 <?php
   325 <?php
   270 if ( is_multisite() ) {
   326 if ( is_multisite() && current_user_can( 'promote_users' ) ) {
   271 	if ( $do_both )
   327 	if ( $do_both )
   272 		echo '<h3 id="add-existing-user">' . __('Add Existing User') . '</h3>';
   328 		echo '<h2 id="add-existing-user">' . __( 'Add Existing User' ) . '</h2>';
   273 	if ( !is_super_admin() ) {
   329 	if ( ! current_user_can( 'manage_network_users' ) ) {
   274 		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>';
   330 		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>';
   275 		$label = __('E-mail');
   331 		$label = __('Email');
   276 		$type  = 'email';
   332 		$type  = 'email';
   277 	} else {
   333 	} else {
   278 		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>';
   334 		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>';
   279 		$label = __('E-mail or Username');
   335 		$label = __('Email or Username');
   280 		$type  = 'text';
   336 		$type  = 'text';
   281 	}
   337 	}
   282 ?>
   338 ?>
   283 <form method="post" name="adduser" id="adduser" class="validate" novalidate="novalidate"<?php
   339 <form method="post" name="adduser" id="adduser" class="validate" novalidate="novalidate"<?php
   284 	/**
   340 	/**
   301 		<td><select name="role" id="adduser-role">
   357 		<td><select name="role" id="adduser-role">
   302 			<?php wp_dropdown_roles( get_option('default_role') ); ?>
   358 			<?php wp_dropdown_roles( get_option('default_role') ); ?>
   303 			</select>
   359 			</select>
   304 		</td>
   360 		</td>
   305 	</tr>
   361 	</tr>
   306 <?php if ( is_super_admin() ) { ?>
   362 <?php if ( current_user_can( 'manage_network_users' ) ) { ?>
   307 	<tr>
   363 	<tr>
   308 		<th scope="row"><label for="adduser-noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
   364 		<th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
   309 		<td><label for="adduser-noconfirmation"><input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" /> <?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label></td>
   365 		<td>
       
   366 			<input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" />
       
   367 			<label for="adduser-noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label>
       
   368 		</td>
   310 	</tr>
   369 	</tr>
   311 <?php } ?>
   370 <?php } ?>
   312 </table>
   371 </table>
   313 <?php
   372 <?php
   314 /**
   373 /**
   329 <?php
   388 <?php
   330 } // is_multisite()
   389 } // is_multisite()
   331 
   390 
   332 if ( current_user_can( 'create_users') ) {
   391 if ( current_user_can( 'create_users') ) {
   333 	if ( $do_both )
   392 	if ( $do_both )
   334 		echo '<h3 id="create-new-user">' . __( 'Add New User' ) . '</h3>';
   393 		echo '<h2 id="create-new-user">' . __( 'Add New User' ) . '</h2>';
   335 ?>
   394 ?>
   336 <p><?php _e('Create a brand new user and add them to this site.'); ?></p>
   395 <p><?php _e('Create a brand new user and add them to this site.'); ?></p>
   337 <form method="post" name="createuser" id="createuser" class="validate" novalidate="novalidate"<?php
   396 <form method="post" name="createuser" id="createuser" class="validate" novalidate="novalidate"<?php
   338 	/** This action is documented in wp-admin/user-new.php */
   397 	/** This action is documented in wp-admin/user-new.php */
   339 	do_action( 'user_new_form_tag' );
   398 	do_action( 'user_new_form_tag' );
   348 $new_user_firstname = $creating && isset( $_POST['first_name'] ) ? wp_unslash( $_POST['first_name'] ) : '';
   407 $new_user_firstname = $creating && isset( $_POST['first_name'] ) ? wp_unslash( $_POST['first_name'] ) : '';
   349 $new_user_lastname = $creating && isset( $_POST['last_name'] ) ? wp_unslash( $_POST['last_name'] ) : '';
   408 $new_user_lastname = $creating && isset( $_POST['last_name'] ) ? wp_unslash( $_POST['last_name'] ) : '';
   350 $new_user_email = $creating && isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';
   409 $new_user_email = $creating && isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';
   351 $new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : '';
   410 $new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : '';
   352 $new_user_role = $creating && isset( $_POST['role'] ) ? wp_unslash( $_POST['role'] ) : '';
   411 $new_user_role = $creating && isset( $_POST['role'] ) ? wp_unslash( $_POST['role'] ) : '';
   353 $new_user_send_password = $creating && isset( $_POST['send_password'] ) ? wp_unslash( $_POST['send_password'] ) : '';
   412 $new_user_send_notification = $creating && ! isset( $_POST['send_user_notification'] ) ? false : true;
   354 $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unslash( $_POST['noconfirmation'] ) : '';
   413 $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unslash( $_POST['noconfirmation'] ) : '';
   355 
   414 
   356 ?>
   415 ?>
   357 <table class="form-table">
   416 <table class="form-table">
   358 	<tr class="form-field form-required">
   417 	<tr class="form-field form-required">
   359 		<th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
   418 		<th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
   360 		<td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td>
   419 		<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" maxlength="60" /></td>
   361 	</tr>
   420 	</tr>
   362 	<tr class="form-field form-required">
   421 	<tr class="form-field form-required">
   363 		<th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
   422 		<th scope="row"><label for="email"><?php _e('Email'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
   364 		<td><input name="email" type="email" id="email" value="<?php echo esc_attr( $new_user_email ); ?>" /></td>
   423 		<td><input name="email" type="email" id="email" value="<?php echo esc_attr( $new_user_email ); ?>" /></td>
   365 	</tr>
   424 	</tr>
   366 <?php if ( !is_multisite() ) { ?>
   425 <?php if ( !is_multisite() ) { ?>
   367 	<tr class="form-field">
   426 	<tr class="form-field">
   368 		<th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
   427 		<th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
   374 	</tr>
   433 	</tr>
   375 	<tr class="form-field">
   434 	<tr class="form-field">
   376 		<th scope="row"><label for="url"><?php _e('Website') ?></label></th>
   435 		<th scope="row"><label for="url"><?php _e('Website') ?></label></th>
   377 		<td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td>
   436 		<td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td>
   378 	</tr>
   437 	</tr>
   379 <?php
   438 	<tr class="form-field form-required user-pass1-wrap">
   380 /**
   439 		<th scope="row">
   381  * Filter the display of the password fields.
   440 			<label for="pass1">
   382  *
   441 				<?php _e( 'Password' ); ?>
   383  * @since 1.5.1
   442 				<span class="description hide-if-js"><?php _e( '(required)' ); ?></span>
   384  *
   443 			</label>
   385  * @param bool $show Whether to show the password fields. Default true.
   444 		</th>
   386  */
       
   387 if ( apply_filters( 'show_password_fields', true ) ) : ?>
       
   388 	<tr class="form-field form-required">
       
   389 		<th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(required)'); ?></span></label></th>
       
   390 		<td>
   445 		<td>
   391 			<input class="hidden" value=" " /><!-- #24364 workaround -->
   446 			<input class="hidden" value=" " /><!-- #24364 workaround -->
   392 			<input name="pass1" type="password" id="pass1" autocomplete="off" />
   447 			<button type="button" class="button wp-generate-pw hide-if-no-js"><?php _e( 'Show password' ); ?></button>
   393 		</td>
   448 			<div class="wp-pwd hide-if-js">
   394 	</tr>
   449 				<?php $initial_password = wp_generate_password( 24 ); ?>
   395 	<tr class="form-field form-required">
   450 				<span class="password-input-wrapper">
   396 		<th scope="row"><label for="pass2"><?php _e('Repeat Password'); ?> <span class="description"><?php /* translators: password input field */_e('(required)'); ?></span></label></th>
   451 					<input type="password" name="pass1" id="pass1" class="regular-text" autocomplete="off" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
       
   452 				</span>
       
   453 				<button type="button" class="button wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
       
   454 					<span class="dashicons dashicons-hidden"></span>
       
   455 					<span class="text"><?php _e( 'Hide' ); ?></span>
       
   456 				</button>
       
   457 				<button type="button" class="button wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel password change' ); ?>">
       
   458 					<span class="text"><?php _e( 'Cancel' ); ?></span>
       
   459 				</button>
       
   460 				<div style="display:none" id="pass-strength-result" aria-live="polite"></div>
       
   461 			</div>
       
   462 		</td>
       
   463 	</tr>
       
   464 	<tr class="form-field form-required user-pass2-wrap hide-if-js">
       
   465 		<th scope="row"><label for="pass2"><?php _e( 'Repeat Password' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
   397 		<td>
   466 		<td>
   398 		<input name="pass2" type="password" id="pass2" autocomplete="off" />
   467 		<input name="pass2" type="password" id="pass2" autocomplete="off" />
   399 		<br />
   468 		</td>
   400 		<div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
   469 	</tr>
   401 		<p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
   470 	<tr class="pw-weak">
       
   471 		<th><?php _e( 'Confirm Password' ); ?></th>
       
   472 		<td>
       
   473 			<label>
       
   474 				<input type="checkbox" name="pw_weak" class="pw-checkbox" />
       
   475 				<?php _e( 'Confirm use of weak password' ); ?>
       
   476 			</label>
   402 		</td>
   477 		</td>
   403 	</tr>
   478 	</tr>
   404 	<tr>
   479 	<tr>
   405 		<th scope="row"><?php _e('Send Password?') ?></th>
   480 		<th scope="row"><?php _e( 'Send User Notification' ) ?></th>
   406 		<td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" value="1" <?php checked( $new_user_send_password ); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td>
   481 		<td>
   407 	</tr>
   482 			<input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> />
   408 <?php endif; ?>
   483 			<label for="send_user_notification"><?php _e( 'Send the new user an email about their account.' ); ?></label>
       
   484 		</td>
       
   485 	</tr>
   409 <?php } // !is_multisite ?>
   486 <?php } // !is_multisite ?>
   410 	<tr class="form-field">
   487 	<tr class="form-field">
   411 		<th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
   488 		<th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
   412 		<td><select name="role" id="role">
   489 		<td><select name="role" id="role">
   413 			<?php
   490 			<?php
   416 			wp_dropdown_roles($new_user_role);
   493 			wp_dropdown_roles($new_user_role);
   417 			?>
   494 			?>
   418 			</select>
   495 			</select>
   419 		</td>
   496 		</td>
   420 	</tr>
   497 	</tr>
   421 	<?php if ( is_multisite() && is_super_admin() ) { ?>
   498 	<?php if ( is_multisite() && current_user_can( 'manage_network_users' ) ) { ?>
   422 	<tr>
   499 	<tr>
   423 		<th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
   500 		<th scope="row"><?php _e( 'Skip Confirmation Email' ); ?></th>
   424 		<td><label for="noconfirmation"><input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" <?php checked( $new_user_ignore_pass ); ?> /> <?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label></td>
   501 		<td>
       
   502 			<input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" <?php checked( $new_user_ignore_pass ); ?> />
       
   503 			<label for="noconfirmation"><?php _e( 'Add the user without sending an email that requires their confirmation.' ); ?></label>
       
   504 		</td>
   425 	</tr>
   505 	</tr>
   426 	<?php } ?>
   506 	<?php } ?>
   427 </table>
   507 </table>
   428 
   508 
   429 <?php
   509 <?php