wp/wp-admin/network/user-new.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    24 		'<p>' . __('Users who are signed up to the network without a site are added as subscribers to the main or primary dashboard site, giving them profile pages to manage their accounts. These users will only see Dashboard and My Sites in the main navigation until a site is created for them.') . '</p>'
    24 		'<p>' . __('Users who are signed up to the network without a site are added as subscribers to the main or primary dashboard site, giving them profile pages to manage their accounts. These users will only see Dashboard and My Sites in the main navigation until a site is created for them.') . '</p>'
    25 ) );
    25 ) );
    26 
    26 
    27 get_current_screen()->set_help_sidebar(
    27 get_current_screen()->set_help_sidebar(
    28 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    28 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    29 	'<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
    29 	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
    30 	'<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
    30 	'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
    31 );
    31 );
    32 
    32 
    33 if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) {
    33 if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) {
    34 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
    34 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
       
    35 
    35 	if ( ! current_user_can( 'manage_network_users' ) )
    36 	if ( ! current_user_can( 'manage_network_users' ) )
    36 		wp_die( __( 'You do not have permission to access this page.' ) );
    37 		wp_die( __( 'You do not have permission to access this page.' ), 403 );
    37 
    38 
    38 	if ( ! is_array( $_POST['user'] ) )
    39 	if ( ! is_array( $_POST['user'] ) )
    39 		wp_die( __( 'Cannot create an empty user.' ) );
    40 		wp_die( __( 'Cannot create an empty user.' ) );
    40 
    41 
    41 	$user = $_POST['user'];
    42 	$user = wp_unslash( $_POST['user'] );
    42 
    43 
    43 	$user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
    44 	$user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
    44 	if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) {
    45 	if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) {
    45 		$add_user_errors = $user_details[ 'errors' ];
    46 		$add_user_errors = $user_details[ 'errors' ];
    46 	} else {
    47 	} else {
    47 		$password = wp_generate_password( 12, false);
    48 		$password = wp_generate_password( 12, false);
    48 		$user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
    49 		$user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) );
    49 
    50 
    50 		if ( ! $user_id ) {
    51 		if ( ! $user_id ) {
    51 	 		$add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
    52 	 		$add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
    52 		} else {
    53 		} else {
    53 			wp_new_user_notification( $user_id, $password );
    54 			wp_new_user_notification( $user_id, $password );
    67 $parent_file = 'users.php';
    68 $parent_file = 'users.php';
    68 
    69 
    69 require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
    70 require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
    70 
    71 
    71 <div class="wrap">
    72 <div class="wrap">
    72 <?php screen_icon(); ?>
       
    73 <h2 id="add-new-user"><?php _e('Add New User') ?></h2>
    73 <h2 id="add-new-user"><?php _e('Add New User') ?></h2>
    74 <?php
    74 <?php
    75 if ( ! empty( $messages ) ) {
    75 if ( ! empty( $messages ) ) {
    76 	foreach ( $messages as $msg )
    76 	foreach ( $messages as $msg )
    77 		echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
    77 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
    78 }
    78 }
    79 
    79 
    80 if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { ?>
    80 if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { ?>
    81 	<div class="error">
    81 	<div class="error">
    82 		<?php
    82 		<?php
    86 	</div>
    86 	</div>
    87 <?php } ?>
    87 <?php } ?>
    88 	<form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post">
    88 	<form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post">
    89 	<table class="form-table">
    89 	<table class="form-table">
    90 		<tr class="form-field form-required">
    90 		<tr class="form-field form-required">
    91 			<th scope="row"><?php _e( 'Username' ) ?></th>
    91 			<th scope="row"><label for="username"><?php _e( 'Username' ) ?></label></th>
    92 			<td><input type="text" class="regular-text" name="user[username]" /></td>
    92 			<td><input type="text" class="regular-text" name="user[username]" id="username" /></td>
    93 		</tr>
    93 		</tr>
    94 		<tr class="form-field form-required">
    94 		<tr class="form-field form-required">
    95 			<th scope="row"><?php _e( 'Email' ) ?></th>
    95 			<th scope="row"><label for="email"><?php _e( 'Email' ) ?></label></th>
    96 			<td><input type="text" class="regular-text" name="user[email]" /></td>
    96 			<td><input type="text" class="regular-text" name="user[email]" id="email"/></td>
    97 		</tr>
    97 		</tr>
    98 		<tr class="form-field">
    98 		<tr class="form-field">
    99 			<td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
    99 			<td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
   100 		</tr>
   100 		</tr>
   101 	</table>
   101 	</table>