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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.