You are here

function yandex_metrics_show_counter_for_role in Yandex.Metrics 7.2

Same name and namespace in other branches
  1. 8.3 yandex_metrics.module \yandex_metrics_show_counter_for_role()
  2. 8.2 yandex_metrics.module \yandex_metrics_show_counter_for_role()
  3. 6.2 yandex_metrics.module \yandex_metrics_show_counter_for_role()
  4. 6 yandex_metrics.module \yandex_metrics_show_counter_for_role()
  5. 7.3 yandex_metrics.module \yandex_metrics_show_counter_for_role()
  6. 7 yandex_metrics.module \yandex_metrics_show_counter_for_role()

Returns FALSE if we need to disable counter for role.

Return value

bool

1 call to yandex_metrics_show_counter_for_role()
yandex_metrics_page_build in ./yandex_metrics.module
Implements hook_page_build(). Adds Yandex.Metrica counter code to the site footer.

File

./yandex_metrics.module, line 220
The main code of Yandex.Metrics Counter module.

Code

function yandex_metrics_show_counter_for_role() {
  global $user;
  $visibility = variable_get('yandex_metrics_visibility_roles', 0);
  $enabled = $visibility;
  $roles = variable_get('yandex_metrics_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;
}