You are here

function _google_tag_role_check in GoogleTagManager 7

Determines whether to insert the snippet based on the user role settings.

Return value

bool TRUE if the role conditions are met; FALSE otherwise.

1 call to _google_tag_role_check()
google_tag_insert_snippet in ./google_tag.module
Determines whether to insert the snippet on the response.

File

./google_tag.module, line 369
Provides primary Drupal hook implementations.

Code

function _google_tag_role_check() {
  global $user;
  static $satisfied;
  if (!isset($satisfied)) {
    $debug = variable_get('google_tag_debug_output', 0);
    $toggle = variable_get('google_tag_role_toggle', GOOGLE_TAG_EXCLUDE_LISTED);
    $roles = variable_get('google_tag_role_list', array());
    $roles = array_filter($roles);
    if (empty($roles)) {
      $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED;
    }
    else {
      $satisfied = FALSE;

      // Check user roles against listed roles.
      $satisfied = (bool) array_intersect($roles, $user->roles);
      $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED ? !$satisfied : $satisfied;
    }
    $debug ? drupal_set_message(t('role check @satisfied', array(
      '@satisfied' => $satisfied,
    ))) : '';
  }
  return $satisfied;
}