function _piwik_visibility_roles in Piwik Web Analytics 8
Same name and namespace in other branches
- 5 piwik.module \_piwik_visibility_roles()
- 6.2 piwik.module \_piwik_visibility_roles()
- 6 piwik.module \_piwik_visibility_roles()
- 7.2 piwik.module \_piwik_visibility_roles()
- 7 piwik.module \_piwik_visibility_roles()
Tracking visibility check for user roles.
Based on visibility setting this function returns TRUE if Piwik code should be added for the current role and otherwise FALSE.
Parameters
object $account: A user object containing an array of roles to check.
Return value
bool TRUE if JS code should be added for the current role and otherwise FALSE.
2 calls to _piwik_visibility_roles()
- piwik_form_user_form_alter in ./
piwik.module - Implements hook_form_FORM_ID_alter().
- _piwik_visibility_user in ./
piwik.module - Tracking visibility check for an user object.
File
- ./
piwik.module, line 604 - Drupal Module: Piwik.
Code
function _piwik_visibility_roles($account) {
$config = \Drupal::config('piwik.settings');
$enabled = $visibility_user_role_mode = $config
->get('visibility.user_role_mode');
$user_role_roles = $config
->get('visibility.user_role_roles');
if (count($user_role_roles) > 0) {
// One or more roles are selected.
foreach (array_values($account
->getRoles()) as $user_role) {
// Is the current user a member of one of these roles?
if (in_array($user_role, $user_role_roles)) {
// Current user is a member of a role that should be tracked/excluded
// from tracking.
$enabled = !$visibility_user_role_mode;
break;
}
}
}
else {
// No role is selected for tracking, therefore all roles should be tracked.
$enabled = TRUE;
}
return $enabled;
}