Changes from trunk/wp-admin/user-new.php at r17431 to branches/3.0/wp-admin/user-new.php at r15370
- File:
-
- 1 edited
-
branches/3.0/wp-admin/user-new.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/wp-admin/user-new.php
r17431 r15370 10 10 require_once('./admin.php'); 11 11 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 } 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'); 18 20 19 21 if ( is_multisite() ) { 20 22 function admin_created_user_email( $text ) { 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. 23 return sprintf( __( "Hi, 24 You've been invited to join '%s' at 25 %s as a %s. 25 26 If you do not want to join this site please ignore 26 27 this email. This invitation will expire in a few days. 27 28 28 29 Please click the following link to activate your user account: 29 %%s '), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) );30 %%s" ), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) ); 30 31 } 31 32 add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' ); … … 37 38 38 39 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) { 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?')); 40 check_admin_referer('add-user'); 87 41 88 42 if ( !is_multisite() ) { … … 102 56 } 103 57 } else { 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' ); 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' ); 119 68 } else { 120 $redirect = add_query_arg( array('update' => 'newuserconfimation'), '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' ); 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 } 121 79 } 122 80 wp_redirect( $redirect ); 123 81 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 } 124 104 } 125 105 } 126 106 } 127 128 107 129 108 $title = __('Add New User'); 130 109 $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;135 110 136 111 add_contextual_help($current_screen, … … 153 128 wp_enqueue_script('wp-ajax-response'); 154 129 wp_enqueue_script('user-profile'); 130 wp_enqueue_script('password-strength-meter'); 155 131 156 132 require_once ('admin-header.php'); … … 172 148 $messages[] = __('That user is already a member of this site.'); 173 149 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;180 150 } 181 151 } else { … … 187 157 <div class="wrap"> 188 158 <?php screen_icon(); ?> 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> 159 <h2 id="add-new-user"><?php _e('Add New User') ?></h2> 196 160 197 161 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?> … … 222 186 223 187 <?php 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 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 ?> 239 210 <table class="form-table"> 240 211 <tr class="form-field form-required"> 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> 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> 288 214 <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td> 289 215 </tr> … … 318 244 <tr> 319 245 <th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th> 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>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> 321 247 </tr> 322 248 <?php endif; ?> … … 336 262 <tr> 337 263 <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th> 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 aconfirmation email.' ); ?></label></td>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> 339 265 </tr> 340 266 <?php } ?> 341 267 </table> 342 343 <?php submit_button( __( 'Add New User '), 'primary', 'createuser', true, array( 'id' => 'createusersub' ) ); ?>344 268 <p class="submit"> 269 <input name="adduser" type="submit" id="addusersub" class="button-primary" value="<?php esc_attr_e('Add User') ?>" /> 270 </p> 345 271 </form> 346 <?php } // current_user_can('create_users') ?> 272 347 273 </div> 348 274 <?php
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)