Changes from branches/3.0/wp-admin/user-new.php at r15370 to trunk/wp-admin/user-new.php at r17431
- File:
-
- 1 edited
-
trunk/wp-admin/user-new.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/user-new.php
r15370 r17431 10 10 require_once('./admin.php'); 11 11 12 if ( !current_user_can('create_users') ) 13 wp_die(__('Cheatin’ uh?')); 14 15 if ( is_multisite() && !get_site_option( 'add_new_users' ) ) 16 wp_die( __('Page disabled by the administrator') ); 17 18 /** WordPress Registration API */ 19 require_once( ABSPATH . WPINC . '/registration.php'); 12 if ( is_multisite() ) { 13 if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) ) 14 wp_die( __( 'Cheatin’ uh?' ) ); 15 } elseif ( ! current_user_can( 'create_users' ) ) { 16 wp_die( __( 'Cheatin’ uh?' ) ); 17 } 20 18 21 19 if ( is_multisite() ) { 22 20 function admin_created_user_email( $text ) { 23 return sprintf( __( "Hi, 24 You've been invited to join '%s' at 25 %s as a %s. 21 /* translators: 1: Site name, 2: site URL, 3: role */ 22 return sprintf( __( 'Hi, 23 You\'ve been invited to join \'%1$s\' at 24 %2$s as a %3$s. 26 25 If you do not want to join this site please ignore 27 26 this email. This invitation will expire in a few days. 28 27 29 28 Please click the following link to activate your user account: 30 %%s "), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) );29 %%s' ), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) ); 31 30 } 32 31 add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' ); … … 38 37 39 38 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) { 40 check_admin_referer('add-user'); 39 check_admin_referer( 'add-user', '_wpnonce_add-user' ); 40 41 $user_details = null; 42 if ( false !== strpos($_REQUEST[ 'email' ], '@') ) { 43 $user_details = get_user_by('email', $_REQUEST[ 'email' ]); 44 } else { 45 if ( is_super_admin() ) { 46 $user_details = get_user_by('login', $_REQUEST[ 'email' ]); 47 } else { 48 wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) ); 49 die(); 50 } 51 } 52 53 if ( !$user_details ) { 54 wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) ); 55 die(); 56 } 57 58 if ( ! current_user_can('promote_user', $user_details->ID) ) 59 wp_die(__('Cheatin’ uh?')); 60 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' ); 68 } else { 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' ); 72 } else { 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' ); 78 } 79 } 80 wp_redirect( $redirect ); 81 die(); 82 } elseif ( isset($_REQUEST['action']) && 'createuser' == $_REQUEST['action'] ) { 83 check_admin_referer( 'create-user', '_wpnonce_create-user' ); 84 85 if ( ! current_user_can('create_users') ) 86 wp_die(__('Cheatin’ uh?')); 41 87 42 88 if ( !is_multisite() ) { … … 56 102 } 57 103 } else { 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' ); 104 // Adding a new user to this blog 105 $user_details = wpmu_validate_user_signup( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ] ); 106 unset( $user_details[ 'errors' ]->errors[ 'user_email_used' ] ); 107 if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) { 108 $add_user_errors = $user_details[ 'errors' ]; 109 } else { 110 $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true)); 111 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { 112 add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email 113 } 114 wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) ); 115 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { 116 $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' ] ) ); 117 wpmu_activate_signup( $key ); 118 $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); 68 119 } else { 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' ); 72 } else { 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' ); 78 } 120 $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' ); 79 121 } 80 122 wp_redirect( $redirect ); 81 123 die(); 82 } else { 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' ]; 88 } else { 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 92 } 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' ); 98 } else { 99 $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' ); 100 } 101 wp_redirect( $redirect ); 102 die(); 103 } 104 } 105 } 106 } 124 } 125 } 126 } 127 107 128 108 129 $title = __('Add New User'); 109 130 $parent_file = 'users.php'; 131 132 $do_both = false; 133 if ( is_multisite() && current_user_can('promote_users') && current_user_can('create_users') ) 134 $do_both = true; 110 135 111 136 add_contextual_help($current_screen, … … 128 153 wp_enqueue_script('wp-ajax-response'); 129 154 wp_enqueue_script('user-profile'); 130 wp_enqueue_script('password-strength-meter');131 155 132 156 require_once ('admin-header.php'); … … 148 172 $messages[] = __('That user is already a member of this site.'); 149 173 break; 174 case "does_not_exist": 175 $messages[] = __('The requested user does not exist.'); 176 break; 177 case "does_not_exist": 178 $messages[] = __('Please enter a valid email address.'); 179 break; 150 180 } 151 181 } else { … … 157 187 <div class="wrap"> 158 188 <?php screen_icon(); ?> 159 <h2 id="add-new-user"><?php _e('Add New User') ?></h2> 189 <h2 id="add-new-user"> <?php 190 if ( current_user_can( 'create_users' ) ) { 191 echo _x( 'Add New User', 'user' ); 192 } elseif ( current_user_can( 'promote_users' ) ) { 193 echo _x( 'Add Existing User', 'user' ); 194 } ?> 195 </h2> 160 196 161 197 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?> … … 186 222 187 223 <?php 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>'; 191 else 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>'; 193 } else { 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>'; 196 } 197 ?> 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') ?> 200 <?php 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]) : ''; 207 } 208 $new_user_send_password = !$_POST || isset($_POST['send_password']); 209 ?> 224 if ( is_multisite() ) { 225 if ( $do_both ) 226 echo '<h3 id="add-existing-user">' . __('Add Existing User') . '</h3>'; 227 if ( !is_super_admin() ) { 228 _e( '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.' ); 229 $label = __('E-mail'); 230 } else { 231 _e( '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.' ); 232 $label = __('E-mail or Username'); 233 } 234 ?> 235 <form action="" method="post" name="adduser" id="adduser" class="add:users: validate"<?php do_action('user_new_form_tag');?>> 236 <input name="action" type="hidden" value="adduser" /> 237 <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?> 238 210 239 <table class="form-table"> 211 240 <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> 241 <th scope="row"><label for="adduser-email"><?php echo $label; ?></label></th> 242 <td><input name="email" type="text" id="adduser-email" value="" /></td> 243 </tr> 244 <tr class="form-field"> 245 <th scope="row"><label for="adduser-role"><?php _e('Role'); ?></label></th> 246 <td><select name="role" id="adduser-role"> 247 <?php wp_dropdown_roles( get_option('default_role') ); ?> 248 </select> 249 </td> 250 </tr> 251 <?php if ( is_super_admin() ) { ?> 252 <tr> 253 <th scope="row"><label for="adduser-noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th> 254 <td><label for="adduser-noconfirmation"><input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" /> <?php _e( 'Add the user without sending them a confirmation email.' ); ?></label></td> 255 </tr> 256 <?php } ?> 257 </table> 258 <?php submit_button( __( 'Add Existing User '), 'primary', 'adduser', true, array( 'id' => 'addusersub' ) ); ?> 259 </form> 260 <?php 261 } // is_multisite() 262 263 if ( current_user_can( 'create_users') ) { 264 if ( $do_both ) 265 echo '<h3 id="create-new-user">' . __( 'Add New User' ) . '</h3>'; 266 ?> 267 <p><?php _e('Create a brand new user and add it to this site.'); ?></p> 268 <form action="" method="post" name="createuser" id="createuser" class="add:users: validate"<?php do_action('user_new_form_tag');?>> 269 <input name="action" type="hidden" value="createuser" /> 270 <?php wp_nonce_field( 'create-user', '_wpnonce_create-user' ) ?> 271 <?php 272 // Load up the passed data, else set to a default. 273 foreach ( array( 'user_login' => 'login', 'first_name' => 'firstname', 'last_name' => 'lastname', 274 'email' => 'email', 'url' => 'uri', 'role' => 'role', 'send_password' => 'send_password', 'noconfirmation' => 'ignore_pass' ) as $post_field => $var ) { 275 $var = "new_user_$var"; 276 if( isset( $_POST['createuser'] ) ) { 277 if ( ! isset($$var) ) 278 $$var = isset( $_POST[$post_field] ) ? stripslashes( $_POST[$post_field] ) : ''; 279 } else { 280 $$var = false; 281 } 282 } 283 284 ?> 285 <table class="form-table"> 286 <tr class="form-field form-required"> 287 <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> 214 288 <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td> 215 289 </tr> … … 244 318 <tr> 245 319 <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>320 <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked( $new_user_send_password ); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td> 247 321 </tr> 248 322 <?php endif; ?> … … 262 336 <tr> 263 337 <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 theconfirmation email.' ); ?></label></td>338 <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 them a confirmation email.' ); ?></label></td> 265 339 </tr> 266 340 <?php } ?> 267 341 </table> 268 <p class="submit"> 269 <input name="adduser" type="submit" id="addusersub" class="button-primary" value="<?php esc_attr_e('Add User') ?>" />270 </p> 342 343 <?php submit_button( __( 'Add New User '), 'primary', 'createuser', true, array( 'id' => 'createusersub' ) ); ?> 344 271 345 </form> 272 346 <?php } // current_user_can('create_users') ?> 273 347 </div> 274 348 <?php
Note: See TracChangeset
for help on using the changeset viewer.