Last active
January 10, 2021 20:03
-
-
Save aldolat/2d97e76e2f2edd2b3bf91047151987e7 to your computer and use it in GitHub Desktop.
Show the current user roles when using the plugin Private Content.
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 | |
/** | |
* Show the current user role. | |
*/ | |
function ubn_show_current_user_role( $text ) { | |
$user = wp_get_current_user(); | |
$roles = ''; | |
foreach ( $user->roles as $role ) { | |
$roles .= $role . ', '; | |
} | |
if ( empty( $roles ) ) { | |
$roles = 'Visitor'; | |
} | |
return '<p style="background-color: red; color: white; font-weight: bold; padding: 1.2em;">Your current roles:<br />' . rtrim( $roles, ', ' ) . '.</p>' . $text; | |
} | |
add_filter( 'ubn_private_text', 'ubn_show_current_user_role' ); | |
add_filter( 'ubn_private_text_empty', 'ubn_show_current_user_role' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment