Halloween Sale 15% off Ends in See the plans
PHP

Private Admin Notes on User Profiles

Adds a notes box to user profiles that only administrators can see and edit, for things like support history or account details.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_user_notes_render = function ( $user ) {
    if ( ! current_user_can( 'edit_users' ) ) {
        return;
    }
    ?>
    <h2>Admin Notes</h2>
    <table class="form-table" role="presentation">
        <tr>
            <th><label for="wpide_admin_notes">Private notes</label></th>
            <td>
                <textarea name="wpide_admin_notes" id="wpide_admin_notes" rows="5" class="large-text"><?php echo esc_textarea( get_user_meta( $user->ID, 'wpide_admin_notes', true ) ); ?></textarea>
                <p class="description">Only visible to users who can edit users.</p>
            </td>
        </tr>
    </table>
    <?php
};

add_action( 'show_user_profile', $wpide_user_notes_render );
add_action( 'edit_user_profile', $wpide_user_notes_render );

// WordPress verifies the profile form nonce before these actions run.
$wpide_user_notes_save = function ( $user_id ) {
    if ( current_user_can( 'edit_users' ) && current_user_can( 'edit_user', $user_id ) && isset( $_POST['wpide_admin_notes'] ) ) {
        update_user_meta( $user_id, 'wpide_admin_notes', sanitize_textarea_field( wp_unslash( $_POST['wpide_admin_notes'] ) ) );
    }
};

add_action( 'personal_options_update', $wpide_user_notes_save );
add_action( 'edit_user_profile_update', $wpide_user_notes_save );

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.