Add access callback contingencies for Context, PHP, Rules, Admin etc.

Created on 30 October 2011, almost 14 years ago
Updated 18 July 2025, 16 days ago

A frequent question in the issues queues for both 6.x and 7.x branches is 'How to show tab X only under condition Y?'

Examples:
- hide tabs for specific user roles, but not for admin
- hide tabs only if PHP code returns TRUE
- hide tabs depending on Context or Rules
etc.

The difficulty of doing this, is that tabs are part of the core menu system. You need to re-write each tab's access callback and add in the contingencies for roles, context, rules, PHP etc.

The way to do it for a single tab looks like this:

function hook_menu_alter(&$items) {
  $items['my/tab/path']['access callback'] = 'my_new_tab_path_callback';
}

function my_new_tab_path_callback() {
  // copy the original access callback (if any)
  // change the code to your needs, e.g. add logic for context, roles, your custom PHP
  // return TRUE or FALSE
}

In this issues we can bundle all ideas and figure out how to do it (if possible at all).

Feature request
Status

Closed: outdated

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024