PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/user-edit.php

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