Skip to content

Instantly share code, notes, and snippets.

@aldolat
Last active January 10, 2021 20:03
Show Gist options
  • Save aldolat/2d97e76e2f2edd2b3bf91047151987e7 to your computer and use it in GitHub Desktop.
Save aldolat/2d97e76e2f2edd2b3bf91047151987e7 to your computer and use it in GitHub Desktop.
Show the current user roles when using the plugin Private Content.
<?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