Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Last active May 30, 2020 15:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hlashbrooke/8f901da7c6f0d107add7 to your computer and use it in GitHub Desktop.
Save hlashbrooke/8f901da7c6f0d107add7 to your computer and use it in GitHub Desktop.
WordPress: Check if user role exists
function role_exists( $role ) {
if( ! empty( $role ) ) {
return $GLOBALS['wp_roles']->is_role( $role );
}
return false;
}
if( role_exists( 'editor' ) ) {
// The 'editor' role exists!
}
@0xcrypto
Copy link

+1 to @TomAuger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment