I have a specific task: I need to give a temporary access to particular unpublished nodes for anonymous users using access token. Anonymous is a key feature, so I can't create a limited user account by some reasons.
I found a rough temporary solution by adding a field "access token" to my node type, creating a role with access to unpublished nodes (using view unpublished module) and by changing user_access function. I added the following strings:
if ($_GET['access_token'] && arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) { $node = node_load(arg(1)); if (isset($node->field_access_token['und'][0]['value']) && $node->field_access_token['und'][0]['value'] == $_GET['access_token']) { $account->roles[6] = 'unpublishedaccess'; } } How can I do similar but without changing Drupal core files?