Skip to content

Instantly share code, notes, and snippets.

@asharirfan
Last active November 15, 2017 15:32
Show Gist options
  • Save asharirfan/f0cfa3b55c147012a2b8a7f33d123094 to your computer and use it in GitHub Desktop.
Save asharirfan/f0cfa3b55c147012a2b8a7f33d123094 to your computer and use it in GitHub Desktop.
WPC — Print current user roles in WP admin dashboard 💯
<?php
/**
* Tell My Role.
*
* Get the roles of current user and display it.
*
* @since 1.0.0
*/
function tmr_display_current_user_role() {
// Get current user.
$current_user = wp_get_current_user();
// Get the user roles.
$current_user_roles = $current_user->roles;
// Convert user roles array into a string.
$current_user_roles = implode( ', ', $current_user_roles );
// Display user roles.
echo '<p class="tmr_user_roles tmr_user_roles__head">' . esc_html( $current_user_roles ) . '</p>';
}
// Hook it!
add_action( 'admin_notices', 'tmr_display_current_user_role' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment