WordPress 3.0 beta 1 documentation kindly provided to you by Hay Kranen
| [ Index ] |
PHP Cross Reference of WordPress 3.0 beta 1 |
|
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * New User Administration Panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once ('admin.php'); 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'); 20 21 if ( is_multisite() ) { 22 function admin_created_user_email( $text ) { 23 return sprintf( __( "Hi, 24 You've been invited to join '%s' at 25 %s as a %s. 26 If you do not want to join this blog please ignore 27 this email. This invitation will expire in a few days. 28 29 Please click the following link to activate your user account: 30 %%s" ), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) ); 31 } 32 add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' ); 33 34 function admin_created_user_subject( $text ) { 35 return "[" . get_bloginfo('name') . "] Your blog invite"; 36 } 37 } 38 39 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) { 40 check_admin_referer('add-user'); 41 42 if ( !is_multisite() ) { 43 $user_id = add_user(); 44 45 if ( is_wp_error( $user_id ) ) { 46 $add_user_errors = $user_id; 47 } else { 48 $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true)); 49 $redirect = 'users.php?usersearch='. urlencode($new_user_login) . '&update=add'; 50 wp_redirect( $redirect . '#user-' . $user_id ); 51 die(); 52 } 53 } else { 54 $user_login = preg_replace( "/\s+/", '', sanitize_user( $_REQUEST[ 'user_login' ], true ) ); 55 $user_details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE user_login = %s AND user_email = %s", $user_login, $_REQUEST[ 'email' ] ) ); 56 if ( $user_details ) { 57 // Adding an existing user to this blog 58 $new_user_email = esc_html(trim($_REQUEST['email'])); 59 $redirect = 'user-new.php'; 60 $username = $user_details->user_login; 61 $user_id = $user_details->ID; 62 if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) { 63 $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' ); 64 } else { 65 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { 66 add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) ); 67 $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); 68 } else { 69 $newuser_key = substr( md5( $user_id ), 0, 5 ); 70 add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) ); 71 $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"); 72 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/"))); 73 $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' ); 74 } 75 } 76 wp_redirect( $redirect ); 77 die(); 78 } else { 79 // Adding a new user to this blog 80 $user_details = wpmu_validate_user_signup( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ] ); 81 unset( $user_details[ 'errors' ]->errors[ 'user_email_used' ] ); 82 if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) { 83 $add_user_errors = $user_details[ 'errors' ]; 84 } else { 85 $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true)); 86 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { 87 add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email 88 } 89 wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) ); 90 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { 91 $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' ] ) ); 92 wpmu_activate_signup( $key ); 93 $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); 94 } else { 95 $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' ); 96 } 97 wp_redirect( $redirect ); 98 die(); 99 } 100 } 101 } 102 } 103 104 $title = __('Add New User'); 105 $parent_file = 'users.php'; 106 107 wp_enqueue_script('wp-ajax-response'); 108 wp_enqueue_script('user-profile'); 109 wp_enqueue_script('password-strength-meter'); 110 111 require_once ('admin-header.php'); 112 113 if ( isset($_GET[ 'update' ]) && is_multisite() ) { 114 switch ( $_GET[ 'update' ] ) { 115 case "newuserconfimation": 116 $messages[] = '<div id="message" class="updated fade"><p>' . __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.') . '</p></div>'; 117 break; 118 case "add": 119 $messages[] = '<div id="message" class="updated fade"><p>' . __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your blog.') . '</p></div>'; 120 break; 121 case "addnoconfirmation": 122 $messages[] = '<div id="message" class="updated fade"><p>' . __('User has been added to your blog.') . '</p></div>'; 123 break; 124 case "addexisting": 125 $messages[] = '<div id="message" class="updated fade"><p>' . __('That user is already a member of this blog.') . '</p></div>'; 126 break; 127 } 128 } 129 ?> 130 <div class="wrap"> 131 <?php screen_icon(); ?> 132 <h2 id="add-new-user"><?php _e('Add New User') ?></h2> 133 134 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?> 135 <div class="error"> 136 <ul> 137 <?php 138 foreach ( $errors->get_error_messages() as $err ) 139 echo "<li>$err</li>\n"; 140 ?> 141 </ul> 142 </div> 143 <?php endif; 144 145 if ( ! empty($messages) ) { 146 foreach ( $messages as $msg ) 147 echo $msg; 148 } ?> 149 150 <?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?> 151 <div class="error"> 152 <?php 153 foreach ( $add_user_errors->get_error_messages() as $message ) 154 echo "<p>$message</p>"; 155 ?> 156 </div> 157 <?php endif; ?> 158 <div id="ajax-response"></div> 159 160 <?php 161 if ( !is_multisite() ) { 162 if ( get_option('users_can_register') ) 163 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>'; 164 else 165 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>'; 166 } else { 167 echo '<p>' . __( 'You can add new users to your blog 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>'; 168 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>'; 169 } 170 ?> 171 <form action="#add-new-user" method="post" name="adduser" id="adduser" class="add:users: validate"> 172 <?php wp_nonce_field('add-user') ?> 173 <?php 174 //Load up the passed data, else set to a default. 175 foreach ( array('user_login' => 'login', 'first_name' => 'firstname', 'last_name' => 'lastname', 176 'email' => 'email', 'url' => 'uri', 'role' => 'role') as $post_field => $var ) { 177 $var = "new_user_$var"; 178 if ( ! isset($$var) ) 179 $$var = isset($_POST[$post_field]) ? stripslashes($_POST[$post_field]) : ''; 180 } 181 $new_user_send_password = !$_POST || isset($_POST['send_password']); 182 ?> 183 <table class="form-table"> 184 <tr class="form-field form-required"> 185 <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label> 186 <input name="action" type="hidden" id="action" value="adduser" /></th> 187 <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td> 188 </tr> 189 <tr class="form-field form-required"> 190 <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> 191 <td><input name="email" type="text" id="email" value="<?php echo esc_attr($new_user_email); ?>" /></td> 192 </tr> 193 <?php if ( !is_multisite() ) { ?> 194 <tr class="form-field"> 195 <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th> 196 <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td> 197 </tr> 198 <tr class="form-field"> 199 <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th> 200 <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td> 201 </tr> 202 <tr class="form-field"> 203 <th scope="row"><label for="url"><?php _e('Website') ?></label></th> 204 <td><input name="url" type="text" id="url" class="code" value="<?php echo esc_attr($new_user_uri); ?>" /></td> 205 </tr> 206 <?php if ( apply_filters('show_password_fields', true) ) : ?> 207 <tr class="form-field form-required"> 208 <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th> 209 <td><input name="pass1" type="password" id="pass1" autocomplete="off" /> 210 <br /> 211 <input name="pass2" type="password" id="pass2" autocomplete="off" /> 212 <br /> 213 <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div> 214 <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> 215 </td> 216 </tr> 217 <tr> 218 <th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th> 219 <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> 220 </tr> 221 <?php endif; ?> 222 <?php } // !is_multisite ?> 223 <tr class="form-field"> 224 <th scope="row"><label for="role"><?php _e('Role'); ?></label></th> 225 <td><select name="role" id="role"> 226 <?php 227 if ( !$new_user_role ) 228 $new_user_role = !empty($current_role) ? $current_role : get_option('default_role'); 229 wp_dropdown_roles($new_user_role); 230 ?> 231 </select> 232 </td> 233 </tr> 234 <?php if ( is_multisite() && is_super_admin() ) { ?> 235 <tr> 236 <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th> 237 <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> 238 </tr> 239 <?php } ?> 240 </table> 241 <p class="submit"> 242 <input name="adduser" type="submit" id="addusersub" class="button-primary" value="<?php esc_attr_e('Add User') ?>" /> 243 </p> 244 </form> 245 246 </div> 247 <?php 248 include ('admin-footer.php'); 249 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 5 14:26:09 2010 | Cross-referenced by PHPXref 0.7 |