You are here

function _pardot_visibility_roles in Pardot Integration 7

Determines if Pardot code should be add for the given user's role.

Parameters

array $user: The given user.

Return value

bool Returns TRUE if GA code should be added for the role, FALSE otherwise.

1 call to _pardot_visibility_roles()
pardot_init in ./pardot.module
Implements hook_init().

File

./pardot.module, line 584
Pardot integration module.

Code

function _pardot_visibility_roles($user) {
  $visibility = variable_get('pardot_visibility_roles', 0);
  $enabled = $visibility;
  $roles = variable_get('pardot_roles', array());
  if (array_sum($roles) > 0) {

    // One or more roles are selected.
    foreach (array_keys($user->roles) as $rid) {

      // Is the current user a member of one of these roles?
      if (isset($roles[$rid]) && $rid == $roles[$rid]) {

        // Current user is a member of a role that should be tracked/excluded
        // from tracking.
        $enabled = !$visibility;
        break;
      }
    }
  }
  else {

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