0

I have a menu item:

$items['login-now'] = array
(
    'title' => 'Log In',
    'page callback' => 'some_or_other_method',
    'access callback' => 'the_permissions_function',
    'menu_name' => 'menu-ecommerce-nav',
    'type' => MENU_NORMAL_ITEM,
    'weight' => '5',
);

And then I have:

function the_permissions_function { 
    $isAnonymousUser = user_is_anonymous();
    if (!$isAnonymousUser) {
        return FALSE;
    } 
    return TRUE;
}

This works if I am logged out. I can see the "log in" button. But when I log in, it STILL shows this login button. Why?

What's interesting is, I added this above the "return false"

print 'xxxx'; die();

And it hits this code!! But for some reason, it still shows the menu item? Why is it not hiding the menu item?

UPDATE

Even if I just do this:

'access callback' => 'user_is_anonymous',

It STILL shows the "log in" menu item when I am LOGGED in. Why on earth is it doing this? What am I missing?

2 Answers 2

0

Your menu gets cached, so you need to clear the caches after you change something in you hook_menu() or hook_menu_alter().

0

user_is_anonymous() returns TRUE if the user is a menu administrator: see function user_is_anonymous

Try user_is_logged_in() instead, e.g.:

function the_permissions_function { 
    $isLoggedIn = user_is_logged_in();
    if ($isLoggedIn) {
        return FALSE;
    } 
    return TRUE;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.