function unpublished_nodes_redirect_access_callback in Unpublished Nodes Redirect 7
Custom access callback to redirect the user if a node is unpublished.
1 string reference to 'unpublished_nodes_redirect_access_callback'
File
Code
function unpublished_nodes_redirect_access_callback($op, $node, $account = NULL) {
// Node is unpublished and the user is not logged in.
if ($node->status == 0 && !user_is_logged_in()) {
// Make sure cron isn't running.
if (variable_get('cron_semaphore', FALSE) === FALSE && $_SERVER['SCRIPT_NAME'] !== '/cron.php' && arg(3) !== 'run-cron') {
// Not a JS callback.
if (arg(0) != 'js') {
// Get the redirect path for this node type.
$redirect_path = variable_get($node->type . '_unpublished_redirect_path', '');
// Get the response code for this node type.
$response_code = variable_get($node->type . '_unpublished_redirect_response_code');
// If the redirect path exists, do a permanent redirect.
if (!empty($redirect_path) && $response_code != 0) {
drupal_goto($redirect_path, array(), $response_code);
}
}
}
}
return node_access($op, $node, $account);
}