9th August 2016 - 5 minutes read time
I was recently asked to implement a feature on a Drupal site where all nodes of a certain type would redirect to a main listing page if that node had been unpublished. The problem in doing this is that if a post is unpublished then Drupal will issue an access denied response quite early on in the boot process. When the menu item is loaded it goes through an access callback which sees that the post is unpublished and issues an access denied before anything else can happen. So in this situation you can't use things like Rules to redirect users as the rule is never triggered.
The solution was to use hook_menu_alter() to change the access callback parameter of the node page. We are essentially replacing the normal access callback of node_access() with our own version.