* Edit user administration panel.
* @subpackage Administration
/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';
/** WordPress Translation Installation API */
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
$action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
$user_id = ! empty( $_REQUEST['user_id'] ) ? absint( $_REQUEST['user_id'] ) : 0;
$wp_http_referer = ! empty( $_REQUEST['wp_http_referer'] ) ? sanitize_url( $_REQUEST['wp_http_referer'] ) : '';
$current_user = wp_get_current_user();
if ( ! defined( 'IS_PROFILE_PAGE' ) ) {
define( 'IS_PROFILE_PAGE', ( $user_id === $current_user->ID ) );
if ( ! $user_id && IS_PROFILE_PAGE ) {
$user_id = $current_user->ID;
} elseif ( ! $user_id && ! IS_PROFILE_PAGE ) {
wp_die( __( 'Invalid user ID.' ) );
} elseif ( ! get_userdata( $user_id ) ) {
wp_die( __( 'Invalid user ID.' ) );
wp_enqueue_script( 'user-profile' );
if ( wp_is_application_passwords_available_for_user( $user_id ) ) {
wp_enqueue_script( 'application-passwords' );
// Used in the HTML title tag.
$title = __( 'Profile' );
// Used in the HTML title tag.
/* translators: %s: User's display name. */
$title = __( 'Edit User %s' );
if ( current_user_can( 'edit_users' ) && ! IS_PROFILE_PAGE ) {
$submenu_file = 'users.php';
$submenu_file = 'profile.php';
if ( current_user_can( 'edit_users' ) && ! is_user_admin() ) {
$parent_file = 'users.php';
$parent_file = 'profile.php';
$profile_help = '<p>' . __( 'Your profile contains information about you (your “account”) as well as some personal options related to using WordPress.' ) . '</p>' .
'<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>' .
'<p>' . __( 'You can select the language you wish to use while using the WordPress administration screen without affecting the language site visitors see.' ) . '</p>' .
'<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>' .
'<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>' .
'<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>' .
'<p>' . __( 'Remember to click the Update Profile button when you are finished.' ) . '</p>';
get_current_screen()->add_help_tab(
'title' => __( 'Overview' ),
'content' => $profile_help,
get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
'<p>' . __( '<a href="https://wordpress.org/documentation/article/users-your-profile-screen/">Documentation on User Profiles</a>' ) . '</p>' .
'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
$wp_http_referer = remove_query_arg( array( 'update', 'delete_count', 'user_id' ), $wp_http_referer );
$user_can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' );
* Filters whether to allow administrators on Multisite to edit every user.
* Enabling the user editing form via this filter also hinges on the user holding
* the 'manage_network_users' cap, and the logged-in user not matching the user
* profile open for editing.
* The filter was introduced to replace the EDIT_ANY_USER constant.
* @param bool $allow Whether to allow editing of any user. Default true.
&& ! current_user_can( 'manage_network_users' )
&& $user_id !== $current_user->ID
&& ! apply_filters( 'enable_edit_any_user_configuration', true )
wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
// Execute confirmed email change. See send_confirmation_on_profile_email().
if ( IS_PROFILE_PAGE && isset( $_GET['newuseremail'] ) && $current_user->ID ) {
$new_email = get_user_meta( $current_user->ID, '_new_email', true );
if ( $new_email && hash_equals( $new_email['hash'], $_GET['newuseremail'] ) ) {
$user->ID = $current_user->ID;
$user->user_email = esc_html( trim( $new_email['newemail'] ) );
if ( is_multisite() && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) {
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) );
delete_user_meta( $current_user->ID, '_new_email' );
wp_redirect( add_query_arg( array( 'updated' => 'true' ), self_admin_url( 'profile.php' ) ) );
wp_redirect( add_query_arg( array( 'error' => 'new-email' ), self_admin_url( 'profile.php' ) ) );
} elseif ( IS_PROFILE_PAGE && ! empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' === $_GET['dismiss'] ) {
check_admin_referer( 'dismiss-' . $current_user->ID . '_new_email' );
delete_user_meta( $current_user->ID, '_new_email' );
wp_redirect( add_query_arg( array( 'updated' => 'true' ), self_admin_url( 'profile.php' ) ) );
check_admin_referer( 'update-user_' . $user_id );
if ( ! current_user_can( 'edit_user', $user_id ) ) {
wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
* Fires before the page loads on the 'Profile' editing screen.
* The action only fires if the current user is editing their own profile.
* @param int $user_id The user ID.
do_action( 'personal_options_update', $user_id );
* Fires before the page loads on the 'Edit User' screen.
* @param int $user_id The user ID.
do_action( 'edit_user_profile_update', $user_id );
// Update the email address in signups, if present.
$user = get_userdata( $user_id );
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 ) ) ) {
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email'], $user_login ) );
$errors = edit_user( $user_id );
// Grant or revoke super admin status if requested.
if ( is_multisite() && is_network_admin()
&& ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' )
&& ! isset( $super_admins ) && empty( $_POST['super_admin'] ) === is_super_admin( $user_id )
empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
if ( ! is_wp_error( $errors ) ) {
$redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) );
if ( $wp_http_referer ) {
$redirect = add_query_arg( 'wp_http_referer', urlencode( $wp_http_referer ), $redirect );
wp_redirect( $redirect );
// Intentional fall-through to display $errors.
$profile_user = get_user_to_edit( $user_id );
if ( ! current_user_can( 'edit_user', $user_id ) ) {
wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
$title = sprintf( $title, $profile_user->display_name );
$sessions = WP_Session_Tokens::get_instance( $profile_user->ID );
require_once ABSPATH . 'wp-admin/admin-header.php';
if ( ! IS_PROFILE_PAGE && is_super_admin( $profile_user->ID ) && current_user_can( 'manage_network_options' ) ) :
$message = '<strong>' . __( 'Important:' ) . '</strong> ' . __( 'This user has super admin privileges.' );
if ( isset( $_GET['updated'] ) ) :
$message = '<p><strong>' . __( 'Profile updated.' ) . '</strong></p>';
$message = '<p><strong>' . __( 'User updated.' ) . '</strong></p>';
if ( $wp_http_referer && ! str_contains( $wp_http_referer, 'user-new.php' ) && ! IS_PROFILE_PAGE ) :
'<p><a href="%1$s">%2$s</a></p>',
esc_url( wp_validate_redirect( sanitize_url( $wp_http_referer ), self_admin_url( 'users.php' ) ) ),
__( '← Go to Users' )
'additional_classes' => array( 'updated' ),
'paragraph_wrap' => false,
if ( isset( $_GET['error'] ) ) :
if ( 'new-email' === $_GET['error'] ) :
$message = __( 'Error while saving the new email address. Please try again.' );
if ( isset( $errors ) && is_wp_error( $errors ) ) {
implode( "</p>\n<p>", $errors->get_error_messages() ),
'additional_classes' => array( 'error' ),
<div class="wrap" id="profile-page">
<h1 class="wp-heading-inline">
<?php echo esc_html( $title ); ?>
<?php if ( ! IS_PROFILE_PAGE ) : ?>
<?php if ( current_user_can( 'create_users' ) ) : ?>
<a href="user-new.php" class="page-title-action"><?php echo esc_html__( 'Add User' ); ?></a>
<?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
<a href="user-new.php" class="page-title-action"><?php echo esc_html__( 'Add Existing User' ); ?></a>
<hr class="wp-header-end">
<form id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post" novalidate="novalidate"
* Fires inside the your-profile form tag on the user editing screen.
do_action( 'user_edit_form_tag' );
<?php wp_nonce_field( 'update-user_' . $user_id ); ?>
<?php if ( $wp_http_referer ) : ?>
<input type="hidden" name="wp_http_referer" value="<?php echo esc_url( $wp_http_referer ); ?>" />
<input type="hidden" name="from" value="profile" />
<input type="hidden" name="checkuser_id" value="<?php echo get_current_user_id(); ?>" />
<h2><?php _e( 'Personal Options' ); ?></h2>
<table class="form-table" role="presentation">
<?php if ( ! ( IS_PROFILE_PAGE && ! $user_can_edit ) && 'false' === $profile_user->rich_editing ) : ?>
<tr class="user-rich-editing-wrap">
<th scope="row"><?php _e( 'Visual Editor' ); ?></th>
<label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="false" <?php checked( 'false', $profile_user->rich_editing ); ?> />
<?php _e( 'Disable the visual editor when writing' ); ?>
$show_syntax_highlighting_preference = (
// For Custom HTML widget and Additional CSS in Customizer.
user_can( $profile_user, 'edit_theme_options' )
user_can( $profile_user, 'edit_plugins' )
user_can( $profile_user, 'edit_themes' )
<?php if ( $show_syntax_highlighting_preference ) : ?>
<tr class="user-syntax-highlighting-wrap">
<th scope="row"><?php _e( 'Syntax Highlighting' ); ?></th>
<label for="syntax_highlighting"><input name="syntax_highlighting" type="checkbox" id="syntax_highlighting" value="false" <?php checked( 'false', $profile_user->syntax_highlighting ); ?> />
<?php _e( 'Disable syntax highlighting when editing code' ); ?>
<?php if ( count( $_wp_admin_css_colors ) > 1 && has_action( 'admin_color_scheme_picker' ) ) : ?>
<tr class="user-admin-color-wrap">
<th scope="row"><?php _e( 'Administration Color Scheme' ); ?></th>
* Fires in the 'Administration Color Scheme' section of the user editing screen.
* The section is only enabled if a callback is hooked to the action,
* and if there is more than one defined color scheme for the admin.
* @since 3.8.1 Added `$user_id` parameter.
* @param int $user_id The user ID.
do_action( 'admin_color_scheme_picker', $user_id );
<?php endif; // End if count ( $_wp_admin_css_colors ) > 1 ?>
<?php if ( ! ( IS_PROFILE_PAGE && ! $user_can_edit ) ) : ?>
<tr class="user-comment-shortcuts-wrap">
<th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th>
<label for="comment_shortcuts">
<input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php checked( 'true', $profile_user->comment_shortcuts ); ?> />
<?php _e( 'Enable keyboard shortcuts for comment moderation.' ); ?>
<?php _e( '<a href="https://wordpress.org/documentation/article/keyboard-shortcuts-classic-editor/#keyboard-shortcuts-for-comments">Documentation on Keyboard Shortcuts</a>' ); ?>
<tr class="show-admin-bar user-admin-bar-front-wrap">
<th scope="row"><?php _e( 'Toolbar' ); ?></th>
<label for="admin_bar_front">
<input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="1"<?php checked( _get_admin_bar_pref( 'front', $profile_user->ID ) ); ?> />
<?php _e( 'Show Toolbar when viewing site' ); ?>
$languages = get_available_languages();
$can_install_translations = current_user_can( 'install_languages' ) && wp_can_install_language_pack();
<?php if ( $languages || $can_install_translations ) : ?>
<tr class="user-language-wrap">
<?php /* translators: The user language selection field label. */ ?>
<label for="locale"><?php _e( 'Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span></label>
$user_locale = $profile_user->locale;
if ( 'en_US' === $user_locale ) {
} elseif ( '' === $user_locale || ! in_array( $user_locale, $languages, true ) ) {
$user_locale = 'site-default';
'selected' => $user_locale,
'languages' => $languages,
'show_available_translations' => $can_install_translations,
'show_option_site_default' => true,
* Fires at the end of the 'Personal Options' settings table on the user editing screen.
* @param WP_User $profile_user The current WP_User object.
do_action( 'personal_options', $profile_user );
* Fires after the 'Personal Options' settings table on the 'Profile' editing screen.
* The action only fires if the current user is editing their own profile.
* @param WP_User $profile_user The current WP_User object.
do_action( 'profile_personal_options', $profile_user );
<h2><?php _e( 'Name' ); ?></h2>
<table class="form-table" role="presentation">
<tr class="user-user-login-wrap">
<th><label for="user_login"><?php _e( 'Username' ); ?></label></th>
<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>
<?php if ( ! IS_PROFILE_PAGE && ! is_network_admin() && current_user_can( 'promote_user', $profile_user->ID ) ) : ?>
<tr class="user-role-wrap">
<th><label for="role"><?php _e( 'Role' ); ?></label></th>
<select name="role" id="role">
// Compare user role against currently editable roles.
$user_roles = array_intersect( array_values( $profile_user->roles ), array_keys( get_editable_roles() ) );
$user_role = reset( $user_roles );
// Print the full list of roles with the primary one selected.
wp_dropdown_roles( $user_role );
// Print the 'no role' option. Make it selected if the user has no role yet.
echo '<option value="">' . __( '— No role for this site —' ) . '</option>';
echo '<option value="" selected="selected">' . __( '— No role for this site —' ) . '</option>';
<?php endif; // End if ! IS_PROFILE_PAGE. ?>
<?php if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && ! isset( $super_admins ) ) : ?>
<tr class="user-super-admin-wrap">
<th><?php _e( 'Super Admin' ); ?></th>
<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>
<tr class="user-first-name-wrap">
<th><label for="first_name"><?php _e( 'First Name' ); ?></label></th>
<?php if ( IS_PROFILE_PAGE ) : ?>
<input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profile_user->first_name ); ?>" autocomplete="given-name" class="regular-text" />
<input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profile_user->first_name ); ?>" class="regular-text" />
<tr class="user-last-name-wrap">
<th><label for="last_name"><?php _e( 'Last Name' ); ?></label></th>
<?php if ( IS_PROFILE_PAGE ) : ?>
<input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profile_user->last_name ); ?>" autocomplete="family-name" class="regular-text" />
<input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profile_user->last_name ); ?>" class="regular-text" />