}
if (function_exists('user_access')) {
$account = NULL;
- if ($userId) {
+ if ($userId || $userId === 0) {
$account = user_load($userId);
}
return user_access($str, $account);
}
if (function_exists('user_access')) {
$account = NULL;
- if ($userId) {
+ if ($userId || $userId === 0) {
$account = user_load($userId);
}
return user_access($str, $account);
}
if (function_exists('user_access')) {
$account = NULL;
- if ($userId) {
+ if ($userId || $userId === 0) {
$account = user_load($userId);
}
return user_access($str, $account);
if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
return TRUE;
}
- $acct = $userId ? \Drupal\user\Entity\User::load($userId) : \Drupal::currentUser();
+ $acct = ($userId === 0 ? \Drupal\user\Entity\User::getAnonymousUser() : ($userId ? \Drupal\user\Entity\User::load($userId) : \Drupal::currentUser()));
return $acct->hasPermission($str);
}
public function check($str, $userId = NULL) {
$config = CRM_Core_Config::singleton();
// JFactory::getUser does strict type checking, so convert falesy values to NULL
- if (!$userId) {
+ if ($userId === 0 || $userId === '0') {
+ $userId = 0;
+ }
+ elseif (!$userId) {
$userId = NULL;
}
$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;