]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/user-edit.php
Wordpress 2.7.1-scripts
[autoinstalls/wordpress.git] / wp-admin / user-edit.php
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 if ( defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE )
13         $is_profile_page = true;
14 else
15         $is_profile_page = false;
16
17 /**
18  * Display JavaScript for profile page.
19  *
20  * @since 2.5.0
21  */
22 function profile_js ( ) {
23 ?>
24 <script type="text/javascript">
25 (function($){
26
27         function check_pass_strength () {
28
29                 var pass = $('#pass1').val();
30                 var user = $('#user_login').val();
31
32                 $('#pass-strength-result').removeClass('short bad good strong');
33                 if ( ! pass ) {
34                         $('#pass-strength-result').html( pwsL10n.empty );
35                         return;
36                 }
37
38                 var strength = passwordStrength(pass, user);
39
40                 if ( 2 == strength )
41                         $('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
42                 else if ( 3 == strength )
43                         $('#pass-strength-result').addClass('good').html( pwsL10n.good );
44                 else if ( 4 == strength )
45                         $('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
46                 else
47                         // this catches 'Too short' and the off chance anything else comes along
48                         $('#pass-strength-result').addClass('short').html( pwsL10n.short );
49
50         }
51
52         function update_nickname () {
53
54                 var nickname = $('#nickname').val();
55                 var display_nickname = $('#display_nickname').val();
56
57                 if ( nickname == '' ) {
58                         $('#display_nickname').remove();
59                 }
60                 $('#display_nickname').val(nickname).html(nickname);
61
62         }
63
64         $(document).ready( function() {
65                 $('#nickname').blur(update_nickname);
66                 $('#pass1').val('').keyup( check_pass_strength );
67                 $('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
68     });
69 })(jQuery);
70 </script>
71 <?php
72 }
73
74 if ( $is_profile_page ) {
75         add_action('admin_head', 'profile_js');
76         wp_enqueue_script('jquery');
77         wp_enqueue_script('password-strength-meter');
78 }
79
80 $title = $is_profile_page? __('Profile') : __('Edit User');
81 if ( current_user_can('edit_users') && !$is_profile_page )
82         $submenu_file = 'users.php';
83 else
84         $submenu_file = 'profile.php';
85 $parent_file = 'users.php';
86
87 wp_reset_vars(array('action', 'redirect', 'profile', 'user_id', 'wp_http_referer'));
88
89 $wp_http_referer = remove_query_arg(array('update', 'delete_count'), stripslashes($wp_http_referer));
90
91 $user_id = (int) $user_id;
92
93 if ( !$user_id ) {
94         if ( $is_profile_page ) {
95                 $current_user = wp_get_current_user();
96                 $user_id = $current_user->ID;
97         } else {
98                 wp_die(__('Invalid user ID.'));
99         }
100 } elseif ( !get_userdata($user_id) ) {
101         wp_die( __('Invalid user ID.') );
102 }
103
104 /**
105  * Optional SSL preference that can be turned on by hooking to the 'personal_options' action.
106  *
107  * @since 2.7.0
108  *
109  * @param object $user User data object
110  */
111 function use_ssl_preference($user) {
112 ?>
113         <tr>
114                 <th scope="row"><?php _e('Use https')?></th>
115                 <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>
116         </tr>
117 <?php
118 }
119
120 switch ($action) {
121 case 'switchposts':
122
123 check_admin_referer();
124
125 /* TODO: Switch all posts from one user to another user */
126
127 break;
128
129 case 'update':
130
131 check_admin_referer('update-user_' . $user_id);
132
133 if ( !current_user_can('edit_user', $user_id) )
134         wp_die(__('You do not have permission to edit this user.'));
135
136 if ($is_profile_page)
137         do_action('personal_options_update');
138 else
139         do_action('edit_user_profile_update');
140
141 $errors = edit_user($user_id);
142
143 if ( !is_wp_error( $errors ) ) {
144         $redirect = ($is_profile_page? "profile.php?" : "user-edit.php?user_id=$user_id&"). "updated=true";
145         $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect);
146         wp_redirect($redirect);
147         exit;
148 }
149
150 default:
151 $profileuser = get_user_to_edit($user_id);
152
153 if ( !current_user_can('edit_user', $user_id) )
154         wp_die(__('You do not have permission to edit this user.'));
155
156 include ('admin-header.php');
157 ?>
158
159 <?php if ( isset($_GET['updated']) ) : ?>
160 <div id="message" class="updated fade">
161         <p><strong><?php _e('User updated.') ?></strong></p>
162         <?php if ( $wp_http_referer && !$is_profile_page ) : ?>
163         <p><a href="users.php"><?php _e('&larr; Back to Authors and Users'); ?></a></p>
164         <?php endif; ?>
165 </div>
166 <?php endif; ?>
167 <?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?>
168 <div class="error">
169         <ul>
170         <?php
171         foreach( $errors->get_error_messages() as $message )
172                 echo "<li>$message</li>";
173         ?>
174         </ul>
175 </div>
176 <?php endif; ?>
177
178 <div class="wrap" id="profile-page">
179 <?php screen_icon(); ?>
180 <h2><?php echo wp_specialchars( $title ); ?></h2>
181
182 <form id="your-profile" action="" method="post">
183 <?php wp_nonce_field('update-user_' . $user_id) ?>
184 <?php if ( $wp_http_referer ) : ?>
185         <input type="hidden" name="wp_http_referer" value="<?php echo clean_url($wp_http_referer); ?>" />
186 <?php endif; ?>
187 <p>
188 <input type="hidden" name="from" value="profile" />
189 <input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" />
190 </p>
191
192 <h3><?php _e('Personal Options'); ?></h3>
193
194 <table class="form-table">
195 <?php if ( rich_edit_exists() ) : // don't bother showing the option if the editor has been removed ?>
196         <tr>
197                 <th scope="row"><?php _e('Visual Editor')?></th>
198                 <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>
199         </tr>
200 <?php endif; ?>
201 <?php if (count($_wp_admin_css_colors) > 1 ) : ?>
202 <tr>
203 <th scope="row"><?php _e('Admin Color Scheme')?></th>
204 <td><fieldset><legend class="hidden"><?php _e('Admin Color Scheme')?></legend>
205 <?php
206 $current_color = get_user_option('admin_color', $user_id);
207 if ( empty($current_color) )
208         $current_color = 'fresh';
209 foreach ( $_wp_admin_css_colors as $color => $color_info ): ?>
210 <div class="color-option"><input name="admin_color" id="admin_color_<?php echo $color; ?>" type="radio" value="<?php echo $color ?>" class="tog" <?php checked($color, $current_color); ?> />
211         <table class="color-palette">
212         <tr>
213         <?php foreach ( $color_info->colors as $html_color ): ?>
214         <td style="background-color: <?php echo $html_color ?>" title="<?php echo $color ?>">&nbsp;</td>
215         <?php endforeach; ?>
216         </tr>
217         </table>
218
219         <label for="admin_color_<?php echo $color; ?>"><?php echo $color_info->name ?></label>
220 </div>
221         <?php endforeach; ?>
222 </fieldset></td>
223 </tr>
224 <tr>
225 <th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th>
226 <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. <a href="http://codex.wordpress.org/Keyboard_Shortcuts">More information</a>' ); ?></label></td>
227 </tr>
228 <?php
229 endif;
230 do_action('personal_options', $profileuser);
231 ?>
232 </table>
233 <?php
234         if ( $is_profile_page )
235                 do_action('profile_personal_options', $profileuser);
236 ?>
237
238 <h3><?php _e('Name') ?></h3>
239
240 <table class="form-table">
241         <tr>
242                 <th><label for="user_login"><?php _e('Username'); ?></label></th>
243                 <td><input type="text" name="user_login" id="user_login" value="<?php echo $profileuser->user_login; ?>" disabled="disabled" class="regular-text" /> <?php _e('Your username cannot be changed.'); ?></td>
244         </tr>
245
246 <?php if ( !$is_profile_page ): ?>
247 <tr><th><label for="role"><?php _e('Role:') ?></label></th>
248 <?php
249 // print_r($profileuser);
250 echo '<td><select name="role" id="role">';
251 $role_list = '';
252 $user_has_role = false;
253 foreach($wp_roles->role_names as $role => $name) {
254         $name = translate_with_context($name);
255         if ( $profileuser->has_cap($role) ) {
256                 $selected = ' selected="selected"';
257                 $user_has_role = true;
258         } else {
259                 $selected = '';
260         }
261         $role_list .= "<option value=\"{$role}\"{$selected}>{$name}</option>";
262 }
263 if ( $user_has_role )
264         $role_list .= '<option value="">' . __('&mdash; No role for this blog &mdash;') . '</option>';
265 else
266         $role_list .= '<option value="" selected="selected">' . __('&mdash; No role for this blog &mdash;') . '</option>';
267 echo $role_list . '</select></td></tr>';
268 ?>
269 <?php endif; ?>
270
271 <tr>
272         <th><label for="first_name"><?php _e('First name') ?></label></th>
273         <td><input type="text" name="first_name" id="first_name" value="<?php echo $profileuser->first_name ?>" class="regular-text" /></td>
274 </tr>
275
276 <tr>
277         <th><label for="last_name"><?php _e('Last name') ?></label></th>
278         <td><input type="text" name="last_name" id="last_name" value="<?php echo $profileuser->last_name ?>" class="regular-text" /></td>
279 </tr>
280
281 <tr>
282         <th><label for="nickname"><?php _e('Nickname') ?></label></th>
283         <td><input type="text" name="nickname" id="nickname" value="<?php echo $profileuser->nickname ?>" class="regular-text" /></td>
284 </tr>
285
286 <tr>
287         <th><label for="display_name"><?php _e('Display name publicly&nbsp;as') ?></label></th>
288         <td>
289                 <select name="display_name" id="display_name">
290                 <?php
291                         $public_display = array();
292                         $public_display['display_displayname'] = $profileuser->display_name;
293                         $public_display['display_nickname'] = $profileuser->nickname;
294                         $public_display['display_username'] = $profileuser->user_login;
295                         $public_display['display_firstname'] = $profileuser->first_name;
296                         $public_display['display_firstlast'] = $profileuser->first_name.' '.$profileuser->last_name;
297                         $public_display['display_lastfirst'] = $profileuser->last_name.' '.$profileuser->first_name;
298                         $public_display = array_unique(array_filter(array_map('trim', $public_display)));
299                         foreach($public_display as $id => $item) {
300                 ?>
301                         <option id="<?php echo $id; ?>" value="<?php echo $item; ?>"><?php echo $item; ?></option>
302                 <?php
303                         }
304                 ?>
305                 </select>
306         </td>
307 </tr>
308 </table>
309
310 <h3><?php _e('Contact Info') ?></h3>
311
312 <table class="form-table">
313 <tr>
314         <th><label for="email"><?php _e('E-mail') ?></label></th>
315         <td><input type="text" name="email" id="email" value="<?php echo $profileuser->user_email ?>" class="regular-text" /> <?php _e('Required.');?></td>
316 </tr>
317
318 <tr>
319         <th><label for="url"><?php _e('Website') ?></label></th>
320         <td><input type="text" name="url" id="url" value="<?php echo $profileuser->user_url ?>" class="regular-text" /></td>
321 </tr>
322
323 <tr>
324         <th><label for="aim"><?php _e('AIM') ?></label></th>
325         <td><input type="text" name="aim" id="aim" value="<?php echo $profileuser->aim ?>" class="regular-text" /></td>
326 </tr>
327
328 <tr>
329         <th><label for="yim"><?php _e('Yahoo IM') ?></label></th>
330         <td><input type="text" name="yim" id="yim" value="<?php echo $profileuser->yim ?>" class="regular-text" /></td>
331 </tr>
332
333 <tr>
334         <th><label for="jabber"><?php _e('Jabber / Google Talk') ?></label></th>
335         <td><input type="text" name="jabber" id="jabber" value="<?php echo $profileuser->jabber ?>" class="regular-text" /></td>
336 </tr>
337 </table>
338
339 <h3><?php $is_profile_page? _e('About Yourself') : _e('About the user'); ?></h3>
340
341 <table class="form-table">
342 <tr>
343         <th><label for="description"><?php _e('Biographical Info'); ?></label></th>
344         <td><textarea name="description" id="description" rows="5" cols="30"><?php echo $profileuser->description ?></textarea><br /><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></td>
345 </tr>
346
347 <?php
348 $show_password_fields = apply_filters('show_password_fields', true);
349 if ( $show_password_fields ) :
350 ?>
351 <tr>
352         <th><label for="pass1"><?php _e('New Password'); ?></label></th>
353         <td><input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" /> <?php _e("If you would like to change the password type a new one. Otherwise leave this blank."); ?><br />
354                 <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" /> <?php _e("Type your new password again."); ?><br />
355         <?php if ( $is_profile_page ): ?>
356                 <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
357                 <p><?php _e('Hint: Your password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
358         <?php endif; ?>
359         </td>
360 </tr>
361 <?php endif; ?>
362 </table>
363
364 <?php
365         if ( $is_profile_page ) {
366                 do_action('show_user_profile');
367         } else {
368                 do_action('edit_user_profile');
369         }
370 ?>
371
372 <?php if (count($profileuser->caps) > count($profileuser->roles)): ?>
373 <br class="clear" />
374         <table width="99%" style="border: none;" cellspacing="2" cellpadding="3" class="editform">
375                 <tr>
376                         <th scope="row"><?php _e('Additional Capabilities') ?></th>
377                         <td><?php
378                         $output = '';
379                         foreach($profileuser->caps as $cap => $value) {
380                                 if(!$wp_roles->is_role($cap)) {
381                                         if($output != '') $output .= ', ';
382                                         $output .= $value ? $cap : "Denied: {$cap}";
383                                 }
384                         }
385                         echo $output;
386                         ?></td>
387                 </tr>
388         </table>
389 <?php endif; ?>
390
391 <p class="submit">
392         <input type="hidden" name="action" value="update" />
393         <input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
394         <input type="submit" class="button-primary" value="<?php $is_profile_page? _e('Update Profile') : _e('Update User') ?>" name="submit" />
395 </p>
396 </form>
397 </div>
398 <?php
399 break;
400 }
401
402 include('admin-footer.php');
403 ?>