[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> user-edit.php (source)

   1  <?php
   2  /**
   3   * Edit user administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once  __DIR__ . '/admin.php';
  11  
  12  /** WordPress Translation Installation API */
  13  require_once  ABSPATH . 'wp-admin/includes/translation-install.php';
  14  
  15  $action          = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
  16  $user_id         = ! empty( $_REQUEST['user_id'] ) ? absint( $_REQUEST['user_id'] ) : 0;
  17  $wp_http_referer = ! empty( $_REQUEST['wp_http_referer'] ) ? sanitize_url( $_REQUEST['wp_http_referer'] ) : '';
  18  
  19  $current_user = wp_get_current_user();
  20  
  21  if ( ! defined( 'IS_PROFILE_PAGE' ) ) {
  22      define( 'IS_PROFILE_PAGE', ( $user_id === $current_user->ID ) );
  23  }
  24  
  25  if ( ! $user_id && IS_PROFILE_PAGE ) {
  26      $user_id = $current_user->ID;
  27  } elseif ( ! $user_id && ! IS_PROFILE_PAGE ) {
  28      wp_die( __( 'Invalid user ID.' ) );
  29  } elseif ( ! get_userdata( $user_id ) ) {
  30      wp_die( __( 'Invalid user ID.' ) );
  31  }
  32  
  33  wp_enqueue_script( 'user-profile' );
  34  
  35  if ( wp_is_application_passwords_available_for_user( $user_id ) ) {
  36      wp_enqueue_script( 'application-passwords' );
  37  }
  38  
  39  if ( IS_PROFILE_PAGE ) {
  40      // Used in the HTML title tag.
  41      $title = __( 'Profile' );
  42  } else {
  43      // Used in the HTML title tag.
  44      /* translators: %s: User's display name. */
  45      $title = __( 'Edit User %s' );
  46  }
  47  
  48  if ( current_user_can( 'edit_users' ) && ! IS_PROFILE_PAGE ) {
  49      $submenu_file = 'users.php';
  50  } else {
  51      $submenu_file = 'profile.php';
  52  }
  53  
  54  if ( current_user_can( 'edit_users' ) && ! is_user_admin() ) {
  55      $parent_file = 'users.php';
  56  } else {
  57      $parent_file = 'profile.php';
  58  }
  59  
  60  $profile_help = '<p>' . __( 'Your profile contains information about you (your &#8220;account&#8221;) as well as some personal options related to using WordPress.' ) . '</p>' .
  61      '<p>' . __( 'You can change your password, turn on keyboard shortcuts, change the color scheme of your WordPress administration screens, and turn off the WYSIWYG (Visual) editor, among other things. You can hide the Toolbar (formerly called the Admin Bar) from the front end of your site, however it cannot be disabled on the admin screens.' ) . '</p>' .
  62      '<p>' . __( 'You can select the language you wish to use while using the WordPress administration screen without affecting the language site visitors see.' ) . '</p>' .
  63      '<p>' . __( 'Your username cannot be changed, but you can use other fields to enter your real name or a nickname, and change which name to display on your posts.' ) . '</p>' .
  64      '<p>' . __( 'You can log out of other devices, such as your phone or a public computer, by clicking the Log Out Everywhere Else button.' ) . '</p>' .
  65      '<p>' . __( 'Required fields are indicated; the rest are optional. Profile information will only be displayed if your theme is set up to do so.' ) . '</p>' .
  66      '<p>' . __( 'Remember to click the Update Profile button when you are finished.' ) . '</p>';
  67  
  68  get_current_screen()->add_help_tab(
  69      array(
  70          'id'      => 'overview',
  71          'title'   => __( 'Overview' ),
  72          'content' => $profile_help,
  73      )
  74  );
  75  
  76  get_current_screen()->set_help_sidebar(
  77      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  78      '<p>' . __( '<a href="https://wordpress.org/documentation/article/users-your-profile-screen/">Documentation on User Profiles</a>' ) . '</p>' .
  79      '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
  80  );
  81  
  82  $wp_http_referer = remove_query_arg( array( 'update', 'delete_count', 'user_id' ), $wp_http_referer );
  83  
  84  $user_can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' );
  85  
  86  /**
  87   * Filters whether to allow administrators on Multisite to edit every user.
  88   *
  89   * Enabling the user editing form via this filter also hinges on the user holding
  90   * the 'manage_network_users' cap, and the logged-in user not matching the user
  91   * profile open for editing.
  92   *
  93   * The filter was introduced to replace the EDIT_ANY_USER constant.
  94   *
  95   * @since 3.0.0
  96   *
  97   * @param bool $allow Whether to allow editing of any user. Default true.
  98   */
  99  if ( is_multisite()
 100      && ! current_user_can( 'manage_network_users' )
 101      && $user_id !== $current_user->ID
 102      && ! apply_filters( 'enable_edit_any_user_configuration', true )
 103  ) {
 104      wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
 105  }
 106  
 107  // Execute confirmed email change. See send_confirmation_on_profile_email().
 108  if ( IS_PROFILE_PAGE && isset( $_GET['newuseremail'] ) && $current_user->ID ) {
 109      $new_email = get_user_meta( $current_user->ID, '_new_email', true );
 110      if ( $new_email && hash_equals( $new_email['hash'], $_GET['newuseremail'] ) ) {
 111          $user             = new stdClass();
 112          $user->ID         = $current_user->ID;
 113          $user->user_email = esc_html( trim( $new_email['newemail'] ) );
 114          if ( is_multisite() && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) {
 115              $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) );
 116          }
 117          wp_update_user( $user );
 118          delete_user_meta( $current_user->ID, '_new_email' );
 119          wp_redirect( add_query_arg( array( 'updated' => 'true' ), self_admin_url( 'profile.php' ) ) );
 120          die();
 121      } else {
 122          wp_redirect( add_query_arg( array( 'error' => 'new-email' ), self_admin_url( 'profile.php' ) ) );
 123      }
 124  } elseif ( IS_PROFILE_PAGE && ! empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' === $_GET['dismiss'] ) {
 125      check_admin_referer( 'dismiss-' . $current_user->ID . '_new_email' );
 126      delete_user_meta( $current_user->ID, '_new_email' );
 127      wp_redirect( add_query_arg( array( 'updated' => 'true' ), self_admin_url( 'profile.php' ) ) );
 128      die();
 129  }
 130  
 131  switch ( $action ) {
 132      case 'update':
 133          check_admin_referer( 'update-user_' . $user_id );
 134  
 135          if ( ! current_user_can( 'edit_user', $user_id ) ) {
 136              wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
 137          }
 138  
 139          if ( IS_PROFILE_PAGE ) {
 140              /**
 141               * Fires before the page loads on the 'Profile' editing screen.
 142               *
 143               * The action only fires if the current user is editing their own profile.
 144               *
 145               * @since 2.0.0
 146               *
 147               * @param int $user_id The user ID.
 148               */
 149              do_action( 'personal_options_update', $user_id );
 150          } else {
 151              /**
 152               * Fires before the page loads on the 'Edit User' screen.
 153               *
 154               * @since 2.7.0
 155               *
 156               * @param int $user_id The user ID.
 157               */
 158              do_action( 'edit_user_profile_update', $user_id );
 159          }
 160  
 161          // Update the email address in signups, if present.
 162          if ( is_multisite() ) {
 163              $user = get_userdata( $user_id );
 164  
 165              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 ) ) ) {
 166                  $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email'], $user_login ) );
 167              }
 168          }
 169  
 170          // Update the user.
 171          $errors = edit_user( $user_id );
 172  
 173          // Grant or revoke super admin status if requested.
 174          if ( is_multisite() && is_network_admin()
 175              && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' )
 176              && ! isset( $super_admins ) && empty( $_POST['super_admin'] ) === is_super_admin( $user_id )
 177          ) {
 178              empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
 179          }
 180  
 181          if ( ! is_wp_error( $errors ) ) {
 182              $redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) );
 183              if ( $wp_http_referer ) {
 184                  $redirect = add_query_arg( 'wp_http_referer', urlencode( $wp_http_referer ), $redirect );
 185              }
 186              wp_redirect( $redirect );
 187              exit;
 188          }
 189  
 190          // Intentional fall-through to display $errors.
 191      default:
 192          $profile_user = get_user_to_edit( $user_id );
 193  
 194          if ( ! current_user_can( 'edit_user', $user_id ) ) {
 195              wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
 196          }
 197  
 198          $title    = sprintf( $title, $profile_user->display_name );
 199          $sessions = WP_Session_Tokens::get_instance( $profile_user->ID );
 200  
 201          require_once  ABSPATH . 'wp-admin/admin-header.php';
 202          ?>
 203  
 204          <?php
 205          if ( ! IS_PROFILE_PAGE && is_super_admin( $profile_user->ID ) && current_user_can( 'manage_network_options' ) ) :
 206              $message = '<strong>' . __( 'Important:' ) . '</strong> ' . __( 'This user has super admin privileges.' );
 207              wp_admin_notice(
 208                  $message,
 209                  array(
 210                      'type' => 'info',
 211                  )
 212              );
 213          endif;
 214  
 215          if ( isset( $_GET['updated'] ) ) :
 216              if ( IS_PROFILE_PAGE ) :
 217                  $message = '<p><strong>' . __( 'Profile updated.' ) . '</strong></p>';
 218              else :
 219                  $message = '<p><strong>' . __( 'User updated.' ) . '</strong></p>';
 220              endif;
 221              if ( $wp_http_referer && ! str_contains( $wp_http_referer, 'user-new.php' ) && ! IS_PROFILE_PAGE ) :
 222                  $message .= sprintf(
 223                      '<p><a href="%1$s">%2$s</a></p>',
 224                      esc_url( wp_validate_redirect( sanitize_url( $wp_http_referer ), self_admin_url( 'users.php' ) ) ),
 225                      __( '&larr; Go to Users' )
 226                  );
 227              endif;
 228              wp_admin_notice(
 229                  $message,
 230                  array(
 231                      'id'                 => 'message',
 232                      'dismissible'        => true,
 233                      'additional_classes' => array( 'updated' ),
 234                      'paragraph_wrap'     => false,
 235                  )
 236              );
 237          endif;
 238  
 239          if ( isset( $_GET['error'] ) ) :
 240              $message = '';
 241              if ( 'new-email' === $_GET['error'] ) :
 242                  $message = __( 'Error while saving the new email address. Please try again.' );
 243              endif;
 244              wp_admin_notice(
 245                  $message,
 246                  array(
 247                      'type' => 'error',
 248                  )
 249              );
 250          endif;
 251  
 252          if ( isset( $errors ) && is_wp_error( $errors ) ) {
 253              wp_admin_notice(
 254                  implode( "</p>\n<p>", $errors->get_error_messages() ),
 255                  array(
 256                      'additional_classes' => array( 'error' ),
 257                  )
 258              );
 259          }
 260          ?>
 261  
 262          <div class="wrap" id="profile-page">
 263              <h1 class="wp-heading-inline">
 264                      <?php echo esc_html( $title ); ?>
 265              </h1>
 266  
 267              <?php if ( ! IS_PROFILE_PAGE ) : ?>
 268                  <?php if ( current_user_can( 'create_users' ) ) : ?>
 269                      <a href="user-new.php" class="page-title-action"><?php echo esc_html__( 'Add User' ); ?></a>
 270                  <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
 271                      <a href="user-new.php" class="page-title-action"><?php echo esc_html__( 'Add Existing User' ); ?></a>
 272                  <?php endif; ?>
 273              <?php endif; ?>
 274  
 275              <hr class="wp-header-end">
 276  
 277              <form id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post" novalidate="novalidate"
 278                  <?php
 279                  /**
 280                   * Fires inside the your-profile form tag on the user editing screen.
 281                   *
 282                   * @since 3.0.0
 283                   */
 284                  do_action( 'user_edit_form_tag' );
 285                  ?>
 286                  >
 287                  <?php wp_nonce_field( 'update-user_' . $user_id ); ?>
 288                  <?php if ( $wp_http_referer ) : ?>
 289                      <input type="hidden" name="wp_http_referer" value="<?php echo esc_url( $wp_http_referer ); ?>" />
 290                  <?php endif; ?>
 291                  <p>
 292                      <input type="hidden" name="from" value="profile" />
 293                      <input type="hidden" name="checkuser_id" value="<?php echo get_current_user_id(); ?>" />
 294                  </p>
 295  
 296                  <h2><?php _e( 'Personal Options' ); ?></h2>
 297  
 298                  <table class="form-table" role="presentation">
 299                      <?php if ( ! ( IS_PROFILE_PAGE && ! $user_can_edit ) && 'false' === $profile_user->rich_editing ) : ?>
 300                          <tr class="user-rich-editing-wrap">
 301                              <th scope="row"><?php _e( 'Visual Editor' ); ?></th>
 302                              <td>
 303                                  <label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="false" <?php checked( 'false', $profile_user->rich_editing ); ?> />
 304                                      <?php _e( 'Disable the visual editor when writing' ); ?>
 305                                  </label>
 306                              </td>
 307                          </tr>
 308                      <?php endif; ?>
 309  
 310                      <?php
 311                      $show_syntax_highlighting_preference = (
 312                      // For Custom HTML widget and Additional CSS in Customizer.
 313                      user_can( $profile_user, 'edit_theme_options' )
 314                      ||
 315                      // Edit plugins.
 316                      user_can( $profile_user, 'edit_plugins' )
 317                      ||
 318                      // Edit themes.
 319                      user_can( $profile_user, 'edit_themes' )
 320                      );
 321                      ?>
 322  
 323                      <?php if ( $show_syntax_highlighting_preference ) : ?>
 324                      <tr class="user-syntax-highlighting-wrap">
 325                          <th scope="row"><?php _e( 'Syntax Highlighting' ); ?></th>
 326                          <td>
 327                              <label for="syntax_highlighting"><input name="syntax_highlighting" type="checkbox" id="syntax_highlighting" value="false" <?php checked( 'false', $profile_user->syntax_highlighting ); ?> />
 328                                  <?php _e( 'Disable syntax highlighting when editing code' ); ?>
 329                              </label>
 330                          </td>
 331                      </tr>
 332                      <?php endif; ?>
 333  
 334                      <?php if ( count( $_wp_admin_css_colors ) > 1 && has_action( 'admin_color_scheme_picker' ) ) : ?>
 335                      <tr class="user-admin-color-wrap">
 336                          <th scope="row"><?php _e( 'Admin Color Scheme' ); ?></th>
 337                          <td>
 338                              <?php
 339                              /**
 340                               * Fires in the 'Admin Color Scheme' section of the user editing screen.
 341                               *
 342                               * The section is only enabled if a callback is hooked to the action,
 343                               * and if there is more than one defined color scheme for the admin.
 344                               *
 345                               * @since 3.0.0
 346                               * @since 3.8.1 Added `$user_id` parameter.
 347                               *
 348                               * @param int $user_id The user ID.
 349                               */
 350                              do_action( 'admin_color_scheme_picker', $user_id );
 351                              ?>
 352                          </td>
 353                      </tr>
 354                      <?php endif; // End if count ( $_wp_admin_css_colors ) > 1 ?>
 355  
 356                      <?php if ( ! ( IS_PROFILE_PAGE && ! $user_can_edit ) ) : ?>
 357                      <tr class="user-comment-shortcuts-wrap">
 358                          <th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th>
 359                          <td>
 360                              <label for="comment_shortcuts">
 361                                  <input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php checked( 'true', $profile_user->comment_shortcuts ); ?> />
 362                                  <?php _e( 'Enable keyboard shortcuts for comment moderation.' ); ?>
 363                              </label>
 364                              <?php _e( '<a href="https://wordpress.org/documentation/article/keyboard-shortcuts-classic-editor/#keyboard-shortcuts-for-comments">Documentation on Keyboard Shortcuts</a>' ); ?>
 365                          </td>
 366                      </tr>
 367                      <?php endif; ?>
 368  
 369                      <tr class="show-admin-bar user-admin-bar-front-wrap">
 370                          <th scope="row"><?php _e( 'Toolbar' ); ?></th>
 371                          <td>
 372                              <label for="admin_bar_front">
 373                                  <input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="1"<?php checked( _get_admin_bar_pref( 'front', $profile_user->ID ) ); ?> />
 374                                  <?php _e( 'Show Toolbar when viewing site' ); ?>
 375                              </label><br />
 376                          </td>
 377                      </tr>
 378  
 379                      <?php
 380                      $languages                = get_available_languages();
 381                      $can_install_translations = current_user_can( 'install_languages' ) && wp_can_install_language_pack();
 382                      ?>
 383                      <?php if ( $languages || $can_install_translations ) : ?>
 384                      <tr class="user-language-wrap">
 385                          <th scope="row">
 386                              <?php /* translators: The user language selection field label. */ ?>
 387                              <label for="locale"><?php _e( 'Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span></label>
 388                          </th>
 389                          <td>
 390                              <?php
 391                                  $user_locale = $profile_user->locale;
 392  
 393                              if ( 'en_US' === $user_locale ) {
 394                                  $user_locale = '';
 395                              } elseif ( '' === $user_locale || ! in_array( $user_locale, $languages, true ) ) {
 396                                  $user_locale = 'site-default';
 397                              }
 398  
 399                              wp_dropdown_languages(
 400                                  array(
 401                                      'name'      => 'locale',
 402                                      'id'        => 'locale',
 403                                      'selected'  => $user_locale,
 404                                      'languages' => $languages,
 405                                      'show_available_translations' => $can_install_translations,
 406                                      'show_option_site_default' => true,
 407                                  )
 408                              );
 409                              ?>
 410                          </td>
 411                      </tr>
 412                      <?php endif; ?>
 413  
 414                      <?php
 415                      /**
 416                       * Fires at the end of the 'Personal Options' settings table on the user editing screen.
 417                       *
 418                       * @since 2.7.0
 419                       *
 420                       * @param WP_User $profile_user The current WP_User object.
 421                       */
 422                      do_action( 'personal_options', $profile_user );
 423                      ?>
 424  
 425                  </table>
 426                  <?php
 427                  if ( IS_PROFILE_PAGE ) {
 428                      /**
 429                       * Fires after the 'Personal Options' settings table on the 'Profile' editing screen.
 430                       *
 431                       * The action only fires if the current user is editing their own profile.
 432                       *
 433                       * @since 2.0.0
 434                       *
 435                       * @param WP_User $profile_user The current WP_User object.
 436                       */
 437                      do_action( 'profile_personal_options', $profile_user );
 438                  }
 439                  ?>
 440  
 441                  <h2><?php _e( 'Name' ); ?></h2>
 442  
 443                  <table class="form-table" role="presentation">
 444                      <tr class="user-user-login-wrap">
 445                          <th><label for="user_login"><?php _e( 'Username' ); ?></label></th>
 446                          <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr( $profile_user->user_login ); ?>" readonly="readonly" class="regular-text" /> <span class="description"><?php _e( 'Usernames cannot be changed.' ); ?></span></td>
 447                      </tr>
 448  
 449                      <?php if ( ! IS_PROFILE_PAGE && ! is_network_admin() && current_user_can( 'promote_user', $profile_user->ID ) ) : ?>
 450                          <tr class="user-role-wrap">
 451                              <th><label for="role"><?php _e( 'Role' ); ?></label></th>
 452                              <td>
 453                                  <select name="role" id="role">
 454                                      <?php
 455                                      // Compare user role against currently editable roles.
 456                                      $user_roles = array_intersect( array_values( $profile_user->roles ), array_keys( get_editable_roles() ) );
 457                                      $user_role  = reset( $user_roles );
 458  
 459                                      // Print the full list of roles with the primary one selected.
 460                                      wp_dropdown_roles( $user_role );
 461  
 462                                      // Print the 'no role' option. Make it selected if the user has no role yet.
 463                                      if ( $user_role ) {
 464                                          echo '<option value="">' . __( '&mdash; No role for this site &mdash;' ) . '</option>';
 465                                      } else {
 466                                          echo '<option value="" selected="selected">' . __( '&mdash; No role for this site &mdash;' ) . '</option>';
 467                                      }
 468                                      ?>
 469                              </select>
 470                              </td>
 471                          </tr>
 472                      <?php endif; // End if ! IS_PROFILE_PAGE. ?>
 473  
 474                      <?php if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && ! isset( $super_admins ) ) : ?>
 475                          <tr class="user-super-admin-wrap">
 476                              <th><?php _e( 'Super Admin' ); ?></th>
 477                              <td>
 478                                  <?php if ( 0 !== strcasecmp( $profile_user->user_email, get_site_option( 'admin_email' ) ) || ! is_super_admin( $profile_user->ID ) ) : ?>
 479                                      <p><label><input type="checkbox" id="super_admin" name="super_admin"<?php checked( is_super_admin( $profile_user->ID ) ); ?> /> <?php _e( 'Grant this user super admin privileges for the Network.' ); ?></label></p>
 480                                  <?php else : ?>
 481                                      <p><?php _e( 'Super admin privileges cannot be removed because this user has the network admin email.' ); ?></p>
 482                                  <?php endif; ?>
 483                              </td>
 484                          </tr>
 485                      <?php endif; ?>
 486  
 487                      <tr class="user-first-name-wrap">
 488                          <th><label for="first_name"><?php _e( 'First Name' ); ?></label></th>
 489                          <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profile_user->first_name ); ?>" class="regular-text" /></td>
 490                      </tr>
 491  
 492                      <tr class="user-last-name-wrap">
 493                          <th><label for="last_name"><?php _e( 'Last Name' ); ?></label></th>
 494                          <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profile_user->last_name ); ?>" class="regular-text" /></td>
 495                      </tr>
 496  
 497                      <tr class="user-nickname-wrap">
 498                          <th><label for="nickname"><?php _e( 'Nickname' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
 499                          <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( $profile_user->nickname ); ?>" class="regular-text" /></td>
 500                      </tr>
 501  
 502                      <tr class="user-display-name-wrap">
 503                          <th>
 504                              <label for="display_name"><?php _e( 'Display name publicly as' ); ?></label>
 505                          </th>
 506                          <td>
 507                              <select name="display_name" id="display_name">
 508                                  <?php
 509                                      $public_display                     = array();
 510                                      $public_display['display_nickname'] = $profile_user->nickname;
 511                                      $public_display['display_username'] = $profile_user->user_login;
 512  
 513                                  if ( ! empty( $profile_user->first_name ) ) {
 514                                      $public_display['display_firstname'] = $profile_user->first_name;
 515                                  }
 516  
 517                                  if ( ! empty( $profile_user->last_name ) ) {
 518                                      $public_display['display_lastname'] = $profile_user->last_name;
 519                                  }
 520  
 521                                  if ( ! empty( $profile_user->first_name ) && ! empty( $profile_user->last_name ) ) {
 522                                      $public_display['display_firstlast'] = $profile_user->first_name . ' ' . $profile_user->last_name;
 523                                      $public_display['display_lastfirst'] = $profile_user->last_name . ' ' . $profile_user->first_name;
 524                                  }
 525  
 526                                  if ( ! in_array( $profile_user->display_name, $public_display, true ) ) { // Only add this if it isn't duplicated elsewhere.
 527                                      $public_display = array( 'display_displayname' => $profile_user->display_name ) + $public_display;
 528                                  }
 529  
 530                                  $public_display = array_map( 'trim', $public_display );
 531                                  $public_display = array_unique( $public_display );
 532  
 533                                  ?>
 534                                  <?php foreach ( $public_display as $id => $item ) : ?>
 535                                      <option <?php selected( $profile_user->display_name, $item ); ?>><?php echo $item; ?></option>
 536                                  <?php endforeach; ?>
 537                              </select>
 538                          </td>
 539                      </tr>
 540                  </table>
 541  
 542                  <h2><?php _e( 'Contact Info' ); ?></h2>
 543  
 544                  <table class="form-table" role="presentation">
 545                      <tr class="user-email-wrap">
 546                          <th><label for="email"><?php _e( 'Email' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
 547                          <td>
 548                              <?php if ( $profile_user->ID === $current_user->ID ) : ?>
 549                                  <input type="email" name="email" id="email" aria-describedby="email-description" value="<?php echo esc_attr( $profile_user->user_email ); ?>" class="regular-text ltr" />
 550                                  <p class="description" id="email-description">
 551                                      <?php _e( 'If you change this, an email will be sent at your new address to confirm it. <strong>The new address will not become active until confirmed.</strong>' ); ?>
 552                                  </p>
 553                              <?php else : ?>
 554                                  <input type="email" name="email" id="email" value="<?php echo esc_attr( $profile_user->user_email ); ?>" class="regular-text ltr" />
 555                              <?php endif; ?>
 556  
 557                              <?php
 558                              $new_email = get_user_meta( $current_user->ID, '_new_email', true );
 559                              if ( $new_email && $new_email['newemail'] !== $current_user->user_email && $profile_user->ID === $current_user->ID ) :
 560  
 561                                  $pending_change_message = sprintf(
 562                                      /* translators: %s: New email. */
 563                                      __( 'There is a pending change of your email to %s.' ),
 564                                      '<code>' . esc_html( $new_email['newemail'] ) . '</code>'
 565                                  );
 566                                  $pending_change_message .= sprintf(
 567                                      ' <a href="%1$s">%2$s</a>',
 568                                      esc_url( wp_nonce_url( self_admin_url( 'profile.php?dismiss=' . $current_user->ID . '_new_email' ), 'dismiss-' . $current_user->ID . '_new_email' ) ),
 569                                      __( 'Cancel' )
 570                                  );
 571                                  wp_admin_notice(
 572                                      $pending_change_message,
 573                                      array(
 574                                          'additional_classes' => array( 'updated', 'inline' ),
 575                                      )
 576                                  );
 577                              endif;
 578                              ?>
 579                          </td>
 580                      </tr>
 581  
 582                      <tr class="user-url-wrap">
 583                          <th><label for="url"><?php _e( 'Website' ); ?></label></th>
 584                          <td><input type="url" name="url" id="url" value="<?php echo esc_attr( $profile_user->user_url ); ?>" class="regular-text code" /></td>
 585                      </tr>
 586  
 587                      <?php foreach ( wp_get_user_contact_methods( $profile_user ) as $name => $desc ) : ?>
 588                      <tr class="user-<?php echo $name; ?>-wrap">
 589                          <th>
 590                              <label for="<?php echo $name; ?>">
 591                              <?php
 592                              /**
 593                               * Filters a user contactmethod label.
 594                               *
 595                               * The dynamic portion of the hook name, `$name`, refers to
 596                               * each of the keys in the contact methods array.
 597                               *
 598                               * @since 2.9.0
 599                               *
 600                               * @param string $desc The translatable label for the contact method.
 601                               */
 602                              echo apply_filters( "user_{$name}_label", $desc );
 603                              ?>
 604                              </label>
 605                          </th>
 606                          <td>
 607                              <input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $profile_user->$name ); ?>" class="regular-text" />
 608                          </td>
 609                      </tr>
 610                      <?php endforeach; ?>
 611                  </table>
 612  
 613                  <h2><?php IS_PROFILE_PAGE ? _e( 'About Yourself' ) : _e( 'About the user' ); ?></h2>
 614  
 615                  <table class="form-table" role="presentation">
 616                      <tr class="user-description-wrap">
 617                          <th><label for="description"><?php _e( 'Biographical Info' ); ?></label></th>
 618                          <td><textarea name="description" id="description" rows="5" cols="30"><?php echo $profile_user->description; // textarea_escaped ?></textarea>
 619                          <p class="description"><?php _e( 'Share a little biographical information to fill out your profile. This may be shown publicly.' ); ?></p></td>
 620                      </tr>
 621  
 622                      <?php if ( get_option( 'show_avatars' ) ) : ?>
 623                          <tr class="user-profile-picture">
 624                              <th><?php _e( 'Profile Picture' ); ?></th>
 625                              <td>
 626                                  <?php echo get_avatar( $user_id ); ?>
 627                                  <p class="description">
 628                                      <?php
 629                                      if ( IS_PROFILE_PAGE ) {
 630                                          $description = sprintf(
 631                                              /* translators: %s: Gravatar URL. */
 632                                              __( '<a href="%s">You can change your profile picture on Gravatar</a>.' ),
 633                                              /* translators: The localized Gravatar URL. */
 634                                              __( 'https://gravatar.com/' )
 635                                          );
 636                                      } else {
 637                                          $description = '';
 638                                      }
 639  
 640                                      /**
 641                                       * Filters the user profile picture description displayed under the Gravatar.
 642                                       *
 643                                       * @since 4.4.0
 644                                       * @since 4.7.0 Added the `$profile_user` parameter.
 645                                       *
 646                                       * @param string  $description  The description that will be printed.
 647                                       * @param WP_User $profile_user The current WP_User object.
 648                                       */
 649                                      echo apply_filters( 'user_profile_picture_description', $description, $profile_user );
 650                                      ?>
 651                                  </p>
 652                              </td>
 653                          </tr>
 654                      <?php endif; ?>
 655                      <?php
 656                      /**
 657                       * Filters the display of the password fields.
 658                       *
 659                       * @since 1.5.1
 660                       * @since 2.8.0 Added the `$profile_user` parameter.
 661                       * @since 4.4.0 Now evaluated only in user-edit.php.
 662                       *
 663                       * @param bool    $show         Whether to show the password fields. Default true.
 664                       * @param WP_User $profile_user User object for the current user to edit.
 665                       */
 666                      $show_password_fields = apply_filters( 'show_password_fields', true, $profile_user );
 667                      ?>
 668                      <?php if ( $show_password_fields ) : ?>
 669                          </table>
 670  
 671                          <h2><?php _e( 'Account Management' ); ?></h2>
 672  
 673                          <table class="form-table" role="presentation">
 674                              <tr id="password" class="user-pass1-wrap">
 675                                  <th><label for="pass1"><?php _e( 'New Password' ); ?></label></th>
 676                                  <td>
 677                                      <input type="hidden" value=" " /><!-- #24364 workaround -->
 678                                      <button type="button" class="button wp-generate-pw hide-if-no-js" aria-expanded="false"><?php _e( 'Set New Password' ); ?></button>
 679                                      <div class="wp-pwd hide-if-js">
 680                                          <div class="password-input-wrapper">
 681                                              <input type="password" name="pass1" id="pass1" class="regular-text" value="" autocomplete="new-password" spellcheck="false" data-pw="<?php echo esc_attr( wp_generate_password( 24 ) ); ?>" aria-describedby="pass-strength-result" />
 682                                              <div style="display:none" id="pass-strength-result" aria-live="polite"></div>
 683                                          </div>
 684                                          <button type="button" class="button wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
 685                                              <span class="dashicons dashicons-hidden" aria-hidden="true"></span>
 686                                              <span class="text"><?php _e( 'Hide' ); ?></span>
 687                                          </button>
 688                                          <button type="button" class="button wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel password change' ); ?>">
 689                                              <span class="dashicons dashicons-no" aria-hidden="true"></span>
 690                                              <span class="text"><?php _e( 'Cancel' ); ?></span>
 691                                          </button>
 692                                      </div>
 693                                  </td>
 694                              </tr>
 695                              <tr class="user-pass2-wrap hide-if-js">
 696                                  <th scope="row"><label for="pass2"><?php _e( 'Repeat New Password' ); ?></label></th>
 697                                  <td>
 698                                  <input type="password" name="pass2" id="pass2" class="regular-text" value="" autocomplete="new-password" spellcheck="false" aria-describedby="pass2-desc" />
 699                                      <?php if ( IS_PROFILE_PAGE ) : ?>
 700                                          <p class="description" id="pass2-desc"><?php _e( 'Type your new password again.' ); ?></p>
 701                                      <?php else : ?>
 702                                          <p class="description" id="pass2-desc"><?php _e( 'Type the new password again.' ); ?></p>
 703                                      <?php endif; ?>
 704                                  </td>
 705                              </tr>
 706                              <tr class="pw-weak">
 707                                  <th><?php _e( 'Confirm Password' ); ?></th>
 708                                  <td>
 709                                      <label>
 710                                          <input type="checkbox" name="pw_weak" class="pw-checkbox" />
 711                                          <span id="pw-weak-text-label"><?php _e( 'Confirm use of weak password' ); ?></span>
 712                                      </label>
 713                                  </td>
 714                              </tr>
 715                              <?php endif; // End Show Password Fields. ?>
 716  
 717                              <?php // Allow admins to send reset password link. ?>
 718                              <?php if ( ! IS_PROFILE_PAGE && true === wp_is_password_reset_allowed_for_user( $profile_user ) ) : ?>
 719                                  <tr class="user-generate-reset-link-wrap hide-if-no-js">
 720                                      <th><?php _e( 'Password Reset' ); ?></th>
 721                                      <td>
 722                                          <div class="generate-reset-link">
 723                                              <button type="button" class="button button-secondary" id="generate-reset-link">
 724                                                  <?php _e( 'Send Reset Link' ); ?>
 725                                              </button>
 726                                          </div>
 727                                          <p class="description">
 728                                              <?php
 729                                              printf(
 730                                                  /* translators: %s: User's display name. */
 731                                                  __( 'Send %s a link to reset their password. This will not change their password, nor will it force a change.' ),
 732                                                  esc_html( $profile_user->display_name )
 733                                              );
 734                                              ?>
 735                                          </p>
 736                                      </td>
 737                                  </tr>
 738                              <?php endif; ?>
 739  
 740                              <?php if ( IS_PROFILE_PAGE && count( $sessions->get_all() ) === 1 ) : ?>
 741                                  <tr class="user-sessions-wrap hide-if-no-js">
 742                                      <th><?php _e( 'Sessions' ); ?></th>
 743                                      <td aria-live="assertive">
 744                                          <div class="destroy-sessions"><button type="button" disabled class="button"><?php _e( 'Log Out Everywhere Else' ); ?></button></div>
 745                                          <p class="description">
 746                                              <?php _e( 'You are only logged in at this location.' ); ?>
 747                                          </p>
 748                                      </td>
 749                                  </tr>
 750                              <?php elseif ( IS_PROFILE_PAGE && count( $sessions->get_all() ) > 1 ) : ?>
 751                                  <tr class="user-sessions-wrap hide-if-no-js">
 752                                      <th><?php _e( 'Sessions' ); ?></th>
 753                                      <td aria-live="assertive">
 754                                          <div class="destroy-sessions"><button type="button" class="button" id="destroy-sessions"><?php _e( 'Log Out Everywhere Else' ); ?></button></div>
 755                                          <p class="description">
 756                                              <?php _e( 'Did you lose your phone or leave your account logged in at a public computer? You can log out everywhere else, and stay logged in here.' ); ?>
 757                                          </p>
 758                                      </td>
 759                                  </tr>
 760                              <?php elseif ( ! IS_PROFILE_PAGE && $sessions->get_all() ) : ?>
 761                                  <tr class="user-sessions-wrap hide-if-no-js">
 762                                      <th><?php _e( 'Sessions' ); ?></th>
 763                                      <td>
 764                                          <p><button type="button" class="button" id="destroy-sessions"><?php _e( 'Log Out Everywhere' ); ?></button></p>
 765                                          <p class="description">
 766                                              <?php
 767                                              /* translators: %s: User's display name. */
 768                                              printf( __( 'Log %s out of all locations.' ), $profile_user->display_name );
 769                                              ?>
 770                                          </p>
 771                                      </td>
 772                                  </tr>
 773                              <?php endif; ?>
 774                          </table>
 775  
 776                      <?php if ( wp_is_application_passwords_available_for_user( $user_id ) || ! wp_is_application_passwords_supported() ) : ?>
 777                          <div class="application-passwords hide-if-no-js" id="application-passwords-section">
 778                              <h2><?php _e( 'Application Passwords' ); ?></h2>
 779                              <p><?php _e( 'Application passwords allow authentication via non-interactive systems, such as XML-RPC or the REST API, without providing your actual password. Application passwords can be easily revoked. They cannot be used for traditional logins to your website.' ); ?></p>
 780                              <?php if ( wp_is_application_passwords_available_for_user( $user_id ) ) : ?>
 781                                  <?php
 782                                  if ( is_multisite() ) :
 783                                      $blogs       = get_blogs_of_user( $user_id, true );
 784                                      $blogs_count = count( $blogs );
 785  
 786                                      if ( $blogs_count > 1 ) :
 787                                          ?>
 788                                          <p>
 789                                              <?php
 790                                              /* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
 791                                              $message = _n(
 792                                                  'Application passwords grant access to <a href="%1$s">the %2$s site in this installation that you have permissions on</a>.',
 793                                                  'Application passwords grant access to <a href="%1$s">all %2$s sites in this installation that you have permissions on</a>.',
 794                                                  $blogs_count
 795                                              );
 796  
 797                                              if ( is_super_admin( $user_id ) ) {
 798                                                  /* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
 799                                                  $message = _n(
 800                                                      'Application passwords grant access to <a href="%1$s">the %2$s site on the network as you have Super Admin rights</a>.',
 801                                                      'Application passwords grant access to <a href="%1$s">all %2$s sites on the network as you have Super Admin rights</a>.',
 802                                                      $blogs_count
 803                                                  );
 804                                              }
 805  
 806                                              printf(
 807                                                  $message,
 808                                                  admin_url( 'my-sites.php' ),
 809                                                  number_format_i18n( $blogs_count )
 810                                              );
 811                                              ?>
 812                                          </p>
 813                                          <?php
 814                                      endif;
 815                                  endif;
 816                                  ?>
 817  
 818                                  <?php if ( ! wp_is_site_protected_by_basic_auth( 'front' ) ) : ?>
 819                                      <div class="create-application-password form-wrap">
 820                                          <div class="form-field">
 821                                              <label for="new_application_password_name"><?php _e( 'New Application Password Name' ); ?></label>
 822                                              <input type="text" size="30" id="new_application_password_name" name="new_application_password_name" class="input" aria-required="true" aria-describedby="new_application_password_name_desc" spellcheck="false" />
 823                                              <p class="description" id="new_application_password_name_desc"><?php _e( 'Required to create an Application Password, but not to update the user.' ); ?></p>
 824                                          </div>
 825  
 826                                          <?php
 827                                          /**
 828                                           * Fires in the create Application Passwords form.
 829                                           *
 830                                           * @since 5.6.0
 831                                           *
 832                                           * @param WP_User $profile_user The current WP_User object.
 833                                           */
 834                                          do_action( 'wp_create_application_password_form', $profile_user );
 835                                          ?>
 836  
 837                                          <button type="button" name="do_new_application_password" id="do_new_application_password" class="button button-secondary"><?php _e( 'Add Application Password' ); ?></button>
 838                                      </div>
 839                                      <?php
 840                                  else :
 841                                      wp_admin_notice(
 842                                          __( 'Your website appears to use Basic Authentication, which is not currently compatible with Application Passwords.' ),
 843                                          array(
 844                                              'type' => 'error',
 845                                              'additional_classes' => array( 'inline' ),
 846                                          )
 847                                      );
 848                                  endif;
 849                                  ?>
 850  
 851                                  <div class="application-passwords-list-table-wrapper">
 852                                      <?php
 853                                      $application_passwords_list_table = _get_list_table( 'WP_Application_Passwords_List_Table', array( 'screen' => 'application-passwords-user' ) );
 854                                      $application_passwords_list_table->prepare_items();
 855                                      $application_passwords_list_table->display();
 856                                      ?>
 857                                  </div>
 858                              <?php elseif ( ! wp_is_application_passwords_supported() ) : ?>
 859                                  <p><?php _e( 'The application password feature requires HTTPS, which is not enabled on this site.' ); ?></p>
 860                                  <p>
 861                                      <?php
 862                                      printf(
 863                                          /* translators: %s: Documentation URL. */
 864                                          __( 'If this is a development website, you can <a href="%s">set the environment type accordingly</a> to enable application passwords.' ),
 865                                          __( 'https://developer.wordpress.org/apis/wp-config-php/#wp-environment-type' )
 866                                      );
 867                                      ?>
 868                                  </p>
 869                              <?php endif; ?>
 870                          </div>
 871                      <?php endif; // End Application Passwords. ?>
 872  
 873                      <?php
 874                      if ( IS_PROFILE_PAGE ) {
 875                          /**
 876                           * Fires after the 'About Yourself' settings table on the 'Profile' editing screen.
 877                           *
 878                           * The action only fires if the current user is editing their own profile.
 879                           *
 880                           * @since 2.0.0
 881                           *
 882                           * @param WP_User $profile_user The current WP_User object.
 883                           */
 884                          do_action( 'show_user_profile', $profile_user );
 885                      } else {
 886                          /**
 887                           * Fires after the 'About the User' settings table on the 'Edit User' screen.
 888                           *
 889                           * @since 2.0.0
 890                           *
 891                           * @param WP_User $profile_user The current WP_User object.
 892                           */
 893                          do_action( 'edit_user_profile', $profile_user );
 894                      }
 895                      ?>
 896  
 897                      <?php
 898                      /**
 899                       * Filters whether to display additional capabilities for the user.
 900                       *
 901                       * The 'Additional Capabilities' section will only be enabled if
 902                       * the number of the user's capabilities exceeds their number of
 903                       * roles.
 904                       *
 905                       * @since 2.8.0
 906                       *
 907                       * @param bool    $enable      Whether to display the capabilities. Default true.
 908                       * @param WP_User $profile_user The current WP_User object.
 909                       */
 910                      $display_additional_caps = apply_filters( 'additional_capabilities_display', true, $profile_user );
 911                      ?>
 912  
 913                  <?php if ( count( $profile_user->caps ) > count( $profile_user->roles ) && ( true === $display_additional_caps ) ) : ?>
 914                      <h2><?php _e( 'Additional Capabilities' ); ?></h2>
 915  
 916                      <table class="form-table" role="presentation">
 917                          <tr class="user-capabilities-wrap">
 918                              <th scope="row"><?php _e( 'Capabilities' ); ?></th>
 919                              <td>
 920                                  <?php
 921                                  $output = '';
 922                                  foreach ( $profile_user->caps as $cap => $value ) {
 923                                      if ( ! $wp_roles->is_role( $cap ) ) {
 924                                          if ( '' !== $output ) {
 925                                              $output .= ', ';
 926                                          }
 927  
 928                                          if ( $value ) {
 929                                              $output .= $cap;
 930                                          } else {
 931                                              /* translators: %s: Capability name. */
 932                                              $output .= sprintf( __( 'Denied: %s' ), $cap );
 933                                          }
 934                                      }
 935                                  }
 936                                  echo $output;
 937                                  ?>
 938                              </td>
 939                          </tr>
 940                      </table>
 941                  <?php endif; // End Display Additional Capabilities. ?>
 942  
 943                  <input type="hidden" name="action" value="update" />
 944                  <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $user_id ); ?>" />
 945  
 946                  <?php submit_button( IS_PROFILE_PAGE ? __( 'Update Profile' ) : __( 'Update User' ) ); ?>
 947  
 948              </form>
 949          </div>
 950          <?php
 951          break;
 952  }
 953  ?>
 954  <script type="text/javascript">
 955      if (window.location.hash == '#password') {
 956          document.getElementById('pass1').focus();
 957      }
 958  </script>
 959  
 960  <script type="text/javascript">
 961      jQuery( function( $ ) {
 962          var languageSelect = $( '#locale' );
 963          $( 'form' ).on( 'submit', function() {
 964              /*
 965               * Don't show a spinner for English and installed languages,
 966               * as there is nothing to download.
 967               */
 968              if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
 969                  $( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
 970              }
 971          });
 972      } );
 973  </script>
 974  
 975  <?php if ( isset( $application_passwords_list_table ) ) : ?>
 976      <script type="text/html" id="tmpl-new-application-password">
 977          <div class="notice notice-success is-dismissible new-application-password-notice" role="alert">
 978              <p class="application-password-display">
 979                  <label for="new-application-password-value">
 980                      <?php
 981                      printf(
 982                          /* translators: %s: Application name. */
 983                          __( 'Your new password for %s is:' ),
 984                          '<strong>{{ data.name }}</strong>'
 985                      );
 986                      ?>
 987                  </label>
 988                  <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="{{ data.password }}" />
 989                  <button type="button" class="button copy-button" data-clipboard-text="{{ data.password }}"><?php _e( 'Copy' ); ?></button>
 990                  <span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>
 991              </p>
 992              <p><?php _e( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ); ?></p>
 993              <button type="button" class="notice-dismiss">
 994                  <span class="screen-reader-text">
 995                      <?php
 996                      /* translators: Hidden accessibility text. */
 997                      _e( 'Dismiss this notice.' );
 998                      ?>
 999                  </span>
1000              </button>
1001          </div>
1002      </script>
1003  
1004      <script type="text/html" id="tmpl-application-password-row">
1005          <?php $application_passwords_list_table->print_js_template_row(); ?>
1006      </script>
1007  <?php endif; ?>
1008  <?php
1009  require_once  ABSPATH . 'wp-admin/admin-footer.php';


Generated : Mon Apr 28 08:20:01 2025 Cross-referenced by PHPXref