$user = $userId ? get_userdata($userId) : wp_get_current_user();
- if ($user->has_cap('super admin') || $user->has_cap('administrator')) {
+ if ($userId !== 0 && ($user->has_cap('super admin') || $user->has_cap('administrator'))) {
return TRUE;
}
// Make string lowercase and convert spaces into underscore
$str = CRM_Utils_String::munge(strtolower($str));
- if ($user->exists()) {
+ if ($userId !== 0 && $user->exists()) {
// Check whether the logged in user has the capabilitity
if ($user->has_cap($str)) {
return TRUE;
else {
//check the capabilities of Anonymous user)
$roleObj = new WP_Roles();
- if (
- $roleObj->get_role('anonymous_user') != NULL &&
- array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities)
- ) {
+ $anonObj = $roleObj->get_role('anonymous_user');
+ if (!empty($anonObj->capabilities) && array_key_exists($str, $anonObj->capabilities)) {
return TRUE;
}
}