You are here

function _hotjar_check_roles in Hotjar 6

Same name and namespace in other branches
  1. 7 hotjar.module \_hotjar_check_roles()

Check user role.

1 call to _hotjar_check_roles()
_hotjar_check_user in ./hotjar.module
Check Hotjar code should be added for user.

File

./hotjar.module, line 172
Drupal Module: Hotjar.

Code

function _hotjar_check_roles($account = NULL) {
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }
  $settings = hotjar_get_settings();
  $visibility = $settings['hotjar_visibility_roles'];
  $enabled = $visibility;
  $roles = $settings['hotjar_roles'];
  $checked_roles = array_filter($roles);
  if (empty($checked_roles)) {

    // No role is selected for tracking, therefore all roles should be tracked.
    return TRUE;
  }

  // The hotjar_roles stores the selected roles as an array where
  // the keys are the role IDs. When the role is not selected the
  // value is 0. If a role is selected the value is the role ID.
  if (count(array_intersect_key($account->roles, $checked_roles))) {
    $enabled = !$visibility;
  }
  return $enabled;
}