Drupal shows "create content" menu item to anonymous users

So, I'm working on a Drupal site that, for reasons unknown, shows the "create content" menu item even when the user is logged out. Since I don't allow anonymous users to post on this site, clicking on that menu item gives a "permission denied" error. Not exactly the sort of user experience I want to provide.

Well, I just came up with this bit of code to fix the problem. It goes in index.php after the call to drupal_bootstrap():


if (strstr($_SERVER["REQUEST_URI"], "/node/add")) {

   if (empty($user->uid)) {
      drupal_set_message("You must be logged in to do that");
      drupal_goto("user");
   }

}

Share and enjoy! (Or just give me funny looks. That works too.)

(Update: If that seems too complicated, you may want to give this a try!)

3
Average: 3 (3 votes)
Your rating: None