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