-
-
Save mikeselander/66dff6f4af3c77ea7f7a to your computer and use it in GitHub Desktop.
This file contains 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 | |
function check_user_role($roles,$user_id=NULL) { | |
// Get user by ID, else get current user | |
if ($user_id) | |
$user = get_userdata($user_id); | |
else | |
$user = wp_get_current_user(); | |
// No user found, return | |
if (empty($user)) | |
return FALSE; | |
// Append administrator to roles, if necessary | |
if (!in_array('administrator',$roles)) | |
$roles[] = 'administrator'; | |
// Loop through user roles | |
foreach ($user->roles as $role) { | |
// Does user have role | |
if (in_array($role,$roles)) { | |
return TRUE; | |
} | |
} | |
// User not in roles | |
return FALSE; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment