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 * Edit user administration panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once ('admin.php'); 11 12 wp_reset_vars(array('action', 'redirect', 'profile', 'user_id', 'wp_http_referer')); 13 14 $user_id = (int) $user_id; 15 $current_user = wp_get_current_user(); 16 if ( ! defined( 'IS_PROFILE_PAGE' ) ) 17 define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) ); 18 19 if ( ! $user_id && IS_PROFILE_PAGE ) 20 $user_id = $current_user->ID; 21 elseif ( ! $user_id && ! IS_PROFILE_PAGE ) 22 wp_die(__( 'Invalid user ID.' ) ); 23 elseif ( ! get_userdata( $user_id ) ) 24 wp_die( __('Invalid user ID.') ); 25 26 wp_enqueue_script('user-profile'); 27 wp_enqueue_script('password-strength-meter'); 28 29 $title = IS_PROFILE_PAGE ? __('Profile') : __('Edit User'); 30 if ( current_user_can('edit_users') && !IS_PROFILE_PAGE ) 31 $submenu_file = 'users.php'; 32 else 33 $submenu_file = 'profile.php'; 34 $parent_file = 'users.php'; 35 36 $wp_http_referer = remove_query_arg(array('update', 'delete_count'), stripslashes($wp_http_referer)); 37 38 $all_post_caps = array('posts', 'pages'); 39 $user_can_edit = false; 40 foreach ( $all_post_caps as $post_cap ) 41 $user_can_edit |= current_user_can("edit_$post_cap"); 42 43 /** 44 * Optional SSL preference that can be turned on by hooking to the 'personal_options' action. 45 * 46 * @since 2.7.0 47 * 48 * @param object $user User data object 49 */ 50 function use_ssl_preference($user) { 51 ?> 52 <tr> 53 <th scope="row"><?php _e('Use https')?></th> 54 <td><label for="use_ssl"><input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked('1', $user->use_ssl); ?> /> <?php _e('Always use https when visiting the admin'); ?></label></td> 55 </tr> 56 <?php 57 } 58 59 60 // Only allow super admins on multisite to edit every user. 61 if ( is_multisite() && ! is_super_admin() && $user_id != $current_user->ID && ! apply_filters( 'enable_edit_any_user_configuration', true ) ) 62 wp_die( __( 'You do not have permission to edit this user.' ) ); 63 64 // Execute confirmed email change. See send_confirmation_on_profile_email(). 65 if ( is_multisite() && IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) { 66 $new_email = get_option( $current_user->ID . '_new_email' ); 67 if ( $new_email[ 'hash' ] == $_GET[ 'newuseremail' ] ) { 68 $user->ID = $current_user->ID; 69 $user->user_email = esc_html( trim( $new_email[ 'newemail' ] ) ); 70 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) 71 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) ); 72 wp_update_user( get_object_vars( $user ) ); 73 delete_option( $current_user->ID . '_new_email' ); 74 wp_redirect( add_query_arg( array('updated' => 'true'), admin_url( 'profile.php' ) ) ); 75 die(); 76 } 77 } 78 79 switch ($action) { 80 case 'switchposts': 81 82 check_admin_referer(); 83 84 /* TODO: Switch all posts from one user to another user */ 85 86 break; 87 88 case 'update': 89 90 check_admin_referer('update-user_' . $user_id); 91 92 if ( !current_user_can('edit_user', $user_id) ) 93 wp_die(__('You do not have permission to edit this user.')); 94 95 if ( IS_PROFILE_PAGE ) 96 do_action('personal_options_update', $user_id); 97 else 98 do_action('edit_user_profile_update', $user_id); 99 100 if ( !is_multisite() ) { 101 $errors = edit_user($user_id); 102 } else { 103 $user = get_userdata( $user_id ); 104 105 // Update the email address in signups, if present. 106 if ( $user->user_login && isset( $_POST[ 'email' ] ) && is_email( $_POST[ 'email' ] ) && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login ) ) ) 107 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST[ 'email' ], $user_login ) ); 108 109 // WPMU must delete the user from the current blog if WP added him after editing. 110 $delete_role = false; 111 $blog_prefix = $wpdb->get_blog_prefix(); 112 if ( $user_id != $current_user->ID ) { 113 $cap = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$user_id}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" ); 114 if ( null == $cap && $_POST[ 'role' ] == '' ) { 115 $_POST[ 'role' ] = 'contributor'; 116 $delete_role = true; 117 } 118 } 119 if ( !isset( $errors ) || ( isset( $errors ) && is_object( $errors ) && false == $errors->get_error_codes() ) ) 120 $errors = edit_user($user_id); 121 if ( $delete_role ) // stops users being added to current blog when they are edited 122 delete_user_meta( $user_id, $blog_prefix . 'capabilities' ); 123 124 if ( is_multisite() && is_super_admin() && !IS_PROFILE_PAGE ) 125 empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id ); 126 } 127 128 if ( !is_wp_error( $errors ) ) { 129 $redirect = (IS_PROFILE_PAGE ? "profile.php?" : "user-edit.php?user_id=$user_id&"). "updated=true"; 130 $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect); 131 wp_redirect($redirect); 132 exit; 133 } 134 135 default: 136 $profileuser = get_user_to_edit($user_id); 137 138 if ( !current_user_can('edit_user', $user_id) ) 139 wp_die(__('You do not have permission to edit this user.')); 140 141 include ('admin-header.php'); 142 ?> 143 144 <?php if ( !IS_PROFILE_PAGE && is_super_admin( $profileuser->ID ) ) { ?> 145 <div class="updated"><p><strong><?php _e('Important:'); ?></strong> <?php _e('This user has super admin privileges.'); ?></p></div> 146 <?php } ?> 147 <?php if ( isset($_GET['updated']) ) : ?> 148 <div id="message" class="updated"> 149 <p><strong><?php _e('User updated.') ?></strong></p> 150 <?php if ( $wp_http_referer && !IS_PROFILE_PAGE ) : ?> 151 <p><a href="users.php"><?php _e('← Back to Authors and Users'); ?></a></p> 152 <?php endif; ?> 153 </div> 154 <?php endif; ?> 155 <?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?> 156 <div class="error"> 157 <ul> 158 <?php 159 foreach( $errors->get_error_messages() as $message ) 160 echo "<li>$message</li>"; 161 ?> 162 </ul> 163 </div> 164 <?php endif; ?> 165 166 <div class="wrap" id="profile-page"> 167 <?php screen_icon(); ?> 168 <h2><?php echo esc_html( $title ); ?></h2> 169 170 <form id="your-profile" action="<?php echo esc_url( admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post"> 171 <?php wp_nonce_field('update-user_' . $user_id) ?> 172 <?php if ( $wp_http_referer ) : ?> 173 <input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?>" /> 174 <?php endif; ?> 175 <p> 176 <input type="hidden" name="from" value="profile" /> 177 <input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" /> 178 </p> 179 180 <h3><?php _e('Personal Options'); ?></h3> 181 182 <table class="form-table"> 183 <?php if ( rich_edit_exists() && !( IS_PROFILE_PAGE && !$user_can_edit ) ) : // don't bother showing the option if the editor has been removed ?> 184 <tr> 185 <th scope="row"><?php _e('Visual Editor')?></th> 186 <td><label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="false" <?php checked('false', $profileuser->rich_editing); ?> /> <?php _e('Disable the visual editor when writing'); ?></label></td> 187 </tr> 188 <?php endif; ?> 189 <?php if ( count($_wp_admin_css_colors) > 1 && has_action('admin_color_scheme_picker') ) : ?> 190 <tr> 191 <th scope="row"><?php _e('Admin Color Scheme')?></th> 192 <td><?php do_action( 'admin_color_scheme_picker' ); ?></td> 193 </tr> 194 <?php 195 endif; // $_wp_admin_css_colors 196 if ( !( IS_PROFILE_PAGE && !$user_can_edit ) ) : ?> 197 <tr> 198 <th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th> 199 <td><label for="comment_shortcuts"><input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php if ( !empty($profileuser->comment_shortcuts) ) checked('true', $profileuser->comment_shortcuts); ?> /> <?php _e('Enable keyboard shortcuts for comment moderation.'); ?></label> <?php _e('<a href="http://codex.wordpress.org/Keyboard_Shortcuts">More information</a>'); ?></td> 200 </tr> 201 <?php 202 endif; 203 do_action('personal_options', $profileuser); 204 ?> 205 </table> 206 <?php 207 if ( IS_PROFILE_PAGE ) 208 do_action('profile_personal_options', $profileuser); 209 ?> 210 211 <h3><?php _e('Name') ?></h3> 212 213 <table class="form-table"> 214 <tr> 215 <th><label for="user_login"><?php _e('Username'); ?></label></th> 216 <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr($profileuser->user_login); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e('Usernames cannot be changed.'); ?></span></td> 217 </tr> 218 219 <?php if ( !IS_PROFILE_PAGE ): ?> 220 <tr><th><label for="role"><?php _e('Role:') ?></label></th> 221 <td><select name="role" id="role"> 222 <?php 223 // Get the highest/primary role for this user 224 // TODO: create a function that does this: wp_get_user_role() 225 $user_roles = $profileuser->roles; 226 $user_role = array_shift($user_roles); 227 228 // print the full list of roles with the primary one selected. 229 wp_dropdown_roles($user_role); 230 231 // print the 'no role' option. Make it selected if the user has no role yet. 232 if ( $user_role ) 233 echo '<option value="">' . __('— No role for this blog —') . '</option>'; 234 else 235 echo '<option value="" selected="selected">' . __('— No role for this blog —') . '</option>'; 236 ?> 237 </select> 238 <?php if ( is_multisite() && is_super_admin() ) { ?> 239 <p><label><input type="checkbox" id="super_admin" name="super_admin"<?php checked( is_super_admin( $profileuser->ID ) ); ?> /> <?php _e( 'Grant this user super admin privileges for the Network.'); ?></label></p> 240 <?php } ?> 241 </td></tr> 242 <?php endif; //!IS_PROFILE_PAGE ?> 243 244 <tr> 245 <th><label for="first_name"><?php _e('First Name') ?></label></th> 246 <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr($profileuser->first_name) ?>" class="regular-text" /></td> 247 </tr> 248 249 <tr> 250 <th><label for="last_name"><?php _e('Last Name') ?></label></th> 251 <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr($profileuser->last_name) ?>" class="regular-text" /></td> 252 </tr> 253 254 <tr> 255 <th><label for="nickname"><?php _e('Nickname'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> 256 <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr($profileuser->nickname) ?>" class="regular-text" /></td> 257 </tr> 258 259 <tr> 260 <th><label for="display_name"><?php _e('Display name publicly as') ?></label></th> 261 <td> 262 <select name="display_name" id="display_name"> 263 <?php 264 $public_display = array(); 265 $public_display['display_username'] = $profileuser->user_login; 266 $public_display['display_nickname'] = $profileuser->nickname; 267 if ( !empty($profileuser->first_name) ) 268 $public_display['display_firstname'] = $profileuser->first_name; 269 if ( !empty($profileuser->last_name) ) 270 $public_display['display_lastname'] = $profileuser->last_name; 271 if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { 272 $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; 273 $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; 274 } 275 if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere 276 $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display; 277 $public_display = array_map( 'trim', $public_display ); 278 $public_display = array_unique( $public_display ); 279 foreach ( $public_display as $id => $item ) { 280 ?> 281 <option id="<?php echo $id; ?>" value="<?php echo esc_attr($item); ?>"<?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option> 282 <?php 283 } 284 ?> 285 </select> 286 </td> 287 </tr> 288 </table> 289 290 <h3><?php _e('Contact Info') ?></h3> 291 292 <table class="form-table"> 293 <tr> 294 <th><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> 295 <td><input type="text" name="email" id="email" value="<?php echo esc_attr($profileuser->user_email) ?>" class="regular-text" /></td> 296 </tr> 297 298 <tr> 299 <th><label for="url"><?php _e('Website') ?></label></th> 300 <td><input type="text" name="url" id="url" value="<?php echo esc_attr($profileuser->user_url) ?>" class="regular-text code" /></td> 301 </tr> 302 303 <?php 304 foreach (_wp_get_user_contactmethods() as $name => $desc) { 305 ?> 306 <tr> 307 <th><label for="<?php echo $name; ?>"><?php echo apply_filters('user_'.$name.'_label', $desc); ?></label></th> 308 <td><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($profileuser->$name) ?>" class="regular-text" /></td> 309 </tr> 310 <?php 311 } 312 ?> 313 </table> 314 315 <h3><?php IS_PROFILE_PAGE ? _e('About Yourself') : _e('About the user'); ?></h3> 316 317 <table class="form-table"> 318 <tr> 319 <th><label for="description"><?php _e('Biographical Info'); ?></label></th> 320 <td><textarea name="description" id="description" rows="5" cols="30"><?php echo esc_html($profileuser->description); ?></textarea><br /> 321 <span class="description"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></span></td> 322 </tr> 323 324 <?php 325 $show_password_fields = apply_filters('show_password_fields', true, $profileuser); 326 if ( $show_password_fields ) : 327 ?> 328 <tr id="password"> 329 <th><label for="pass1"><?php _e('New Password'); ?></label></th> 330 <td><input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" /> <span class="description"><?php _e("If you would like to change the password type a new one. Otherwise leave this blank."); ?></span><br /> 331 <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" /> <span class="description"><?php _e("Type your new password again."); ?></span><br /> 332 <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div> 333 <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> 334 </td> 335 </tr> 336 <?php endif; ?> 337 </table> 338 339 <?php 340 if ( IS_PROFILE_PAGE ) 341 do_action( 'show_user_profile', $profileuser ); 342 else 343 do_action( 'edit_user_profile', $profileuser ); 344 ?> 345 346 <?php if ( count($profileuser->caps) > count($profileuser->roles) && apply_filters('additional_capabilities_display', true, $profileuser) ) { ?> 347 <br class="clear" /> 348 <table width="99%" style="border: none;" cellspacing="2" cellpadding="3" class="editform"> 349 <tr> 350 <th scope="row"><?php _e('Additional Capabilities') ?></th> 351 <td><?php 352 $output = ''; 353 foreach ( $profileuser->caps as $cap => $value ) { 354 if ( !$wp_roles->is_role($cap) ) { 355 if ( $output != '' ) 356 $output .= ', '; 357 $output .= $value ? $cap : "Denied: {$cap}"; 358 } 359 } 360 echo $output; 361 ?></td> 362 </tr> 363 </table> 364 <?php } ?> 365 366 <p class="submit"> 367 <input type="hidden" name="action" value="update" /> 368 <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($user_id); ?>" /> 369 <input type="submit" class="button-primary" value="<?php IS_PROFILE_PAGE ? esc_attr_e('Update Profile') : esc_attr_e('Update User') ?>" name="submit" /> 370 </p> 371 </form> 372 </div> 373 <?php 374 break; 375 } 376 377 include ('admin-footer.php'); 378 ?>
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 |