[ 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_text_field( $_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 = '<strong>' . __( 'Profile updated.' ) . '</strong>';
 218              else :
 219                  $message = '<strong>' . __( 'User updated.' ) . '</strong>';
 220              endif;
 221              if ( $wp_http_referer && ! str_contains( $wp_http_referer, 'user-new.php' ) && ! IS_PROFILE_PAGE ) :
 222                  $message .= '<a href="' . esc_url( wp_validate_redirect( sanitize_url( $wp_http_referer ), self_admin_url( 'users.php' ) ) ) . '">' . __( '&larr; Go to Users' ) . '</a>';
 223              endif;
 224              wp_admin_notice(
 225                  $message,
 226                  array(
 227                      'id'                 => 'message',
 228                      'dismissible'        => true,
 229                      'additional_classes' => array( 'updated' ),
 230                  )
 231              );
 232          endif;
 233  
 234          if ( isset( $_GET['error'] ) ) :
 235              $message = '';
 236              if ( 'new-email' === $_GET['error'] ) :
 237                  $message = __( 'Error while saving the new email address. Please try again.' );
 238              endif;
 239              wp_admin_notice(
 240                  $message,
 241                  array(
 242                      'type' => 'error',
 243                  )
 244              );
 245          endif;
 246  
 247          if ( isset( $errors ) && is_wp_error( $errors ) ) {
 248              wp_admin_notice(
 249                  implode( "</p>\n<p>", $errors->get_error_messages() ),
 250                  array(
 251                      'additional_classes' => array( 'error' ),
 252                  )
 253              );
 254          }
 255          ?>
 256  
 257          <div class="wrap" id="profile-page">
 258              <h1 class="wp-heading-inline">
 259                      <?php echo esc_html( $title ); ?>
 260              </h1>
 261  
 262              <?php if ( ! IS_PROFILE_PAGE ) : ?>
 263                  <?php if ( current_user_can( 'create_users' ) ) : ?>
 264                      <a href="user-new.php" class="page-title-action"><?php echo esc_html__( 'Add New User' ); ?></a>
 265                  <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
 266                      <a href="user-new.php" class="page-title-action"><?php echo esc_html__( 'Add Existing User' ); ?></a>
 267                  <?php endif; ?>
 268              <?php endif; ?>
 269  
 270              <hr class="wp-header-end">
 271  
 272              <form id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post" novalidate="novalidate"
 273                  <?php
 274                  /**
 275                   * Fires inside the your-profile form tag on the user editing screen.
 276                   *
 277                   * @since 3.0.0
 278                   */
 279                  do_action( 'user_edit_form_tag' );
 280                  ?>
 281                  >
 282                  <?php wp_nonce_field( 'update-user_' . $user_id ); ?>
 283                  <?php if ( $wp_http_referer ) : ?>
 284                      <input type="hidden" name="wp_http_referer" value="<?php echo esc_url( $wp_http_referer ); ?>" />
 285                  <?php endif; ?>
 286                  <p>
 287                      <input type="hidden" name="from" value="profile" />
 288                      <input type="hidden" name="checkuser_id" value="<?php echo get_current_user_id(); ?>" />
 289                  </p>
 290  
 291                  <h2><?php _e( 'Personal Options' ); ?></h2>
 292  
 293                  <table class="form-table" role="presentation">
 294                      <?php if ( ! ( IS_PROFILE_PAGE && ! $user_can_edit ) ) : ?>
 295                          <tr class="user-rich-editing-wrap">
 296                              <th scope="row"><?php _e( 'Visual Editor' ); ?></th>
 297                              <td>
 298                                  <label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="false" <?php checked( 'false', $profile_user->rich_editing ); ?> />
 299                                      <?php _e( 'Disable the visual editor when writing' ); ?>
 300                                  </label>
 301                              </td>
 302                          </tr>
 303                      <?php endif; ?>
 304  
 305                      <?php
 306                      $show_syntax_highlighting_preference = (
 307                      // For Custom HTML widget and Additional CSS in Customizer.
 308                      user_can( $profile_user, 'edit_theme_options' )
 309                      ||
 310                      // Edit plugins.
 311                      user_can( $profile_user, 'edit_plugins' )
 312                      ||
 313                      // Edit themes.
 314                      user_can( $profile_user, 'edit_themes' )
 315                      );
 316                      ?>
 317  
 318                      <?php if ( $show_syntax_highlighting_preference ) : ?>
 319                      <tr class="user-syntax-highlighting-wrap">
 320                          <th scope="row"><?php _e( 'Syntax Highlighting' ); ?></th>
 321                          <td>
 322                              <label for="syntax_highlighting"><input name="syntax_highlighting" type="checkbox" id="syntax_highlighting" value="false" <?php checked( 'false', $profile_user->syntax_highlighting ); ?> />
 323                                  <?php _e( 'Disable syntax highlighting when editing code' ); ?>
 324                              </label>
 325                          </td>
 326                      </tr>
 327                      <?php endif; ?>
 328  
 329                      <?php if ( count( $_wp_admin_css_colors ) > 1 && has_action( 'admin_color_scheme_picker' ) ) : ?>
 330                      <tr class="user-admin-color-wrap">
 331                          <th scope="row"><?php _e( 'Admin Color Scheme' ); ?></th>
 332                          <td>
 333                              <?php
 334                              /**
 335                               * Fires in the 'Admin Color Scheme' section of the user editing screen.
 336                               *
 337                               * The section is only enabled if a callback is hooked to the action,
 338                               * and if there is more than one defined color scheme for the admin.
 339                               *
 340                               * @since 3.0.0
 341                               * @since 3.8.1 Added `$user_id` parameter.
 342                               *
 343                               * @param int $user_id The user ID.
 344                               */
 345                              do_action( 'admin_color_scheme_picker', $user_id );
 346                              ?>
 347                          </td>
 348                      </tr>
 349                      <?php endif; // End if count ( $_wp_admin_css_colors ) > 1 ?>
 350  
 351                      <?php if ( ! ( IS_PROFILE_PAGE && ! $user_can_edit ) ) : ?>
 352                      <tr class="user-comment-shortcuts-wrap">
 353                          <th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th>
 354                          <td>
 355                              <label for="comment_shortcuts">
 356                                  <input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php checked( 'true', $profile_user->comment_shortcuts ); ?> />
 357                                  <?php _e( 'Enable keyboard shortcuts for comment moderation.' ); ?>
 358                              </label>
 359                              <?php _e( '<a href="https://wordpress.org/documentation/article/keyboard-shortcuts-classic-editor/#keyboard-shortcuts-for-comments">Documentation on Keyboard Shortcuts</a>' ); ?>
 360                          </td>
 361                      </tr>
 362                      <?php endif; ?>
 363  
 364                      <tr class="show-admin-bar user-admin-bar-front-wrap">
 365                          <th scope="row"><?php _e( 'Toolbar' ); ?></th>
 366                          <td>
 367                              <label for="admin_bar_front">
 368                                  <input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="1"<?php checked( _get_admin_bar_pref( 'front', $profile_user->ID ) ); ?> />
 369                                  <?php _e( 'Show Toolbar when viewing site' ); ?>
 370                              </label><br />
 371                          </td>
 372                      </tr>
 373  
 374                      <?php
 375                      $languages                = get_available_languages();
 376                      $can_install_translations = current_user_can( 'install_languages' ) && wp_can_install_language_pack();
 377                      ?>
 378                      <?php if ( $languages || $can_install_translations ) : ?>
 379                      <tr class="user-language-wrap">
 380                          <th scope="row">
 381                              <?php /* translators: The user language selection field label. */ ?>
 382                              <label for="locale"><?php _e( 'Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span></label>
 383                          </th>
 384                          <td>
 385                              <?php
 386                                  $user_locale = $profile_user->locale;
 387  
 388                              if ( 'en_US' === $user_locale ) {
 389                                  $user_locale = '';
 390                              } elseif ( '' === $user_locale || ! in_array( $user_locale, $languages, true ) ) {
 391                                  $user_locale = 'site-default';
 392                              }
 393  
 394                              wp_dropdown_languages(
 395                                  array(
 396                                      'name'      => 'locale',
 397                                      'id'        => 'locale',
 398                                      'selected'  => $user_locale,
 399                                      'languages' => $languages,
 400                                      'show_available_translations' => $can_install_translations,
 401                                      'show_option_site_default' => true,
 402                                  )
 403                              );
 404                              ?>
 405                          </td>
 406                      </tr>
 407                      <?php endif; ?>
 408  
 409                      <?php
 410                      /**
 411                       * Fires at the end of the 'Personal Options' settings table on the user editing screen.
 412                       *
 413                       * @since 2.7.0
 414                       *
 415                       * @param WP_User $profile_user The current WP_User object.
 416                       */
 417                      do_action( 'personal_options', $profile_user );
 418                      ?>
 419  
 420                  </table>
 421                  <?php
 422                  if ( IS_PROFILE_PAGE ) {
 423                      /**
 424                       * Fires after the 'Personal Options' settings table on the 'Profile' editing screen.
 425                       *
 426                       * The action only fires if the current user is editing their own profile.
 427                       *
 428                       * @since 2.0.0
 429                       *
 430                       * @param WP_User $profile_user The current WP_User object.
 431                       */
 432                      do_action( 'profile_personal_options', $profile_user );
 433                  }
 434                  ?>
 435  
 436                  <h2><?php _e( 'Name' ); ?></h2>
 437  
 438                  <table class="form-table" role="presentation">
 439                      <tr class="user-user-login-wrap">
 440                          <th><label for="user_login"><?php _e( 'Username' ); ?></label></th>
 441                          <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr( $profile_user->user_login ); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e( 'Usernames cannot be changed.' ); ?></span></td>
 442                      </tr>
 443  
 444                      <?php if ( ! IS_PROFILE_PAGE && ! is_network_admin() && current_user_can( 'promote_user', $profile_user->ID ) ) : ?>
 445                          <tr class="user-role-wrap">
 446                              <th><label for="role"><?php _e( 'Role' ); ?></label></th>
 447                              <td>
 448                                  <select name="role" id="role">
 449                                      <?php
 450                                      // Compare user role against currently editable roles.
 451                                      $user_roles = array_intersect( array_values( $profile_user->roles ), array_keys( get_editable_roles() ) );
 452                                      $user_role  = reset( $user_roles );
 453  
 454                                      // Print the full list of roles with the primary one selected.
 455                                      wp_dropdown_roles( $user_role );
 456  
 457                                      // Print the 'no role' option. Make it selected if the user has no role yet.
 458                                      if ( $user_role ) {
 459                                          echo '<option value="">' . __( '&mdash; No role for this site &mdash;' ) . '</option>';
 460                                      } else {
 461                                          echo '<option value="" selected="selected">' . __( '&mdash; No role for this site &mdash;' ) . '</option>';
 462                                      }
 463                                      ?>
 464                              </select>
 465                              </td>
 466                          </tr>
 467                      <?php endif; // End if ! IS_PROFILE_PAGE. ?>
 468  
 469                      <?php if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && ! isset( $super_admins ) ) : ?>
 470                          <tr class="user-super-admin-wrap">
 471                              <th><?php _e( 'Super Admin' ); ?></th>
 472                              <td>
 473                                  <?php if ( 0 !== strcasecmp( $profile_user->user_email, get_site_option( 'admin_email' ) ) || ! is_super_admin( $profile_user->ID ) ) : ?>
 474                                      <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>
 475                                  <?php else : ?>
 476                                      <p><?php _e( 'Super admin privileges cannot be removed because this user has the network admin email.' ); ?></p>
 477                                  <?php endif; ?>
 478                              </td>
 479                          </tr>
 480                      <?php endif; ?>
 481  
 482                      <tr class="user-first-name-wrap">
 483                          <th><label for="first_name"><?php _e( 'First Name' ); ?></label></th>
 484                          <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profile_user->first_name ); ?>" class="regular-text" /></td>
 485                      </tr>
 486  
 487                      <tr class="user-last-name-wrap">
 488                          <th><label for="last_name"><?php _e( 'Last Name' ); ?></label></th>
 489                          <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profile_user->last_name ); ?>" class="regular-text" /></td>
 490                      </tr>
 491  
 492                      <tr class="user-nickname-wrap">
 493                          <th><label for="nickname"><?php _e( 'Nickname' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
 494                          <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( $profile_user->nickname ); ?>" class="regular-text" /></td>
 495                      </tr>
 496  
 497                      <tr class="user-display-name-wrap">
 498                          <th>
 499                              <label for="display_name"><?php _e( 'Display name publicly as' ); ?></label>
 500                          </th>
 501                          <td>
 502                              <select name="display_name" id="display_name">
 503                                  <?php
 504                                      $public_display                     = array();
 505                                      $public_display['display_nickname'] = $profile_user->nickname;
 506                                      $public_display['display_username'] = $profile_user->user_login;
 507  
 508                                  if ( ! empty( $profile_user->first_name ) ) {
 509                                      $public_display['display_firstname'] = $profile_user->first_name;
 510                                  }
 511  
 512                                  if ( ! empty( $profile_user->last_name ) ) {
 513                                      $public_display['display_lastname'] = $profile_user->last_name;
 514                                  }
 515  
 516                                  if ( ! empty( $profile_user->first_name ) && ! empty( $profile_user->last_name ) ) {
 517                                      $public_display['display_firstlast'] = $profile_user->first_name . ' ' . $profile_user->last_name;
 518                                      $public_display['display_lastfirst'] = $profile_user->last_name . ' ' . $profile_user->first_name;
 519                                  }
 520  
 521                                  if ( ! in_array( $profile_user->display_name, $public_display, true ) ) { // Only add this if it isn't duplicated elsewhere.
 522                                      $public_display = array( 'display_displayname' => $profile_user->display_name ) + $public_display;
 523                                  }
 524  
 525                                  $public_display = array_map( 'trim', $public_display );
 526                                  $public_display = array_unique( $public_display );
 527  
 528                                  ?>
 529                                  <?php foreach ( $public_display as $id => $item ) : ?>
 530                                      <option <?php selected( $profile_user->display_name, $item ); ?>><?php echo $item; ?></option>
 531                                  <?php endforeach; ?>
 532                              </select>
 533                          </td>
 534                      </tr>
 535                  </table>
 536  
 537                  <h2><?php _e( 'Contact Info' ); ?></h2>
 538  
 539                  <table class="form-table" role="presentation">
 540                      <tr class="user-email-wrap">
 541                          <th><label for="email"><?php _e( 'Email' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
 542                          <td>
 543                              <input type="email" name="email" id="email" aria-describedby="email-description" value="<?php echo esc_attr( $profile_user->user_email ); ?>" class="regular-text ltr" />
 544                              <?php if ( $profile_user->ID === $current_user->ID ) : ?>
 545                                  <p class="description" id="email-description">
 546                                      <?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>' ); ?>
 547                                  </p>
 548                              <?php endif; ?>
 549  
 550                              <?php
 551                              $new_email = get_user_meta( $current_user->ID, '_new_email', true );
 552                              if ( $new_email && $new_email['newemail'] !== $current_user->user_email && $profile_user->ID === $current_user->ID ) :
 553  
 554                                  $pending_change_message = sprintf(
 555                                      /* translators: %s: New email. */
 556                                      __( 'There is a pending change of your email to %s.' ),
 557                                      '<code>' . esc_html( $new_email['newemail'] ) . '</code>'
 558                                  );
 559                                  $pending_change_message .= sprintf(
 560                                      ' <a href="%1$s">%2$s</a>',
 561                                      esc_url( wp_nonce_url( self_admin_url( 'profile.php?dismiss=' . $current_user->ID . '_new_email' ), 'dismiss-' . $current_user->ID . '_new_email' ) ),
 562                                      __( 'Cancel' )
 563                                  );
 564                                  wp_admin_notice(
 565                                      $pending_change_message,
 566                                      array(
 567                                          'additional_classes' => array( 'updated', 'inline' ),
 568                                      )
 569                                  );
 570                              endif;
 571                              ?>
 572                          </td>
 573                      </tr>
 574  
 575                      <tr class="user-url-wrap">
 576                          <th><label for="url"><?php _e( 'Website' ); ?></label></th>
 577                          <td><input type="url" name="url" id="url" value="<?php echo esc_attr( $profile_user->user_url ); ?>" class="regular-text code" /></td>
 578                      </tr>
 579  
 580                      <?php foreach ( wp_get_user_contact_methods( $profile_user ) as $name => $desc ) : ?>
 581                      <tr class="user-<?php echo $name; ?>-wrap">
 582                          <th>
 583                              <label for="<?php echo $name; ?>">
 584                              <?php
 585                              /**
 586                               * Filters a user contactmethod label.
 587                               *
 588                               * The dynamic portion of the hook name, `$name`, refers to
 589                               * each of the keys in the contact methods array.
 590                               *
 591                               * @since 2.9.0
 592                               *
 593                               * @param string $desc The translatable label for the contact method.
 594                               */
 595                              echo apply_filters( "user_{$name}_label", $desc );
 596                              ?>
 597                              </label>
 598                          </th>
 599                          <td>
 600                              <input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $profile_user->$name ); ?>" class="regular-text" />
 601                          </td>
 602                      </tr>
 603                      <?php endforeach; ?>
 604                  </table>
 605  
 606                  <h2><?php IS_PROFILE_PAGE ? _e( 'About Yourself' ) : _e( 'About the user' ); ?></h2>
 607  
 608                  <table class="form-table" role="presentation">
 609                      <tr class="user-description-wrap">
 610                          <th><label for="description"><?php _e( 'Biographical Info' ); ?></label></th>
 611                          <td><textarea name="description" id="description" rows="5" cols="30"><?php echo $profile_user->description; // textarea_escaped ?></textarea>
 612                          <p class="description"><?php _e( 'Share a little biographical information to fill out your profile. This may be shown publicly.' ); ?></p></td>
 613                      </tr>
 614  
 615                      <?php if ( get_option( 'show_avatars' ) ) : ?>
 616                          <tr class="user-profile-picture">
 617                              <th><?php _e( 'Profile Picture' ); ?></th>
 618                              <td>
 619                                  <?php echo get_avatar( $user_id ); ?>
 620                                  <p class="description">
 621                                      <?php
 622                                      if ( IS_PROFILE_PAGE ) {
 623                                          $description = sprintf(
 624                                              /* translators: %s: Gravatar URL. */
 625                                              __( '<a href="%s">You can change your profile picture on Gravatar</a>.' ),
 626                                              __( 'https://en.gravatar.com/' )
 627                                          );
 628                                      } else {
 629                                          $description = '';
 630                                      }
 631  
 632                                      /**
 633                                       * Filters the user profile picture description displayed under the Gravatar.
 634                                       *
 635                                       * @since 4.4.0
 636                                       * @since 4.7.0 Added the `$profile_user` parameter.
 637                                       *
 638                                       * @param string  $description  The description that will be printed.
 639                                       * @param WP_User $profile_user The current WP_User object.
 640                                       */
 641                                      echo apply_filters( 'user_profile_picture_description', $description, $profile_user );
 642                                      ?>
 643                                  </p>
 644                              </td>
 645                          </tr>
 646                      <?php endif; ?>
 647                      <?php
 648                      /**
 649                       * Filters the display of the password fields.
 650                       *
 651                       * @since 1.5.1
 652                       * @since 2.8.0 Added the `$profile_user` parameter.
 653                       * @since 4.4.0 Now evaluated only in user-edit.php.
 654                       *
 655                       * @param bool    $show         Whether to show the password fields. Default true.
 656                       * @param WP_User $profile_user User object for the current user to edit.
 657                       */
 658                      $show_password_fields = apply_filters( 'show_password_fields', true, $profile_user );
 659                      ?>
 660                      <?php if ( $show_password_fields ) : ?>
 661                          </table>
 662  
 663                          <h2><?php _e( 'Account Management' ); ?></h2>
 664  
 665                          <table class="form-table" role="presentation">
 666                              <tr id="password" class="user-pass1-wrap">
 667                                  <th><label for="pass1"><?php _e( 'New Password' ); ?></label></th>
 668                                  <td>
 669                                      <input type="hidden" value=" " /><!-- #24364 workaround -->
 670                                      <button type="button" class="button wp-generate-pw hide-if-no-js" aria-expanded="false"><?php _e( 'Set New Password' ); ?></button>
 671                                      <div class="wp-pwd hide-if-js">
 672                                          <div class="password-input-wrapper">
 673                                              <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" />
 674                                              <div style="display:none" id="pass-strength-result" aria-live="polite"></div>
 675                                          </div>
 676                                          <button type="button" class="button wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
 677                                              <span class="dashicons dashicons-hidden" aria-hidden="true"></span>
 678                                              <span class="text"><?php _e( 'Hide' ); ?></span>
 679                                          </button>
 680                                          <button type="button" class="button wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel password change' ); ?>">
 681                                              <span class="dashicons dashicons-no" aria-hidden="true"></span>
 682                                              <span class="text"><?php _e( 'Cancel' ); ?></span>
 683                                          </button>
 684                                      </div>
 685                                  </td>
 686                              </tr>
 687                              <tr class="user-pass2-wrap hide-if-js">
 688                                  <th scope="row"><label for="pass2"><?php _e( 'Repeat New Password' ); ?></label></th>
 689                                  <td>
 690                                  <input type="password" name="pass2" id="pass2" class="regular-text" value="" autocomplete="new-password" spellcheck="false" aria-describedby="pass2-desc" />
 691                                      <?php if ( IS_PROFILE_PAGE ) : ?>
 692                                          <p class="description" id="pass2-desc"><?php _e( 'Type your new password again.' ); ?></p>
 693                                      <?php else : ?>
 694                                          <p class="description" id="pass2-desc"><?php _e( 'Type the new password again.' ); ?></p>
 695                                      <?php endif; ?>
 696                                  </td>
 697                              </tr>
 698                              <tr class="pw-weak">
 699                                  <th><?php _e( 'Confirm Password' ); ?></th>
 700                                  <td>
 701                                      <label>
 702                                          <input type="checkbox" name="pw_weak" class="pw-checkbox" />
 703                                          <span id="pw-weak-text-label"><?php _e( 'Confirm use of weak password' ); ?></span>
 704                                      </label>
 705                                  </td>
 706                              </tr>
 707                              <?php endif; // End Show Password Fields. ?>
 708  
 709                              <?php // Allow admins to send reset password link. ?>
 710                              <?php if ( ! IS_PROFILE_PAGE && true === wp_is_password_reset_allowed_for_user( $profile_user ) ) : ?>
 711                                  <tr class="user-generate-reset-link-wrap hide-if-no-js">
 712                                      <th><?php _e( 'Password Reset' ); ?></th>
 713                                      <td>
 714                                          <div class="generate-reset-link">
 715                                              <button type="button" class="button button-secondary" id="generate-reset-link">
 716                                                  <?php _e( 'Send Reset Link' ); ?>
 717                                              </button>
 718                                          </div>
 719                                          <p class="description">
 720                                              <?php
 721                                              printf(
 722                                                  /* translators: %s: User's display name. */
 723                                                  __( 'Send %s a link to reset their password. This will not change their password, nor will it force a change.' ),
 724                                                  esc_html( $profile_user->display_name )
 725                                              );
 726                                              ?>
 727                                          </p>
 728                                      </td>
 729                                  </tr>
 730                              <?php endif; ?>
 731  
 732                              <?php if ( IS_PROFILE_PAGE && count( $sessions->get_all() ) === 1 ) : ?>
 733                                  <tr class="user-sessions-wrap hide-if-no-js">
 734                                      <th><?php _e( 'Sessions' ); ?></th>
 735                                      <td aria-live="assertive">
 736                                          <div class="destroy-sessions"><button type="button" disabled class="button"><?php _e( 'Log Out Everywhere Else' ); ?></button></div>
 737                                          <p class="description">
 738                                              <?php _e( 'You are only logged in at this location.' ); ?>
 739                                          </p>
 740                                      </td>
 741                                  </tr>
 742                              <?php elseif ( IS_PROFILE_PAGE && count( $sessions->get_all() ) > 1 ) : ?>
 743                                  <tr class="user-sessions-wrap hide-if-no-js">
 744                                      <th><?php _e( 'Sessions' ); ?></th>
 745                                      <td aria-live="assertive">
 746                                          <div class="destroy-sessions"><button type="button" class="button" id="destroy-sessions"><?php _e( 'Log Out Everywhere Else' ); ?></button></div>
 747                                          <p class="description">
 748                                              <?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.' ); ?>
 749                                          </p>
 750                                      </td>
 751                                  </tr>
 752                              <?php elseif ( ! IS_PROFILE_PAGE && $sessions->get_all() ) : ?>
 753                                  <tr class="user-sessions-wrap hide-if-no-js">
 754                                      <th><?php _e( 'Sessions' ); ?></th>
 755                                      <td>
 756                                          <p><button type="button" class="button" id="destroy-sessions"><?php _e( 'Log Out Everywhere' ); ?></button></p>
 757                                          <p class="description">
 758                                              <?php
 759                                              /* translators: %s: User's display name. */
 760                                              printf( __( 'Log %s out of all locations.' ), $profile_user->display_name );
 761                                              ?>
 762                                          </p>
 763                                      </td>
 764                                  </tr>
 765                              <?php endif; ?>
 766                          </table>
 767  
 768                      <?php if ( wp_is_application_passwords_available_for_user( $user_id ) || ! wp_is_application_passwords_supported() ) : ?>
 769                          <div class="application-passwords hide-if-no-js" id="application-passwords-section">
 770                              <h2><?php _e( 'Application Passwords' ); ?></h2>
 771                              <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>
 772                              <?php if ( wp_is_application_passwords_available_for_user( $user_id ) ) : ?>
 773                                  <?php
 774                                  if ( is_multisite() ) :
 775                                      $blogs       = get_blogs_of_user( $user_id, true );
 776                                      $blogs_count = count( $blogs );
 777  
 778                                      if ( $blogs_count > 1 ) :
 779                                          ?>
 780                                          <p>
 781                                              <?php
 782                                              /* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
 783                                              $message = _n(
 784                                                  'Application passwords grant access to <a href="%1$s">the %2$s site in this installation that you have permissions on</a>.',
 785                                                  'Application passwords grant access to <a href="%1$s">all %2$s sites in this installation that you have permissions on</a>.',
 786                                                  $blogs_count
 787                                              );
 788  
 789                                              if ( is_super_admin( $user_id ) ) {
 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 on the network as you have Super Admin rights</a>.',
 793                                                      'Application passwords grant access to <a href="%1$s">all %2$s sites on the network as you have Super Admin rights</a>.',
 794                                                      $blogs_count
 795                                                  );
 796                                              }
 797  
 798                                              printf(
 799                                                  $message,
 800                                                  admin_url( 'my-sites.php' ),
 801                                                  number_format_i18n( $blogs_count )
 802                                              );
 803                                              ?>
 804                                          </p>
 805                                          <?php
 806                                      endif;
 807                                  endif;
 808                                  ?>
 809  
 810                                  <?php if ( ! wp_is_site_protected_by_basic_auth( 'front' ) ) : ?>
 811                                      <div class="create-application-password form-wrap">
 812                                          <div class="form-field">
 813                                              <label for="new_application_password_name"><?php _e( 'New Application Password Name' ); ?></label>
 814                                              <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" />
 815                                              <p class="description" id="new_application_password_name_desc"><?php _e( 'Required to create an Application Password, but not to update the user.' ); ?></p>
 816                                          </div>
 817  
 818                                          <?php
 819                                          /**
 820                                           * Fires in the create Application Passwords form.
 821                                           *
 822                                           * @since 5.6.0
 823                                           *
 824                                           * @param WP_User $profile_user The current WP_User object.
 825                                           */
 826                                          do_action( 'wp_create_application_password_form', $profile_user );
 827                                          ?>
 828  
 829                                          <button type="button" name="do_new_application_password" id="do_new_application_password" class="button button-secondary"><?php _e( 'Add New Application Password' ); ?></button>
 830                                      </div>
 831                                      <?php
 832                                  else :
 833                                      wp_admin_notice(
 834                                          __( 'Your website appears to use Basic Authentication, which is not currently compatible with Application Passwords.' ),
 835                                          array(
 836                                              'type' => 'error',
 837                                              'additional_classes' => array( 'inline' ),
 838                                          )
 839                                      );
 840                                  endif;
 841                                  ?>
 842  
 843                                  <div class="application-passwords-list-table-wrapper">
 844                                      <?php
 845                                      $application_passwords_list_table = _get_list_table( 'WP_Application_Passwords_List_Table', array( 'screen' => 'application-passwords-user' ) );
 846                                      $application_passwords_list_table->prepare_items();
 847                                      $application_passwords_list_table->display();
 848                                      ?>
 849                                  </div>
 850                              <?php elseif ( ! wp_is_application_passwords_supported() ) : ?>
 851                                  <p><?php _e( 'The application password feature requires HTTPS, which is not enabled on this site.' ); ?></p>
 852                                  <p>
 853                                      <?php
 854                                      printf(
 855                                          /* translators: %s: Documentation URL. */
 856                                          __( 'If this is a development website you can <a href="%s" target="_blank">set the environment type accordingly</a> to enable application passwords.' ),
 857                                          __( 'https://developer.wordpress.org/apis/wp-config-php/#wp-environment-type' )
 858                                      );
 859                                      ?>
 860                                  </p>
 861                              <?php endif; ?>
 862                          </div>
 863                      <?php endif; // End Application Passwords. ?>
 864  
 865                      <?php
 866                      if ( IS_PROFILE_PAGE ) {
 867                          /**
 868                           * Fires after the 'About Yourself' settings table on the 'Profile' editing screen.
 869                           *
 870                           * The action only fires if the current user is editing their own profile.
 871                           *
 872                           * @since 2.0.0
 873                           *
 874                           * @param WP_User $profile_user The current WP_User object.
 875                           */
 876                          do_action( 'show_user_profile', $profile_user );
 877                      } else {
 878                          /**
 879                           * Fires after the 'About the User' settings table on the 'Edit User' screen.
 880                           *
 881                           * @since 2.0.0
 882                           *
 883                           * @param WP_User $profile_user The current WP_User object.
 884                           */
 885                          do_action( 'edit_user_profile', $profile_user );
 886                      }
 887                      ?>
 888  
 889                      <?php
 890                      /**
 891                       * Filters whether to display additional capabilities for the user.
 892                       *
 893                       * The 'Additional Capabilities' section will only be enabled if
 894                       * the number of the user's capabilities exceeds their number of
 895                       * roles.
 896                       *
 897                       * @since 2.8.0
 898                       *
 899                       * @param bool    $enable      Whether to display the capabilities. Default true.
 900                       * @param WP_User $profile_user The current WP_User object.
 901                       */
 902                      $display_additional_caps = apply_filters( 'additional_capabilities_display', true, $profile_user );
 903                      ?>
 904  
 905                  <?php if ( count( $profile_user->caps ) > count( $profile_user->roles ) && ( true === $display_additional_caps ) ) : ?>
 906                      <h2><?php _e( 'Additional Capabilities' ); ?></h2>
 907  
 908                      <table class="form-table" role="presentation">
 909                          <tr class="user-capabilities-wrap">
 910                              <th scope="row"><?php _e( 'Capabilities' ); ?></th>
 911                              <td>
 912                                  <?php
 913                                  $output = '';
 914                                  foreach ( $profile_user->caps as $cap => $value ) {
 915                                      if ( ! $wp_roles->is_role( $cap ) ) {
 916                                          if ( '' !== $output ) {
 917                                              $output .= ', ';
 918                                          }
 919  
 920                                          if ( $value ) {
 921                                              $output .= $cap;
 922                                          } else {
 923                                              /* translators: %s: Capability name. */
 924                                              $output .= sprintf( __( 'Denied: %s' ), $cap );
 925                                          }
 926                                      }
 927                                  }
 928                                  echo $output;
 929                                  ?>
 930                              </td>
 931                          </tr>
 932                      </table>
 933                  <?php endif; // End Display Additional Capabilities. ?>
 934  
 935                  <input type="hidden" name="action" value="update" />
 936                  <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $user_id ); ?>" />
 937  
 938                  <?php submit_button( IS_PROFILE_PAGE ? __( 'Update Profile' ) : __( 'Update User' ) ); ?>
 939  
 940              </form>
 941          </div>
 942          <?php
 943          break;
 944  }
 945  ?>
 946  <script type="text/javascript">
 947      if (window.location.hash == '#password') {
 948          document.getElementById('pass1').focus();
 949      }
 950  </script>
 951  
 952  <script type="text/javascript">
 953      jQuery( function( $ ) {
 954          var languageSelect = $( '#locale' );
 955          $( 'form' ).on( 'submit', function() {
 956              /*
 957               * Don't show a spinner for English and installed languages,
 958               * as there is nothing to download.
 959               */
 960              if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
 961                  $( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
 962              }
 963          });
 964      } );
 965  </script>
 966  
 967  <?php if ( isset( $application_passwords_list_table ) ) : ?>
 968      <script type="text/html" id="tmpl-new-application-password">
 969          <div class="notice notice-success is-dismissible new-application-password-notice" role="alert">
 970              <p class="application-password-display">
 971                  <label for="new-application-password-value">
 972                      <?php
 973                      printf(
 974                          /* translators: %s: Application name. */
 975                          __( 'Your new password for %s is:' ),
 976                          '<strong>{{ data.name }}</strong>'
 977                      );
 978                      ?>
 979                  </label>
 980                  <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="{{ data.password }}" />
 981              </p>
 982              <p><?php _e( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ); ?></p>
 983              <button type="button" class="notice-dismiss">
 984                  <span class="screen-reader-text">
 985                      <?php
 986                      /* translators: Hidden accessibility text. */
 987                      _e( 'Dismiss this notice.' );
 988                      ?>
 989                  </span>
 990              </button>
 991          </div>
 992      </script>
 993  
 994      <script type="text/html" id="tmpl-application-password-row">
 995          <?php $application_passwords_list_table->print_js_template_row(); ?>
 996      </script>
 997  <?php endif; ?>
 998  <?php
 999  require_once  ABSPATH . 'wp-admin/admin-footer.php';


Generated : Thu May 9 08:20:02 2024 Cross-referenced by PHPXref