You are here

function add_to_head_match_role in Add To Head 7

Same name and namespace in other branches
  1. 8 add_to_head.module \add_to_head_match_role()

Determines if code should be displayed for a particular role.

Originally from _googleanalytics_visibility_roles().

Parameters

boolean $visibility: TRUE if visible only for selected roles or FALSE if visible for all roles except listed.

array $roles: The list of roles to match.

Return value

boolean TRUE if the code should be displayed on the page; FALSE otherwise.

1 call to add_to_head_match_role()
add_to_head_process_html in ./add_to_head.module
Implements hook_process_html().

File

./add_to_head.module, line 174
Add To Head allows abritrary insertion of code into the head of the page based on path selection.

Code

function add_to_head_match_role($visibility, $roles) {

  // Assume the default visibility until we find one of the current roles on the list.
  $enabled = $visibility;
  if (array_sum($roles) > 0) {

    // One or more roles are selected.
    foreach (array_keys($GLOBALS['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 included or excluded from display.
        $enabled = !$visibility;
        break;
      }
    }
  }
  else {

    // No role is selected. Therefore all roles should be enabled.
    $enabled = TRUE;
  }
  return $enabled;
}