function taxonomy_tools_taxonomy_term_access in Taxonomy Tools 8
Same name and namespace in other branches
- 7 taxonomy_tools.module \taxonomy_tools_taxonomy_term_access()
Controls the access to the taxonomy term.
If the taxonomy term is from a vocabulary that uses Taxonoomy Publisher functionality, it's status will checked to determine whether the user is allowed to access it.
Parameters
stdClass $term: A taxonomy term object or a string containing taxonomy term ID.
Return value
bool TRUE if user is allowed to access the taxonomy term, and FALSE if isn't.
1 string reference to 'taxonomy_tools_taxonomy_term_access'
- taxonomy_tools_menu_alter in ./
taxonomy_tools.module - Implements hook_menu_alter().
File
- ./
taxonomy_tools.module, line 139 - Drupal hooks and functions to work with taxonomy terms.
Code
function taxonomy_tools_taxonomy_term_access($term) {
$access = user_access('access content');
// In case only term ID is passed as parameter we must load the term object.
if (is_numeric($term)) {
$term = taxonomy_term_load($term);
}
if (is_object($term)) {
if (module_exists('taxonomy_tools_publisher') && $access) {
// If Taxonomy Publisher is enabled and term is available to the user.
$config = array_filter(variable_get('taxonomy_tools_publisher_config', array()));
if (!empty($config) && in_array($term->vocabulary_machine_name, $config)) {
// We must check the whole hierarchy branch up to the top level.
$result = taxonomy_tools_publisher_check_branch($term->tid);
if (!user_access('bypass taxonomy publisher') && $result == 0) {
// User isn't allowed to access the term,
// because the term (or it's parent term) is not published
// and user doesn't have permission to view unpublished terms.
$access = FALSE;
}
}
}
if (module_exists('taxonomy_tools_role_access') && $access && !user_access('bypass taxonomy role access')) {
// If Taxonomy Role Access is enabled and term is still available to
// the user and user doesn't have permissions to bypass settings.
$access = FALSE;
global $user;
$roles = $user->roles;
$config = variable_get('taxonomy_tools_role_access_role_config', array());
foreach ($roles as $rid => $role) {
if (in_array($rid, $config)) {
// User role is controlled by Taxonomy Role Access.
$role_access = taxonomy_tools_role_access_get_access($term->tid, $rid);
if ($role_access) {
// Term is available to the user role.
$access = TRUE;
break;
}
}
else {
// One of the user roles is not controlled by Taxonomy Role Access
// term is available to the user.
$access = TRUE;
break;
}
}
}
}
else {
// Something is wrong with the passed parameter - deny access.
$access = FALSE;
}
return $access;
}