]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/user-new.php
WordPress 4.3.1-scripts
[autoinstalls/wordpress.git] / wp-admin / user-new.php
1 <?php
2 /**
3  * New User Administration Screen.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11
12 if ( is_multisite() ) {
13         if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) )
14                 wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
15 } elseif ( ! current_user_can( 'create_users' ) ) {
16         wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
17 }
18
19 if ( is_multisite() ) {
20         /**
21          *
22          * @param string $text
23          * @return string
24          */
25         function admin_created_user_email( $text ) {
26                 $roles = get_editable_roles();
27                 $role = $roles[ $_REQUEST['role'] ];
28                 /* translators: 1: Site name, 2: site URL, 3: role */
29                 return sprintf( __( 'Hi,
30 You\'ve been invited to join \'%1$s\' at
31 %2$s with the role of %3$s.
32 If you do not want to join this site please ignore
33 this email. This invitation will expire in a few days.
34
35 Please click the following link to activate your user account:
36 %%s' ), get_bloginfo( 'name' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ) );
37         }
38         add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
39 }
40
41 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
42         check_admin_referer( 'add-user', '_wpnonce_add-user' );
43
44         $user_details = null;
45         $user_email = wp_unslash( $_REQUEST['email'] );
46         if ( false !== strpos( $user_email, '@' ) ) {
47                 $user_details = get_user_by( 'email', $user_email );
48         } else {
49                 if ( is_super_admin() ) {
50                         $user_details = get_user_by( 'login', $user_email );
51                 } else {
52                         wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
53                         die();
54                 }
55         }
56
57         if ( !$user_details ) {
58                 wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) );
59                 die();
60         }
61
62         if ( ! current_user_can('promote_user', $user_details->ID) )
63                 wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
64
65         // Adding an existing user to this blog
66         $new_user_email = $user_details->user_email;
67         $redirect = 'user-new.php';
68         $username = $user_details->user_login;
69         $user_id = $user_details->ID;
70         if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
71                 $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
72         } else {
73                 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
74                         add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
75                         $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
76                 } else {
77                         $newuser_key = substr( md5( $user_id ), 0, 5 );
78                         add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
79
80                         $roles = get_editable_roles();
81                         $role = $roles[ $_REQUEST['role'] ];
82                         /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
83                         $message = __( 'Hi,
84
85 You\'ve been invited to join \'%1$s\' at
86 %2$s with the role of %3$s.
87
88 Please click the following link to confirm the invite:
89 %4$s' );
90                         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/" ) ) );
91                         $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
92                 }
93         }
94         wp_redirect( $redirect );
95         die();
96 } elseif ( isset($_REQUEST['action']) && 'createuser' == $_REQUEST['action'] ) {
97         check_admin_referer( 'create-user', '_wpnonce_create-user' );
98
99         if ( ! current_user_can('create_users') )
100                 wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
101
102         if ( ! is_multisite() ) {
103                 $user_id = edit_user();
104
105                 if ( is_wp_error( $user_id ) ) {
106                         $add_user_errors = $user_id;
107                 } else {
108                         if ( current_user_can( 'list_users' ) )
109                                 $redirect = 'users.php?update=add&id=' . $user_id;
110                         else
111                                 $redirect = add_query_arg( 'update', 'add', 'user-new.php' );
112                         wp_redirect( $redirect );
113                         die();
114                 }
115         } else {
116                 // Adding a new user to this site
117                 $new_user_email = wp_unslash( $_REQUEST['email'] );
118                 $user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email );
119                 if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) {
120                         $add_user_errors = $user_details[ 'errors' ];
121                 } else {
122                         /**
123                          * Filter the user_login, also known as the username, before it is added to the site.
124                          *
125                          * @since 2.0.3
126                          *
127                          * @param string $user_login The sanitized username.
128                          */
129                         $new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) );
130                         if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
131                                 add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
132                                 add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email
133                         }
134                         wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'] ) );
135                         if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
136                                 $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 ) );
137                                 wpmu_activate_signup( $key );
138                                 $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
139                         } else {
140                                 $redirect = add_query_arg( array('update' => 'newuserconfirmation'), 'user-new.php' );
141                         }
142                         wp_redirect( $redirect );
143                         die();
144                 }
145         }
146 }
147
148 $title = __('Add New User');
149 $parent_file = 'users.php';
150
151 $do_both = false;
152 if ( is_multisite() && current_user_can('promote_users') && current_user_can('create_users') )
153         $do_both = true;
154
155 $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>';
156
157 if ( is_multisite() ) {
158         $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>' .
159         '<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>';
160 } else {
161         $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>' .
162         '<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>';
163 }
164
165 $help .= '<p>' . __('Remember to click the Add New User button at the bottom of this screen when you are finished.') . '</p>';
166
167 get_current_screen()->add_help_tab( array(
168         'id'      => 'overview',
169         'title'   => __('Overview'),
170         'content' => $help,
171 ) );
172
173 get_current_screen()->add_help_tab( array(
174 'id'      => 'user-roles',
175 'title'   => __('User Roles'),
176 'content' => '<p>' . __('Here is a basic overview of the different user roles and the permissions associated with each one:') . '</p>' .
177                                 '<ul>' .
178                                 '<li>' . __('Subscribers can read comments/comment/receive newsletters, etc. but cannot create regular site content.') . '</li>' .
179                                 '<li>' . __('Contributors can write and manage their posts but not publish posts or upload media files.') . '</li>' .
180                                 '<li>' . __('Authors can publish and manage their own posts, and are able to upload files.') . '</li>' .
181                                 '<li>' . __('Editors can publish posts, manage posts as well as manage other people&#8217;s posts, etc.') . '</li>' .
182                                 '<li>' . __('Administrators have access to all the administration features.') . '</li>' .
183                                 '</ul>'
184 ) );
185
186 get_current_screen()->set_help_sidebar(
187     '<p><strong>' . __('For more information:') . '</strong></p>' .
188     '<p>' . __('<a href="https://codex.wordpress.org/Users_Add_New_Screen" target="_blank">Documentation on Adding New Users</a>') . '</p>' .
189     '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
190 );
191
192 wp_enqueue_script('wp-ajax-response');
193 wp_enqueue_script( 'user-profile' );
194
195 /**
196  * Filter whether to enable user auto-complete for non-super admins in Multisite.
197  *
198  * @since 3.4.0
199  *
200  * @param bool $enable Whether to enable auto-complete for non-super admins. Default false.
201  */
202 if ( is_multisite() && current_user_can( 'promote_users' ) && ! wp_is_large_network( 'users' )
203         && ( is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) )
204 ) {
205         wp_enqueue_script( 'user-suggest' );
206 }
207
208 require_once( ABSPATH . 'wp-admin/admin-header.php' );
209
210 if ( isset($_GET['update']) ) {
211         $messages = array();
212         if ( is_multisite() ) {
213                 switch ( $_GET['update'] ) {
214                         case "newuserconfirmation":
215                                 $messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.');
216                                 break;
217                         case "add":
218                                 $messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.');
219                                 break;
220                         case "addnoconfirmation":
221                                 $messages[] = __('User has been added to your site.');
222                                 break;
223                         case "addexisting":
224                                 $messages[] = __('That user is already a member of this site.');
225                                 break;
226                         case "does_not_exist":
227                                 $messages[] = __('The requested user does not exist.');
228                                 break;
229                         case "enter_email":
230                                 $messages[] = __('Please enter a valid email address.');
231                                 break;
232                 }
233         } else {
234                 if ( 'add' == $_GET['update'] )
235                         $messages[] = __('User added.');
236         }
237 }
238 ?>
239 <div class="wrap">
240 <h1 id="add-new-user"><?php
241 if ( current_user_can( 'create_users' ) ) {
242         echo _x( 'Add New User', 'user' );
243 } elseif ( current_user_can( 'promote_users' ) ) {
244         echo _x( 'Add Existing User', 'user' );
245 } ?>
246 </h1>
247
248 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
249         <div class="error">
250                 <ul>
251                 <?php
252                         foreach ( $errors->get_error_messages() as $err )
253                                 echo "<li>$err</li>\n";
254                 ?>
255                 </ul>
256         </div>
257 <?php endif;
258
259 if ( ! empty( $messages ) ) {
260         foreach ( $messages as $msg )
261                 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
262 } ?>
263
264 <?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?>
265         <div class="error">
266                 <?php
267                         foreach ( $add_user_errors->get_error_messages() as $message )
268                                 echo "<p>$message</p>";
269                 ?>
270         </div>
271 <?php endif; ?>
272 <div id="ajax-response"></div>
273
274 <?php
275 if ( is_multisite() ) {
276         if ( $do_both )
277                 echo '<h3 id="add-existing-user">' . __('Add Existing User') . '</h3>';
278         if ( !is_super_admin() ) {
279                 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>';
280                 $label = __('E-mail');
281                 $type  = 'email';
282         } else {
283                 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>';
284                 $label = __('E-mail or Username');
285                 $type  = 'text';
286         }
287 ?>
288 <form method="post" name="adduser" id="adduser" class="validate" novalidate="novalidate"<?php
289         /**
290          * Fires inside the adduser form tag.
291          *
292          * @since 3.0.0
293          */
294         do_action( 'user_new_form_tag' );
295 ?>>
296 <input name="action" type="hidden" value="adduser" />
297 <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?>
298
299 <table class="form-table">
300         <tr class="form-field form-required">
301                 <th scope="row"><label for="adduser-email"><?php echo $label; ?></label></th>
302                 <td><input name="email" type="<?php echo $type; ?>" id="adduser-email" class="wp-suggest-user" value="" /></td>
303         </tr>
304         <tr class="form-field">
305                 <th scope="row"><label for="adduser-role"><?php _e('Role'); ?></label></th>
306                 <td><select name="role" id="adduser-role">
307                         <?php wp_dropdown_roles( get_option('default_role') ); ?>
308                         </select>
309                 </td>
310         </tr>
311 <?php if ( is_super_admin() ) { ?>
312         <tr>
313                 <th scope="row"><label for="adduser-noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
314                 <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>
315         </tr>
316 <?php } ?>
317 </table>
318 <?php
319 /**
320  * Fires at the end of the new user form.
321  *
322  * Passes a contextual string to make both types of new user forms
323  * uniquely targetable. Contexts are 'add-existing-user' (Multisite),
324  * and 'add-new-user' (single site and network admin).
325  *
326  * @since 3.7.0
327  *
328  * @param string $type A contextual string specifying which type of new user form the hook follows.
329  */
330 do_action( 'user_new_form', 'add-existing-user' );
331 ?>
332 <?php submit_button( __( 'Add Existing User' ), 'primary', 'adduser', true, array( 'id' => 'addusersub' ) ); ?>
333 </form>
334 <?php
335 } // is_multisite()
336
337 if ( current_user_can( 'create_users') ) {
338         if ( $do_both )
339                 echo '<h3 id="create-new-user">' . __( 'Add New User' ) . '</h3>';
340 ?>
341 <p><?php _e('Create a brand new user and add them to this site.'); ?></p>
342 <form method="post" name="createuser" id="createuser" class="validate" novalidate="novalidate"<?php
343         /** This action is documented in wp-admin/user-new.php */
344         do_action( 'user_new_form_tag' );
345 ?>>
346 <input name="action" type="hidden" value="createuser" />
347 <?php wp_nonce_field( 'create-user', '_wpnonce_create-user' ); ?>
348 <?php
349 // Load up the passed data, else set to a default.
350 $creating = isset( $_POST['createuser'] );
351
352 $new_user_login = $creating && isset( $_POST['user_login'] ) ? wp_unslash( $_POST['user_login'] ) : '';
353 $new_user_firstname = $creating && isset( $_POST['first_name'] ) ? wp_unslash( $_POST['first_name'] ) : '';
354 $new_user_lastname = $creating && isset( $_POST['last_name'] ) ? wp_unslash( $_POST['last_name'] ) : '';
355 $new_user_email = $creating && isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';
356 $new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : '';
357 $new_user_role = $creating && isset( $_POST['role'] ) ? wp_unslash( $_POST['role'] ) : '';
358 $new_user_send_password = $creating && isset( $_POST['send_password'] ) ? wp_unslash( $_POST['send_password'] ) : true;
359 $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unslash( $_POST['noconfirmation'] ) : '';
360
361 ?>
362 <table class="form-table">
363         <tr class="form-field form-required">
364                 <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
365                 <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" /></td>
366         </tr>
367         <tr class="form-field form-required">
368                 <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
369                 <td><input name="email" type="email" id="email" value="<?php echo esc_attr( $new_user_email ); ?>" /></td>
370         </tr>
371 <?php if ( !is_multisite() ) { ?>
372         <tr class="form-field">
373                 <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
374                 <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td>
375         </tr>
376         <tr class="form-field">
377                 <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
378                 <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td>
379         </tr>
380         <tr class="form-field">
381                 <th scope="row"><label for="url"><?php _e('Website') ?></label></th>
382                 <td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td>
383         </tr>
384 <?php
385 /**
386  * Filter the display of the password fields.
387  *
388  * @since 1.5.1
389  *
390  * @param bool $show Whether to show the password fields. Default true.
391  */
392 if ( apply_filters( 'show_password_fields', true ) ) : ?>
393         <tr class="form-field form-required user-pass1-wrap">
394                 <th scope="row">
395                         <label for="pass1">
396                                 <?php _e( 'Password' ); ?>
397                                 <span class="description hide-if-js"><?php _e( '(required)' ); ?></span>
398                         </label>
399                 </th>
400                 <td>
401                         <input class="hidden" value=" " /><!-- #24364 workaround -->
402                         <button type="button" class="button button-secondary wp-generate-pw hide-if-no-js"><?php _e( 'Show password' ); ?></button>
403                         <div class="wp-pwd hide-if-js">
404                                 <?php $initial_password = wp_generate_password( 24 ); ?>
405                                 <span class="password-input-wrapper">
406                                         <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" />
407                                 </span>
408                                 <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
409                                         <span class="dashicons dashicons-hidden"></span>
410                                         <span class="text"><?php _e( 'Hide' ); ?></span>
411                                 </button>
412                                 <button type="button" class="button button-secondary wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel password change' ); ?>">
413                                         <span class="text"><?php _e( 'Cancel' ); ?></span>
414                                 </button>
415                                 <div style="display:none" id="pass-strength-result" aria-live="polite"></div>
416                         </div>
417                         <p><span class="description"><?php _e( 'A password reset link will be sent to the user via email.' ); ?></span></p>
418                 </td>
419         </tr>
420         <tr class="form-field form-required user-pass2-wrap hide-if-js">
421                 <th scope="row"><label for="pass2"><?php _e( 'Repeat Password' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
422                 <td>
423                 <input name="pass2" type="password" id="pass2" autocomplete="off" />
424                 </td>
425         </tr>
426         <tr class="pw-weak">
427                 <th><?php _e( 'Confirm Password' ); ?></th>
428                 <td>
429                         <label>
430                                 <input type="checkbox" name="pw_weak" class="pw-checkbox" />
431                                 <?php _e( 'Confirm use of weak password' ); ?>
432                         </label>
433                 </td>
434         </tr>
435 <?php endif; ?>
436 <?php } // !is_multisite ?>
437         <tr class="form-field">
438                 <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
439                 <td><select name="role" id="role">
440                         <?php
441                         if ( !$new_user_role )
442                                 $new_user_role = !empty($current_role) ? $current_role : get_option('default_role');
443                         wp_dropdown_roles($new_user_role);
444                         ?>
445                         </select>
446                 </td>
447         </tr>
448         <?php if ( is_multisite() && is_super_admin() ) { ?>
449         <tr>
450                 <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
451                 <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>
452         </tr>
453         <?php } ?>
454 </table>
455
456 <?php
457 /** This action is documented in wp-admin/user-new.php */
458 do_action( 'user_new_form', 'add-new-user' );
459 ?>
460
461 <?php submit_button( __( 'Add New User' ), 'primary', 'createuser', true, array( 'id' => 'createusersub' ) ); ?>
462
463 </form>
464 <?php } // current_user_can('create_users') ?>
465 </div>
466 <?php
467 include( ABSPATH . 'wp-admin/admin-footer.php' );