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