Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/user-edit.php

    r42217 r42343  
    1212wp_reset_vars( array( 'action', 'user_id', 'wp_http_referer' ) );
    1313
    14 $user_id = (int) $user_id;
     14$user_id      = (int) $user_id;
    1515$current_user = wp_get_current_user();
    16 if ( ! defined( 'IS_PROFILE_PAGE' ) )
     16if ( ! defined( 'IS_PROFILE_PAGE' ) ) {
    1717        define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) );
    18 
    19 if ( ! $user_id && IS_PROFILE_PAGE )
     18}
     19
     20if ( ! $user_id && IS_PROFILE_PAGE ) {
    2021        $user_id = $current_user->ID;
    21 elseif ( ! $user_id && ! IS_PROFILE_PAGE )
    22         wp_die(__( 'Invalid user ID.' ) );
    23 elseif ( ! get_userdata( $user_id ) )
    24         wp_die( __('Invalid user ID.') );
    25 
    26 wp_enqueue_script('user-profile');
     22} elseif ( ! $user_id && ! IS_PROFILE_PAGE ) {
     23        wp_die( __( 'Invalid user ID.' ) );
     24} elseif ( ! get_userdata( $user_id ) ) {
     25        wp_die( __( 'Invalid user ID.' ) );
     26}
     27
     28wp_enqueue_script( 'user-profile' );
    2729
    2830if ( IS_PROFILE_PAGE ) {
    … …  
    3335}
    3436
    35 if ( current_user_can('edit_users') && !IS_PROFILE_PAGE )
     37if ( current_user_can( 'edit_users' ) && ! IS_PROFILE_PAGE ) {
    3638        $submenu_file = 'users.php';
    37 else
     39} else {
    3840        $submenu_file = 'profile.php';
    39 
    40 if ( current_user_can('edit_users') && !is_user_admin() )
     41}
     42
     43if ( current_user_can( 'edit_users' ) && ! is_user_admin() ) {
    4144        $parent_file = 'users.php';
    42 else
     45} else {
    4346        $parent_file = 'profile.php';
    44 
    45 $profile_help = '<p>' . __('Your profile contains information about you (your &#8220;account&#8221;) as well as some personal options related to using WordPress.') . '</p>' .
    46         '<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>' .
     47}
     48
     49$profile_help = '<p>' . __( 'Your profile contains information about you (your &#8220;account&#8221;) as well as some personal options related to using WordPress.' ) . '</p>' .
     50        '<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>' .
    4751        '<p>' . __( 'You can select the language you wish to use while using the WordPress administration screen without affecting the language site visitors see.' ) . '</p>' .
    48         '<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>' .
     52        '<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>' .
    4953        '<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>' .
    50         '<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>' .
    51         '<p>' . __('Remember to click the Update Profile button when you are finished.') . '</p>';
    52 
    53 get_current_screen()->add_help_tab( array(
    54         'id'      => 'overview',
    55         'title'   => __('Overview'),
    56         'content' => $profile_help,
    57 ) );
     54        '<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>' .
     55        '<p>' . __( 'Remember to click the Update Profile button when you are finished.' ) . '</p>';
     56
     57get_current_screen()->add_help_tab(
     58        array(
     59                'id'      => 'overview',
     60                'title'   => __( 'Overview' ),
     61                'content' => $profile_help,
     62        )
     63);
    5864
    5965get_current_screen()->set_help_sidebar(
    60     '<p><strong>' . __('For more information:') . '</strong></p>' .
    61     '<p>' . __('<a href="https://codex.wordpress.org/Users_Your_Profile_Screen">Documentation on User Profiles</a>') . '</p>' .
    62     '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
     66        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     67        '<p>' . __( '<a href="https://codex.wordpress.org/Users_Your_Profile_Screen">Documentation on User Profiles</a>' ) . '</p>' .
     68        '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    6369);
    6470
    … …  
    8995
    9096// Execute confirmed email change. See send_confirmation_on_profile_email().
    91 if ( IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) {
     97if ( IS_PROFILE_PAGE && isset( $_GET['newuseremail'] ) && $current_user->ID ) {
    9298        $new_email = get_user_meta( $current_user->ID, '_new_email', true );
    93         if ( $new_email && hash_equals( $new_email[ 'hash' ], $_GET[ 'newuseremail' ] ) ) {
    94                 $user = new stdClass;
    95                 $user->ID = $current_user->ID;
    96                 $user->user_email = esc_html( trim( $new_email[ 'newemail' ] ) );
     99        if ( $new_email && hash_equals( $new_email['hash'], $_GET['newuseremail'] ) ) {
     100                $user             = new stdClass;
     101                $user->ID         = $current_user->ID;
     102                $user->user_email = esc_html( trim( $new_email['newemail'] ) );
    97103                if ( is_multisite() && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) {
    98104                        $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) );
    … …  
    108114        check_admin_referer( 'dismiss-' . $current_user->ID . '_new_email' );
    109115        delete_user_meta( $current_user->ID, '_new_email' );
    110         wp_redirect( add_query_arg( array('updated' => 'true'), self_admin_url( 'profile.php' ) ) );
     116        wp_redirect( add_query_arg( array( 'updated' => 'true' ), self_admin_url( 'profile.php' ) ) );
    111117        die();
    112118}
    113119
    114 switch ($action) {
    115 case 'update':
    116 
    117 check_admin_referer('update-user_' . $user_id);
    118 
    119 if ( !current_user_can('edit_user', $user_id) )
    120         wp_die(__('Sorry, you are not allowed to edit this user.'));
    121 
    122 if ( IS_PROFILE_PAGE ) {
    123         /**
    124          * Fires before the page loads on the 'Your Profile' editing screen.
    125          *
    126          * The action only fires if the current user is editing their own profile.
    127          *
    128          * @since 2.0.0
    129          *
    130          * @param int $user_id The user ID.
    131          */
    132         do_action( 'personal_options_update', $user_id );
    133 } else {
    134         /**
    135          * Fires before the page loads on the 'Edit User' screen.
    136          *
    137          * @since 2.7.0
    138          *
    139          * @param int $user_id The user ID.
    140          */
    141         do_action( 'edit_user_profile_update', $user_id );
    142 }
    143 
    144 // Update the email address in signups, if present.
    145 if ( is_multisite() ) {
    146         $user = get_userdata( $user_id );
    147 
    148         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 ) ) ) {
    149                 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST[ 'email' ], $user_login ) );
    150         }
    151 }
    152 
    153 // Update the user.
    154 $errors = edit_user( $user_id );
    155 
    156 // Grant or revoke super admin status if requested.
    157 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 ) ) {
    158         empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
    159 }
    160 
    161 if ( !is_wp_error( $errors ) ) {
    162         $redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) );
    163         if ( $wp_http_referer )
    164                 $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect);
    165         wp_redirect($redirect);
    166         exit;
    167 }
    168 
    169 default:
    170 $profileuser = get_user_to_edit($user_id);
    171 
    172 if ( !current_user_can('edit_user', $user_id) )
    173         wp_die(__('Sorry, you are not allowed to edit this user.'));
    174 
    175 $title = sprintf( $title, $profileuser->display_name );
    176 $sessions = WP_Session_Tokens::get_instance( $profileuser->ID );
    177 
    178 include(ABSPATH . 'wp-admin/admin-header.php');
    179 ?>
    180 
    181 <?php if ( !IS_PROFILE_PAGE && is_super_admin( $profileuser->ID ) && current_user_can( 'manage_network_options' ) ) { ?>
    182         <div class="notice notice-info"><p><strong><?php _e('Important:'); ?></strong> <?php _e('This user has super admin privileges.'); ?></p></div>
     120switch ( $action ) {
     121        case 'update':
     122                check_admin_referer( 'update-user_' . $user_id );
     123
     124                if ( ! current_user_can( 'edit_user', $user_id ) ) {
     125                        wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
     126                }
     127
     128                if ( IS_PROFILE_PAGE ) {
     129                        /**
     130                         * Fires before the page loads on the 'Your Profile' editing screen.
     131                         *
     132                         * The action only fires if the current user is editing their own profile.
     133                         *
     134                         * @since 2.0.0
     135                         *
     136                         * @param int $user_id The user ID.
     137                         */
     138                        do_action( 'personal_options_update', $user_id );
     139                } else {
     140                        /**
     141                         * Fires before the page loads on the 'Edit User' screen.
     142                         *
     143                         * @since 2.7.0
     144                         *
     145                         * @param int $user_id The user ID.
     146                         */
     147                        do_action( 'edit_user_profile_update', $user_id );
     148                }
     149
     150                // Update the email address in signups, if present.
     151                if ( is_multisite() ) {
     152                        $user = get_userdata( $user_id );
     153
     154                        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 ) ) ) {
     155                                $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email'], $user_login ) );
     156                        }
     157                }
     158
     159                // Update the user.
     160                $errors = edit_user( $user_id );
     161
     162                // Grant or revoke super admin status if requested.
     163                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 ) ) {
     164                        empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
     165                }
     166
     167                if ( ! is_wp_error( $errors ) ) {
     168                        $redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) );
     169                        if ( $wp_http_referer ) {
     170                                $redirect = add_query_arg( 'wp_http_referer', urlencode( $wp_http_referer ), $redirect );
     171                        }
     172                        wp_redirect( $redirect );
     173                        exit;
     174                }
     175
     176        default:
     177                $profileuser = get_user_to_edit( $user_id );
     178
     179                if ( ! current_user_can( 'edit_user', $user_id ) ) {
     180                        wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
     181                }
     182
     183                $title    = sprintf( $title, $profileuser->display_name );
     184                $sessions = WP_Session_Tokens::get_instance( $profileuser->ID );
     185
     186                include( ABSPATH . 'wp-admin/admin-header.php' );
     187        ?>
     188
     189        <?php if ( ! IS_PROFILE_PAGE && is_super_admin( $profileuser->ID ) && current_user_can( 'manage_network_options' ) ) { ?>
     190        <div class="notice notice-info"><p><strong><?php _e( 'Important:' ); ?></strong> <?php _e( 'This user has super admin privileges.' ); ?></p></div>
    183191<?php } ?>
    184 <?php if ( isset($_GET['updated']) ) : ?>
     192<?php if ( isset( $_GET['updated'] ) ) : ?>
    185193<div id="message" class="updated notice is-dismissible">
    186194        <?php if ( IS_PROFILE_PAGE ) : ?>
    187         <p><strong><?php _e('Profile updated.') ?></strong></p>
    188         <?php else: ?>
    189         <p><strong><?php _e('User updated.') ?></strong></p>
     195        <p><strong><?php _e( 'Profile updated.' ); ?></strong></p>
     196        <?php else : ?>
     197        <p><strong><?php _e( 'User updated.' ); ?></strong></p>
    190198        <?php endif; ?>
    191199        <?php if ( $wp_http_referer && false === strpos( $wp_http_referer, 'user-new.php' ) && ! IS_PROFILE_PAGE ) : ?>
    192         <p><a href="<?php echo esc_url( wp_validate_redirect( esc_url_raw( $wp_http_referer ), self_admin_url( 'users.php' ) ) ); ?>"><?php _e('&larr; Back to Users'); ?></a></p>
     200        <p><a href="<?php echo esc_url( wp_validate_redirect( esc_url_raw( $wp_http_referer ), self_admin_url( 'users.php' ) ) ); ?>"><?php _e( '&larr; Back to Users' ); ?></a></p>
    193201        <?php endif; ?>
    194202</div>
    … …  
    206214
    207215<div class="wrap" id="profile-page">
    208 <h1 class="wp-heading-inline"><?php
     216<h1 class="wp-heading-inline">
     217<?php
    209218echo esc_html( $title );
    210 ?></h1>
     219?>
     220</h1>
    211221
    212222<?php
    213223if ( ! IS_PROFILE_PAGE ) {
    214         if ( current_user_can( 'create_users' ) ) { ?>
     224        if ( current_user_can( 'create_users' ) ) {
     225        ?>
    215226                <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
    216227        <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
    217228                <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
    218         <?php }
     229        <?php
     230}
    219231}
    220232?>
    … …  
    222234<hr class="wp-header-end">
    223235
    224 <form id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post" novalidate="novalidate"<?php
    225         /**
    226          * Fires inside the your-profile form tag on the user editing screen.
    227          *
    228          * @since 3.0.0
    229          */
    230         do_action( 'user_edit_form_tag' );
    231 ?>>
    232 <?php wp_nonce_field('update-user_' . $user_id) ?>
     236<form id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post" novalidate="novalidate"
     237                                                                                        <?php
     238                                                                                        /**
     239                                                                                         * Fires inside the your-profile form tag on the user editing screen.
     240                                                                                         *
     241                                                                                         * @since 3.0.0
     242                                                                                         */
     243                                                                                        do_action( 'user_edit_form_tag' );
     244        ?>
     245        >
     246        <?php wp_nonce_field( 'update-user_' . $user_id ); ?>
    233247<?php if ( $wp_http_referer ) : ?>
    234         <input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?>" />
     248        <input type="hidden" name="wp_http_referer" value="<?php echo esc_url( $wp_http_referer ); ?>" />
    235249<?php endif; ?>
    236250<p>
    … …  
    258272        // Edit themes.
    259273        user_can( $profileuser, 'edit_themes' )
    260 );
    261 ?>
    262 <?php if ( $show_syntax_highlighting_preference ) : ?>
     274        );
     275        ?>
     276        <?php if ( $show_syntax_highlighting_preference ) : ?>
    263277        <tr class="user-syntax-highlighting-wrap">
    264278                <th scope="row"><?php _e( 'Syntax Highlighting' ); ?></th>
    … …  
    268282        </tr>
    269283<?php endif; ?>
    270 <?php if ( count($_wp_admin_css_colors) > 1 && has_action('admin_color_scheme_picker') ) : ?>
     284<?php if ( count( $_wp_admin_css_colors ) > 1 && has_action( 'admin_color_scheme_picker' ) ) : ?>
    271285<tr class="user-admin-color-wrap">
    272 <th scope="row"><?php _e('Admin Color Scheme')?></th>
    273 <td><?php
     286<th scope="row"><?php _e( 'Admin Color Scheme' ); ?></th>
     287<td>
     288<?php
    274289        /**
    275290         * Fires in the 'Admin Color Scheme' section of the user editing screen.
    … …  
    284299         */
    285300        do_action( 'admin_color_scheme_picker', $user_id );
    286 ?></td>
     301?>
     302</td>
    287303</tr>
    288304<?php
    289305endif; // $_wp_admin_css_colors
    290 if ( !( IS_PROFILE_PAGE && !$user_can_edit ) ) : ?>
     306if ( ! ( IS_PROFILE_PAGE && ! $user_can_edit ) ) :
     307?>
    291308<tr class="user-comment-shortcuts-wrap">
    292309<th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th>
    293 <td><label for="comment_shortcuts"><input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php checked( 'true', $profileuser->comment_shortcuts ); ?> /> <?php _e('Enable keyboard shortcuts for comment moderation.'); ?></label> <?php _e('<a href="https://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">More information</a>'); ?></td>
     310<td><label for="comment_shortcuts"><input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php checked( 'true', $profileuser->comment_shortcuts ); ?> /> <?php _e( 'Enable keyboard shortcuts for comment moderation.' ); ?></label> <?php _e( '<a href="https://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">More information</a>' ); ?></td>
    294311</tr>
    295312<?php endif; ?>
    296313<tr class="show-admin-bar user-admin-bar-front-wrap">
    297314<th scope="row"><?php _e( 'Toolbar' ); ?></th>
    298 <td><fieldset><legend class="screen-reader-text"><span><?php _e('Toolbar') ?></span></legend>
     315<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Toolbar' ); ?></span></legend>
    299316<label for="admin_bar_front">
    300317<input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="1"<?php checked( _get_admin_bar_pref( 'front', $profileuser->ID ) ); ?> />
    … …  
    306323<?php
    307324$languages = get_available_languages();
    308 if ( $languages ) : ?>
     325if ( $languages ) :
     326?>
    309327<tr class="user-language-wrap">
    310328        <th scope="row">
    … …  
    322340                }
    323341
    324                 wp_dropdown_languages( array(
    325                         'name'                        => 'locale',
    326                         'id'                          => 'locale',
    327                         'selected'                    => $user_locale,
    328                         'languages'                   => $languages,
    329                         'show_available_translations' => false,
    330                         'show_option_site_default'    => true
    331                 ) );
     342                wp_dropdown_languages(
     343                        array(
     344                                'name'                        => 'locale',
     345                                'id'                          => 'locale',
     346                                'selected'                    => $user_locale,
     347                                'languages'                   => $languages,
     348                                'show_available_translations' => false,
     349                                'show_option_site_default'    => true,
     350                        )
     351                );
    332352                ?>
    333353        </td>
    … …  
    350370</table>
    351371<?php
    352         if ( IS_PROFILE_PAGE ) {
    353                 /**
    354                 * Fires after the 'Personal Options' settings table on the 'Your Profile' editing screen.
    355                 *
    356                 * The action only fires if the current user is editing their own profile.
    357                 *
    358                 * @since 2.0.0
    359                 *
    360                 * @param WP_User $profileuser The current WP_User object.
    361                 */
    362                 do_action( 'profile_personal_options', $profileuser );
    363         }
     372if ( IS_PROFILE_PAGE ) {
     373        /**
     374        * Fires after the 'Personal Options' settings table on the 'Your Profile' editing screen.
     375        *
     376        * The action only fires if the current user is editing their own profile.
     377        *
     378        * @since 2.0.0
     379        *
     380        * @param WP_User $profileuser The current WP_User object.
     381        */
     382        do_action( 'profile_personal_options', $profileuser );
     383}
    364384?>
    365385
    … …  
    368388<table class="form-table">
    369389        <tr class="user-user-login-wrap">
    370                 <th><label for="user_login"><?php _e('Username'); ?></label></th>
    371                 <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr($profileuser->user_login); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e('Usernames cannot be changed.'); ?></span></td>
    372         </tr>
    373 
    374 <?php if ( !IS_PROFILE_PAGE && !is_network_admin() ) : ?>
    375 <tr class="user-role-wrap"><th><label for="role"><?php _e('Role') ?></label></th>
     390                <th><label for="user_login"><?php _e( 'Username' ); ?></label></th>
     391                <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr( $profileuser->user_login ); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e( 'Usernames cannot be changed.' ); ?></span></td>
     392        </tr>
     393
     394<?php if ( ! IS_PROFILE_PAGE && ! is_network_admin() ) : ?>
     395<tr class="user-role-wrap"><th><label for="role"><?php _e( 'Role' ); ?></label></th>
    376396<td><select name="role" id="role">
    377397<?php
    … …  
    381401
    382402// print the full list of roles with the primary one selected.
    383 wp_dropdown_roles($user_role);
     403wp_dropdown_roles( $user_role );
    384404
    385405// print the 'no role' option. Make it selected if the user has no role yet.
    386 if ( $user_role )
    387         echo '<option value="">' . __('&mdash; No role for this site &mdash;') . '</option>';
    388 else
    389         echo '<option value="" selected="selected">' . __('&mdash; No role for this site &mdash;') . '</option>';
     406if ( $user_role ) {
     407        echo '<option value="">' . __( '&mdash; No role for this site &mdash;' ) . '</option>';
     408} else {
     409        echo '<option value="" selected="selected">' . __( '&mdash; No role for this site &mdash;' ) . '</option>';
     410}
    390411?>
    391412</select></td></tr>
    392 <?php endif; //!IS_PROFILE_PAGE
    393 
    394 if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) ) { ?>
    395 <tr class="user-super-admin-wrap"><th><?php _e('Super Admin'); ?></th>
     413<?php
     414endif; //!IS_PROFILE_PAGE
     415
     416if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && ! isset( $super_admins ) ) {
     417?>
     418<tr class="user-super-admin-wrap"><th><?php _e( 'Super Admin' ); ?></th>
    396419<td>
    397420<?php if ( $profileuser->user_email != get_site_option( 'admin_email' ) || ! is_super_admin( $profileuser->ID ) ) : ?>
    … …  
    404427
    405428<tr class="user-first-name-wrap">
    406         <th><label for="first_name"><?php _e('First Name') ?></label></th>
    407         <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr($profileuser->first_name) ?>" class="regular-text" /></td>
     429        <th><label for="first_name"><?php _e( 'First Name' ); ?></label></th>
     430        <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profileuser->first_name ); ?>" class="regular-text" /></td>
    408431</tr>
    409432
    410433<tr class="user-last-name-wrap">
    411         <th><label for="last_name"><?php _e('Last Name') ?></label></th>
    412         <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr($profileuser->last_name) ?>" class="regular-text" /></td>
     434        <th><label for="last_name"><?php _e( 'Last Name' ); ?></label></th>
     435        <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profileuser->last_name ); ?>" class="regular-text" /></td>
    413436</tr>
    414437
    415438<tr class="user-nickname-wrap">
    416         <th><label for="nickname"><?php _e('Nickname'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
    417         <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr($profileuser->nickname) ?>" class="regular-text" /></td>
     439        <th><label for="nickname"><?php _e( 'Nickname' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
     440        <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( $profileuser->nickname ); ?>" class="regular-text" /></td>
    418441</tr>
    419442
    420443<tr class="user-display-name-wrap">
    421         <th><label for="display_name"><?php _e('Display name publicly as') ?></label></th>
     444        <th><label for="display_name"><?php _e( 'Display name publicly as' ); ?></label></th>
    422445        <td>
    423446                <select name="display_name" id="display_name">
    424447                <?php
    425                         $public_display = array();
    426                         $public_display['display_nickname']  = $profileuser->nickname;
    427                         $public_display['display_username']  = $profileuser->user_login;
    428 
    429                         if ( !empty($profileuser->first_name) )
    430                                 $public_display['display_firstname'] = $profileuser->first_name;
    431 
    432                         if ( !empty($profileuser->last_name) )
    433                                 $public_display['display_lastname'] = $profileuser->last_name;
    434 
    435                         if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
    436                                 $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
    437                                 $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
    438                         }
    439 
    440                         if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
    441                                 $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
     448                        $public_display                     = array();
     449                        $public_display['display_nickname'] = $profileuser->nickname;
     450                        $public_display['display_username'] = $profileuser->user_login;
     451
     452                if ( ! empty( $profileuser->first_name ) ) {
     453                        $public_display['display_firstname'] = $profileuser->first_name;
     454                }
     455
     456                if ( ! empty( $profileuser->last_name ) ) {
     457                        $public_display['display_lastname'] = $profileuser->last_name;
     458                }
     459
     460                if ( ! empty( $profileuser->first_name ) && ! empty( $profileuser->last_name ) ) {
     461                        $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
     462                        $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
     463                }
     464
     465                if ( ! in_array( $profileuser->display_name, $public_display ) ) { // Only add this if it isn't duplicated elsewhere
     466                        $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
     467                }
    442468
    443469                        $public_display = array_map( 'trim', $public_display );
    444470                        $public_display = array_unique( $public_display );
    445471
    446                         foreach ( $public_display as $id => $item ) {
     472                foreach ( $public_display as $id => $item ) {
    447473                ?>
    448                         <option <?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>
     474                <option <?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>
    449475                <?php
    450                         }
     476                }
    451477                ?>
    452478                </select>
    453         </td>
    454 </tr>
    455 </table>
    456 
    457 <h2><?php _e( 'Contact Info' ); ?></h2>
    458 
    459 <table class="form-table">
    460 <tr class="user-email-wrap">
    461         <th><label for="email"><?php _e('Email'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
    462         <td><input type="email" name="email" id="email" value="<?php echo esc_attr( $profileuser->user_email ) ?>" class="regular-text ltr" />
    463         <?php
    464         $new_email = get_user_meta( $current_user->ID, '_new_email', true );
    465         if ( $new_email && $new_email['newemail'] != $current_user->user_email && $profileuser->ID == $current_user->ID ) : ?>
    466         <div class="updated inline">
    467         <p><?php
     479                </td>
     480        </tr>
     481        </table>
     482
     483        <h2><?php _e( 'Contact Info' ); ?></h2>
     484
     485        <table class="form-table">
     486        <tr class="user-email-wrap">
     487                <th><label for="email"><?php _e( 'Email' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
     488                <td><input type="email" name="email" id="email" value="<?php echo esc_attr( $profileuser->user_email ); ?>" class="regular-text ltr" />
     489                <?php
     490                $new_email = get_user_meta( $current_user->ID, '_new_email', true );
     491                if ( $new_email && $new_email['newemail'] != $current_user->user_email && $profileuser->ID == $current_user->ID ) :
     492                ?>
     493                <div class="updated inline">
     494                <p>
     495                <?php
    468496                printf(
    469497                        /* translators: %s: new email */
    … …  
    476504                        __( 'Cancel' )
    477505                );
    478         ?></p>
    479         </div>
    480         <?php endif; ?>
     506                ?>
     507                </p>
     508                </div>
     509                <?php endif; ?>
    481510        </td>
    482 </tr>
    483 
    484 <tr class="user-url-wrap">
    485         <th><label for="url"><?php _e('Website') ?></label></th>
    486         <td><input type="url" name="url" id="url" value="<?php echo esc_attr( $profileuser->user_url ) ?>" class="regular-text code" /></td>
    487 </tr>
    488 
    489 <?php
     511        </tr>
     512
     513        <tr class="user-url-wrap">
     514        <th><label for="url"><?php _e( 'Website' ); ?></label></th>
     515        <td><input type="url" name="url" id="url" value="<?php echo esc_attr( $profileuser->user_url ); ?>" class="regular-text code" /></td>
     516        </tr>
     517
     518        <?php
    490519        foreach ( wp_get_user_contact_methods( $profileuser ) as $name => $desc ) {
    491 ?>
    492 <tr class="user-<?php echo $name; ?>-wrap">
    493         <th><label for="<?php echo $name; ?>">
    494                 <?php
    495                 /**
    496                 * Filters a user contactmethod label.
    497                 *
    498                 * The dynamic portion of the filter hook, `$name`, refers to
    499                 * each of the keys in the contactmethods array.
    500                 *
    501                 * @since 2.9.0
    502                 *
    503                 * @param string $desc The translatable label for the contactmethod.
    504                 */
    505                 echo apply_filters( "user_{$name}_label", $desc );
    506                 ?>
     520        ?>
     521        <tr class="user-<?php echo $name; ?>-wrap">
     522<th><label for="<?php echo $name; ?>">
     523        <?php
     524        /**
     525        * Filters a user contactmethod label.
     526        *
     527        * The dynamic portion of the filter hook, `$name`, refers to
     528        * each of the keys in the contactmethods array.
     529        *
     530        * @since 2.9.0
     531        *
     532        * @param string $desc The translatable label for the contactmethod.
     533        */
     534        echo apply_filters( "user_{$name}_label", $desc );
     535        ?>
    507536        </label></th>
    508         <td><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($profileuser->$name) ?>" class="regular-text" /></td>
    509 </tr>
    510 <?php
     537        <td><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $profileuser->$name ); ?>" class="regular-text" /></td>
     538        </tr>
     539        <?php
    511540        }
    512 ?>
    513 </table>
    514 
    515 <h2><?php IS_PROFILE_PAGE ? _e( 'About Yourself' ) : _e( 'About the user' ); ?></h2>
     541        ?>
     542        </table>
     543
     544        <h2><?php IS_PROFILE_PAGE ? _e( 'About Yourself' ) : _e( 'About the user' ); ?></h2>
    516545
    517546<table class="form-table">
    518547<tr class="user-description-wrap">
    519         <th><label for="description"><?php _e('Biographical Info'); ?></label></th>
     548        <th><label for="description"><?php _e( 'Biographical Info' ); ?></label></th>
    520549        <td><textarea name="description" id="description" rows="5" cols="30"><?php echo $profileuser->description; // textarea_escaped ?></textarea>
    521         <p class="description"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></p></td>
     550        <p class="description"><?php _e( 'Share a little biographical information to fill out your profile. This may be shown publicly.' ); ?></p></td>
    522551</tr>
    523552
    … …  
    527556        <td>
    528557                <?php echo get_avatar( $user_id ); ?>
    529                 <p class="description"><?php
    530                         if ( IS_PROFILE_PAGE ) {
    531                                 /* translators: %s: Gravatar URL */
    532                                 $description = sprintf( __( 'You can change your profile picture on <a href="%s">Gravatar</a>.' ),
    533                                         __( 'https://en.gravatar.com/' )
    534                                 );
    535                         } else {
    536                                 $description = '';
    537                         }
     558                <p class="description">
     559                <?php
     560                if ( IS_PROFILE_PAGE ) {
     561                        /* translators: %s: Gravatar URL */
     562                        $description = sprintf(
     563                                __( 'You can change your profile picture on <a href="%s">Gravatar</a>.' ),
     564                                __( 'https://en.gravatar.com/' )
     565                        );
     566                } else {
     567                        $description = '';
     568                }
    538569
    539570                        /**
    … …  
    547578                         */
    548579                        echo apply_filters( 'user_profile_picture_description', $description, $profileuser );
    549                 ?></p>
     580                ?>
     581                </p>
    550582        </td>
    551583</tr>
    552584<?php endif; ?>
    553585
    554 <?php
    555 /**
    556  * Filters the display of the password fields.
    557  *
    558  * @since 1.5.1
    559  * @since 2.8.0 Added the `$profileuser` parameter.
    560  * @since 4.4.0 Now evaluated only in user-edit.php.
    561  *
    562  * @param bool    $show        Whether to show the password fields. Default true.
    563  * @param WP_User $profileuser User object for the current user to edit.
    564  */
    565 if ( $show_password_fields = apply_filters( 'show_password_fields', true, $profileuser ) ) :
    566 ?>
    567 </table>
    568 
    569 <h2><?php _e( 'Account Management' ); ?></h2>
     586        <?php
     587        /**
     588        * Filters the display of the password fields.
     589        *
     590        * @since 1.5.1
     591        * @since 2.8.0 Added the `$profileuser` parameter.
     592        * @since 4.4.0 Now evaluated only in user-edit.php.
     593        *
     594        * @param bool    $show        Whether to show the password fields. Default true.
     595        * @param WP_User $profileuser User object for the current user to edit.
     596        */
     597        if ( $show_password_fields = apply_filters( 'show_password_fields', true, $profileuser ) ) :
     598        ?>
     599        </table>
     600
     601        <h2><?php _e( 'Account Management' ); ?></h2>
    570602<table class="form-table">
    571603<tr id="password" class="user-pass1-wrap">
    … …  
    608640
    609641<?php
    610 if ( IS_PROFILE_PAGE && count( $sessions->get_all() ) === 1 ) : ?>
     642if ( IS_PROFILE_PAGE && count( $sessions->get_all() ) === 1 ) :
     643?>
    611644        <tr class="user-sessions-wrap hide-if-no-js">
    612645                <th><?php _e( 'Sessions' ); ?></th>
    … …  
    643676<?php endif; ?>
    644677
    645 </table>
    646 
    647 <?php
     678        </table>
     679
     680        <?php
    648681        if ( IS_PROFILE_PAGE ) {
    649682                /**
    … …  
    667700                do_action( 'edit_user_profile', $profileuser );
    668701        }
    669 ?>
    670 
    671 <?php
    672 /**
    673  * Filters whether to display additional capabilities for the user.
    674  *
    675  * The 'Additional Capabilities' section will only be enabled if
    676  * the number of the user's capabilities exceeds their number of
    677  * roles.
    678  *
    679  * @since 2.8.0
    680  *
    681  * @param bool    $enable      Whether to display the capabilities. Default true.
    682  * @param WP_User $profileuser The current WP_User object.
    683  */
    684 if ( count( $profileuser->caps ) > count( $profileuser->roles )
     702        ?>
     703
     704        <?php
     705        /**
     706        * Filters whether to display additional capabilities for the user.
     707        *
     708        * The 'Additional Capabilities' section will only be enabled if
     709        * the number of the user's capabilities exceeds their number of
     710        * roles.
     711        *
     712        * @since 2.8.0
     713        *
     714        * @param bool    $enable      Whether to display the capabilities. Default true.
     715        * @param WP_User $profileuser The current WP_User object.
     716        */
     717        if ( count( $profileuser->caps ) > count( $profileuser->roles )
    685718        && apply_filters( 'additional_capabilities_display', true, $profileuser )
    686 ) : ?>
    687 <h2><?php _e( 'Additional Capabilities' ); ?></h2>
     719        ) :
     720        ?>
     721        <h2><?php _e( 'Additional Capabilities' ); ?></h2>
    688722<table class="form-table">
    689723<tr class="user-capabilities-wrap">
    … …  
    692726<?php
    693727        $output = '';
    694         foreach ( $profileuser->caps as $cap => $value ) {
    695                 if ( ! $wp_roles->is_role( $cap ) ) {
    696                         if ( '' != $output )
    697                                 $output .= ', ';
    698                         $output .= $value ? $cap : sprintf( __( 'Denied: %s' ), $cap );
    699                 }
     728foreach ( $profileuser->caps as $cap => $value ) {
     729        if ( ! $wp_roles->is_role( $cap ) ) {
     730                if ( '' != $output ) {
     731                        $output .= ', ';
     732                }
     733                $output .= $value ? $cap : sprintf( __( 'Denied: %s' ), $cap );
    700734        }
     735}
    701736        echo $output;
    702737?>
    … …  
    707742
    708743<input type="hidden" name="action" value="update" />
    709 <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($user_id); ?>" />
    710 
    711 <?php submit_button( IS_PROFILE_PAGE ? __('Update Profile') : __('Update User') ); ?>
     744<input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $user_id ); ?>" />
     745
     746<?php submit_button( IS_PROFILE_PAGE ? __( 'Update Profile' ) : __( 'Update User' ) ); ?>
    712747
    713748</form>
    714749</div>
    715750<?php
    716 break;
     751                break;
    717752}
    718753?>
    … …  
    723758</script>
    724759<?php
    725 include( ABSPATH . 'wp-admin/admin-footer.php');
     760include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.