Last active
July 24, 2018 00:24
-
-
Save travisbutterfield/b7072888d8566d1b9bda01c1edf866cd to your computer and use it in GitHub Desktop.
An example of the code to place in a custom module for limiting access to a specific content type, in this case the "custom content type" content type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implement hook_node_access(). | |
*/ | |
// Add perms to the custom_content_type content type | |
function HOOK_node_access($node, $op, $account) { | |
$type = is_string($node) ? $node : $node->type; | |
if ($type == 'custom_content_type' && $op == 'view') { | |
// Define roles that can see custom_content_type content type content. | |
global $user; | |
$custom_content_type_perms = array_intersect( | |
array( | |
'role1', | |
'role2', | |
'role3' | |
), | |
array_values($user->roles)); | |
// If they have any of these roles, then they can see the custom_content_type content | |
if ($custom_content_type_perms){ | |
return NODE_ACCESS_ALLOW; | |
} | |
else { | |
return NODE_ACCESS_DENY; | |
} | |
} | |
return NODE_ACCESS_IGNORE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment