Last active
November 15, 2017 15:32
-
-
Save asharirfan/f0cfa3b55c147012a2b8a7f33d123094 to your computer and use it in GitHub Desktop.
WPC — Print current user roles in WP admin dashboard 💯
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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