3 * New User Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 if ( !current_user_can('create_users') )
13 wp_die(__('Cheatin’ uh?'));
15 if ( is_multisite() && !get_site_option( 'add_new_users' ) )
16 wp_die( __('Page disabled by the administrator') );
18 /** WordPress Registration API */
19 require_once( ABSPATH . WPINC . '/registration.php');
21 if ( is_multisite() ) {
22 function admin_created_user_email( $text ) {
23 return sprintf( __( "Hi,
24 You've been invited to join '%s' at
26 If you do not want to join this site please ignore
27 this email. This invitation will expire in a few days.
29 Please click the following link to activate your user account:
30 %%s" ), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) );
32 add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
34 function admin_created_user_subject( $text ) {
35 return "[" . get_bloginfo('name') . "] Your site invite";
39 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
40 check_admin_referer('add-user');
42 if ( !is_multisite() ) {
43 $user_id = add_user();
45 if ( is_wp_error( $user_id ) ) {
46 $add_user_errors = $user_id;
48 if ( current_user_can('edit_users') ) {
49 $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
50 $redirect = 'users.php?usersearch='. urlencode($new_user_login) . '&update=add' . '#user-' . $user_id;
52 $redirect = add_query_arg( 'update', 'add', 'user-new.php' );
54 wp_redirect( $redirect );
58 $user_login = preg_replace( "/\s+/", '', sanitize_user( $_REQUEST[ 'user_login' ], true ) );
59 $user_details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE user_login = %s AND user_email = %s", $user_login, $_REQUEST[ 'email' ] ) );
60 if ( $user_details ) {
61 // Adding an existing user to this blog
62 $new_user_email = esc_html(trim($_REQUEST['email']));
63 $redirect = 'user-new.php';
64 $username = $user_details->user_login;
65 $user_id = $user_details->ID;
66 if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
67 $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
69 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
70 add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
71 $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
73 $newuser_key = substr( md5( $user_id ), 0, 5 );
74 add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
75 $message = __("Hi,\n\nYou have been invited to join '%s' at\n%s as a %s.\nPlease click the following link to confirm the invite:\n%s\n");
76 wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ), sprintf($message, get_option('blogname'), site_url(), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/")));
77 $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
80 wp_redirect( $redirect );
83 // Adding a new user to this blog
84 $user_details = wpmu_validate_user_signup( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ] );
85 unset( $user_details[ 'errors' ]->errors[ 'user_email_used' ] );
86 if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) {
87 $add_user_errors = $user_details[ 'errors' ];
89 $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
90 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
91 add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
93 wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) );
94 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
95 $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $_REQUEST[ 'email' ] ) );
96 wpmu_activate_signup( $key );
97 $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
99 $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' );
101 wp_redirect( $redirect );
108 $title = __('Add New User');
109 $parent_file = 'users.php';
111 add_contextual_help($current_screen,
112 '<p>' . __('To add a new user to your site, fill in the form on this screen. If you’re not sure which role to assign, you can use the link below to review the different roles and their capabilities. Here is a basic overview of roles:') . '</p>' .
114 '<li>' . __('Administrators have access to all the administration features.') . '</li>' .
115 '<li>' . __('Editors can publish posts, manage posts as well as manage other people’s posts, etc.') . '</li>' .
116 '<li>' . __('Authors can publish and manage their own posts.') . '</li>' .
117 '<li>' . __('Contributors can write and manage their posts but not publish posts or upload media files.') . '</li>' .
118 '<li>' . __('Subscribers can read comments/comment/receive newsletters, etc.') . '</li>' .
120 '<p>' . __('You must assign a password to the new user, but don’t worry; when they log in for the first time they will be prompted to change it. The username, however, cannot be changed.') . '</p>' .
121 '<p>' . __('New users will receive an email letting them know they’ve been added as a user for your site. By default, this email will also contain their password. Uncheck the box if you do not the password to be included in the welcome email.') . '</p>' .
122 '<p>' . __('Remember to click the Add User button at the bottom of this screen when you are finished.') . '</p>' .
123 '<p><strong>' . __('For more information:') . '</strong></p>' .
124 '<p>' . __('<a href="http://codex.wordpress.org/Users_Add_New_SubPanel" target="_blank">Documentation on Adding New Users</a>') . '</p>' .
125 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
128 wp_enqueue_script('wp-ajax-response');
129 wp_enqueue_script('user-profile');
130 wp_enqueue_script('password-strength-meter');
132 require_once ('admin-header.php');
134 if ( isset($_GET['update']) ) {
136 if ( is_multisite() ) {
137 switch ( $_GET['update'] ) {
138 case "newuserconfimation":
139 $messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.');
142 $messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.');
144 case "addnoconfirmation":
145 $messages[] = __('User has been added to your site.');
148 $messages[] = __('That user is already a member of this site.');
152 if ( 'add' == $_GET['update'] )
153 $messages[] = __('User added.');
158 <?php screen_icon(); ?>
159 <h2 id="add-new-user"><?php _e('Add New User') ?></h2>
161 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
165 foreach ( $errors->get_error_messages() as $err )
166 echo "<li>$err</li>\n";
172 if ( ! empty( $messages ) ) {
173 foreach ( $messages as $msg )
174 echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
177 <?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?>
180 foreach ( $add_user_errors->get_error_messages() as $message )
181 echo "<p>$message</p>";
185 <div id="ajax-response"></div>
188 if ( !is_multisite() ) {
189 if ( get_option('users_can_register') )
190 echo '<p>' . sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), site_url('wp-register.php')) . '</p>';
192 echo '<p>' . sprintf(__('Users cannot currently <a href="%1$s">register themselves</a>, but you can manually create users here.'), admin_url('options-general.php#users_can_register')) . '</p>';
194 echo '<p>' . __( 'You can add new users to your site in two ways:' ) . '<ol><li> ' . __( 'Enter the username and email address of an existing user on this site.' ) . '</li><li> ' . __( 'Enter the username and the email address of a person who is not already a member of this site. Choose the username carefully, it cannot be changed.' ) . '</li></ol></p>';
195 echo '<p>' . __( 'That person will be sent an email asking them to click a link confirming the invite. New users will then be sent an email with a randomly generated password and a login link.' ) . '</p>';
198 <form action="#add-new-user" method="post" name="adduser" id="adduser" class="add:users: validate"<?php do_action('user_new_form_tag');?>>
199 <?php wp_nonce_field('add-user') ?>
201 //Load up the passed data, else set to a default.
202 foreach ( array('user_login' => 'login', 'first_name' => 'firstname', 'last_name' => 'lastname',
203 'email' => 'email', 'url' => 'uri', 'role' => 'role') as $post_field => $var ) {
204 $var = "new_user_$var";
205 if ( ! isset($$var) )
206 $$var = isset($_POST[$post_field]) ? stripslashes($_POST[$post_field]) : '';
208 $new_user_send_password = !$_POST || isset($_POST['send_password']);
210 <table class="form-table">
211 <tr class="form-field form-required">
212 <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label>
213 <input name="action" type="hidden" id="action" value="adduser" /></th>
214 <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td>
216 <tr class="form-field form-required">
217 <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
218 <td><input name="email" type="text" id="email" value="<?php echo esc_attr($new_user_email); ?>" /></td>
220 <?php if ( !is_multisite() ) { ?>
221 <tr class="form-field">
222 <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
223 <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td>
225 <tr class="form-field">
226 <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
227 <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td>
229 <tr class="form-field">
230 <th scope="row"><label for="url"><?php _e('Website') ?></label></th>
231 <td><input name="url" type="text" id="url" class="code" value="<?php echo esc_attr($new_user_uri); ?>" /></td>
233 <?php if ( apply_filters('show_password_fields', true) ) : ?>
234 <tr class="form-field form-required">
235 <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th>
236 <td><input name="pass1" type="password" id="pass1" autocomplete="off" />
238 <input name="pass2" type="password" id="pass2" autocomplete="off" />
240 <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
241 <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).'); ?></p>
245 <th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th>
246 <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked($new_user_send_password, true); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td>
249 <?php } // !is_multisite ?>
250 <tr class="form-field">
251 <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
252 <td><select name="role" id="role">
254 if ( !$new_user_role )
255 $new_user_role = !empty($current_role) ? $current_role : get_option('default_role');
256 wp_dropdown_roles($new_user_role);
261 <?php if ( is_multisite() && is_super_admin() ) { ?>
263 <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
264 <td><label for="noconfirmation"><input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" /> <?php _e( 'Site administrators can add a user without sending the confirmation email.' ); ?></label></td>
269 <input name="adduser" type="submit" id="addusersub" class="button-primary" value="<?php esc_attr_e('Add User') ?>" />
275 include('./admin-footer.php');