You are here

function _statcounter_visibility_roles in StatCounter 7.2

Based on visibility setting this function returns TRUE if Statcounter code should be added for the current role and otherwise FALSE.

2 calls to _statcounter_visibility_roles()
statcounter_form_user_profile_form_alter in ./statcounter.module
Implement hook_form_FORM_ID_alter().
_statcounter_visibility_user in ./statcounter.module
Tracking visibility check for an user object.

File

./statcounter.module, line 297
Drupal Module: Statcounter Adds the required Javascript to the bottom of all your Drupal pages to allow tracking by the Statcounter statistics service.

Code

function _statcounter_visibility_roles($account) {
  $visibility = variable_get('statcounter_visibility_roles', 0);
  $enabled = $visibility;
  $roles = variable_get('statcounter_roles', array());
  if (array_sum($roles) > 0) {

    // One or more roles are selected.
    foreach (array_keys($account->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;
}