Skip to content

Instantly share code, notes, and snippets.

@Pross
Last active January 11, 2021 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Pross/e74b518d62d5b1dbe02afff8be5de399 to your computer and use it in GitHub Desktop.
Save Pross/e74b518d62d5b1dbe02afff8be5de399 to your computer and use it in GitHub Desktop.
Current user role shortcode.
<?php // ADDED FOR CODE HIGHLIGHTING
add_shortcode( 'current_role', function() {
global $wp_roles;
$current_user = wp_get_current_user();
$role = array_shift( $current_user->roles );
return isset( $wp_roles->role_names[ $role ] ) ? translate_user_role( $wp_roles->role_names[ $role ] ) : false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment