wp/wp-admin/network/user-new.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     8  */
     8  */
     9 
     9 
    10 /** Load WordPress Administration Bootstrap */
    10 /** Load WordPress Administration Bootstrap */
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    12 
    12 
    13 if ( ! current_user_can('create_users') )
    13 if ( ! current_user_can( 'create_users' ) ) {
    14 	wp_die(__('Sorry, you are not allowed to add users to this network.'));
    14 	wp_die( __( 'Sorry, you are not allowed to add users to this network.' ) );
       
    15 }
    15 
    16 
    16 get_current_screen()->add_help_tab( array(
    17 get_current_screen()->add_help_tab(
    17 	'id'      => 'overview',
    18 	array(
    18 	'title'   => __('Overview'),
    19 		'id'      => 'overview',
    19 	'content' =>
    20 		'title'   => __( 'Overview' ),
    20 		'<p>' . __('Add User will set up a new user account on the network and send that person an email with username and password.') . '</p>' .
    21 		'content' =>
    21 		'<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>'
    22 			'<p>' . __( 'Add User will set up a new user account on the network and send that person an email with username and password.' ) . '</p>' .
    22 ) );
    23 			'<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 	)
       
    25 );
    23 
    26 
    24 get_current_screen()->set_help_sidebar(
    27 get_current_screen()->set_help_sidebar(
    25 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    28 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    26 	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>') . '</p>' .
    29 	'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' .
    27 	'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>'
    30 	'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
    28 );
    31 );
    29 
    32 
    30 if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) {
    33 if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) {
    31 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
    34 	check_admin_referer( 'add-user', '_wpnonce_add-user' );
    32 
    35 
    33 	if ( ! current_user_can( 'manage_network_users' ) )
    36 	if ( ! current_user_can( 'manage_network_users' ) ) {
    34 		wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    37 		wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
       
    38 	}
    35 
    39 
    36 	if ( ! is_array( $_POST['user'] ) )
    40 	if ( ! is_array( $_POST['user'] ) ) {
    37 		wp_die( __( 'Cannot create an empty user.' ) );
    41 		wp_die( __( 'Cannot create an empty user.' ) );
       
    42 	}
    38 
    43 
    39 	$user = wp_unslash( $_POST['user'] );
    44 	$user = wp_unslash( $_POST['user'] );
    40 
    45 
    41 	$user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
    46 	$user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
    42 	if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) {
    47 	if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) {
    43 		$add_user_errors = $user_details[ 'errors' ];
    48 		$add_user_errors = $user_details['errors'];
    44 	} else {
    49 	} else {
    45 		$password = wp_generate_password( 12, false);
    50 		$password = wp_generate_password( 12, false );
    46 		$user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) );
    51 		$user_id  = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) );
    47 
    52 
    48 		if ( ! $user_id ) {
    53 		if ( ! $user_id ) {
    49 	 		$add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
    54 			$add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
    50 		} else {
    55 		} else {
    51 			/**
    56 			/**
    52 			  * Fires after a new user has been created via the network user-new.php page.
    57 			 * Fires after a new user has been created via the network user-new.php page.
    53 			  *
    58 			 *
    54 			  * @since 4.4.0
    59 			 * @since 4.4.0
    55 			  *
    60 			 *
    56 			  * @param int $user_id ID of the newly created user.
    61 			 * @param int $user_id ID of the newly created user.
    57 			  */
    62 			 */
    58 			do_action( 'network_user_new_created_user', $user_id );
    63 			do_action( 'network_user_new_created_user', $user_id );
    59 			wp_redirect( add_query_arg( array('update' => 'added', 'user_id' => $user_id ), 'user-new.php' ) );
    64 			wp_redirect(
       
    65 				add_query_arg(
       
    66 					array(
       
    67 						'update'  => 'added',
       
    68 						'user_id' => $user_id,
       
    69 					),
       
    70 					'user-new.php'
       
    71 				)
       
    72 			);
    60 			exit;
    73 			exit;
    61 		}
    74 		}
    62 	}
    75 	}
    63 }
    76 }
    64 
    77 
    65 if ( isset($_GET['update']) ) {
    78 if ( isset( $_GET['update'] ) ) {
    66 	$messages = array();
    79 	$messages = array();
    67 	if ( 'added' == $_GET['update'] ) {
    80 	if ( 'added' == $_GET['update'] ) {
    68 		$edit_link = '';
    81 		$edit_link = '';
    69 		if ( isset( $_GET['user_id'] ) ) {
    82 		if ( isset( $_GET['user_id'] ) ) {
    70 			$user_id_new = absint( $_GET['user_id'] );
    83 			$user_id_new = absint( $_GET['user_id'] );
    80 			$messages[] = sprintf( __( 'User added. <a href="%s">Edit user</a>' ), $edit_link );
    93 			$messages[] = sprintf( __( 'User added. <a href="%s">Edit user</a>' ), $edit_link );
    81 		}
    94 		}
    82 	}
    95 	}
    83 }
    96 }
    84 
    97 
    85 $title = __('Add New User');
    98 $title       = __( 'Add New User' );
    86 $parent_file = 'users.php';
    99 $parent_file = 'users.php';
    87 
   100 
    88 require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   101 require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
    89 
   102 
    90 <div class="wrap">
   103 <div class="wrap">
    91 <h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1>
   104 <h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1>
    92 <?php
   105 <?php
    93 if ( ! empty( $messages ) ) {
   106 if ( ! empty( $messages ) ) {
    94 	foreach ( $messages as $msg )
   107 	foreach ( $messages as $msg ) {
    95 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
   108 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
       
   109 	}
    96 }
   110 }
    97 
   111 
    98 if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { ?>
   112 if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) {
       
   113 	?>
    99 	<div class="error">
   114 	<div class="error">
   100 		<?php
   115 		<?php
   101 			foreach ( $add_user_errors->get_error_messages() as $message )
   116 		foreach ( $add_user_errors->get_error_messages() as $message ) {
   102 				echo "<p>$message</p>";
   117 			echo "<p>$message</p>";
       
   118 		}
   103 		?>
   119 		?>
   104 	</div>
   120 	</div>
   105 <?php } ?>
   121 <?php } ?>
   106 	<form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post" novalidate="novalidate">
   122 	<form action="<?php echo network_admin_url( 'user-new.php?action=add-user' ); ?>" id="adduser" method="post" novalidate="novalidate">
   107 	<table class="form-table">
   123 	<table class="form-table" role="presentation">
   108 		<tr class="form-field form-required">
   124 		<tr class="form-field form-required">
   109 			<th scope="row"><label for="username"><?php _e( 'Username' ) ?></label></th>
   125 			<th scope="row"><label for="username"><?php _e( 'Username' ); ?></label></th>
   110 			<td><input type="text" class="regular-text" name="user[username]" id="username" autocapitalize="none" autocorrect="off" maxlength="60" /></td>
   126 			<td><input type="text" class="regular-text" name="user[username]" id="username" autocapitalize="none" autocorrect="off" maxlength="60" /></td>
   111 		</tr>
   127 		</tr>
   112 		<tr class="form-field form-required">
   128 		<tr class="form-field form-required">
   113 			<th scope="row"><label for="email"><?php _e( 'Email' ) ?></label></th>
   129 			<th scope="row"><label for="email"><?php _e( 'Email' ); ?></label></th>
   114 			<td><input type="email" class="regular-text" name="user[email]" id="email"/></td>
   130 			<td><input type="email" class="regular-text" name="user[email]" id="email"/></td>
   115 		</tr>
   131 		</tr>
   116 		<tr class="form-field">
   132 		<tr class="form-field">
   117 			<td colspan="2"><?php _e( 'A password reset link will be sent to the user via email.' ) ?></td>
   133 			<td colspan="2" class="td-full"><?php _e( 'A password reset link will be sent to the user via email.' ); ?></td>
   118 		</tr>
   134 		</tr>
   119 	</table>
   135 	</table>
   120 	<?php
   136 	<?php
   121 	/**
   137 	/**
   122 	 * Fires at the end of the new user form in network admin.
   138 	 * Fires at the end of the new user form in network admin.
   124 	 * @since 4.5.0
   140 	 * @since 4.5.0
   125 	 */
   141 	 */
   126 	do_action( 'network_user_new_form' );
   142 	do_action( 'network_user_new_form' );
   127 
   143 
   128 	wp_nonce_field( 'add-user', '_wpnonce_add-user' );
   144 	wp_nonce_field( 'add-user', '_wpnonce_add-user' );
   129 	submit_button( __('Add User'), 'primary', 'add-user' );
   145 	submit_button( __( 'Add User' ), 'primary', 'add-user' );
   130 	?>
   146 	?>
   131 	</form>
   147 	</form>
   132 </div>
   148 </div>
   133 <?php
   149 <?php
   134 require( ABSPATH . 'wp-admin/admin-footer.php' );
   150 require( ABSPATH . 'wp-admin/admin-footer.php' );