Primary links: Hide "login" after user logs in?
crick - April 19, 2006 - 05:02
I am using 4.7rc3. I have added "Login" (user/login) and "Register" (user/register) to my primary links. After logging in, the "Register" link disappears by default. I was wondering if there is a way to make the "Login" link do the same thing.
I looked through user.module and found this:
// Registration and login pages.
$items[] = array('path' => 'user/login', 'title' => t('log in'),
'callback' => 'user_login', 'type' => MENU_DEFAULT_LOCAL_TASK);
$items[] = array('path' => 'user/register', 'title' => t('register'),
'callback' => 'user_register', 'access' => $user->uid == 0 && variable_get('user_register', 1), 'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'user/password', 'title' => t('request new password'),
'callback' => 'user_pass', 'access' => $user->uid == 0, 'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'user/reset', 'title' => t('reset password'),
'callback' => 'user_pass_reset', 'access' => TRUE, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'user/help', 'title' => t('help'),
'callback' => 'user_help_page', 'type' => MENU_CALLBACK);I tried adding: 'access' => $user-uid == 0,
as well as a few other variations to the 'user_login' line. I was able to get the "Login" link to disappear, but it always messed up the login process by directing to a "you do not have access" page even though the log in was successful and the user menu block appeared.

ps. I did do a search on
ps. I did do a search on this and found ways of doing in 4.6.x with phptemplate in page.tpl.php. but the syntax is different in 4.7 and I couldnt make it work.
Link?
Can you provide a link? I'm feeling lazy today.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.
solution is not straightforward, but simple
I had this same problem once...
what you need to do is a make a module that defines a menu entry vor login .. I suggest the path
loginand access for only anonymous users$user->uid == 0that path must direct to a page that has a
drupal_goto('user/login')The result is something like this (save the code as loginmenu.module somewhere in your modules directory)
<?php
/* 2006-04-19 <a href="mailto:l.evers@ontwerpwerk.nl" rel="nofollow">l.evers@ontwerpwerk.nl</a> */
function loginmenu_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Make a login menu item that dissapeasr when users login.');
}
}
function loginmenu_menu($may_cache) {
$items = array();
global $user;
if ($may_cache) {
$items[] = array('path' => 'login',
'title' => t('login'),
'type' => MENU_NORMAL_ITEM,
'callback' => 'loginmenu_loginredirect',
// menu item for anonymous users
'access' => ($user->uid==0),
'weight' => 10);
}
return $items;
}
function loginmenu_loginredirect() {
// the redirect is nessecary, beacuse hijacking user/login here creates a little problem when logging in
drupal_goto('user/login');
}
?>
after that, enable the module, and place the login item on the right menu.
Use drupal_goto
You can use drupal_goto as your callback with the callback argument user eg:
<?php'callback' => 'drupal_goto',
'callback arguments' => array('user'),
?>
To get it on top of the nav menu, set weight to -10
http://pctips.ustilago.org/drupal-anonymous-link
Note: OP wants the link among the primary links.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.
cool
I guess I learned a new trick today :)
slick module trick
i just used this at manywaters.us -- was perfect. it was all i needed. you should submit it; too many modules try to do too much; this does just enough. (like simple_access, another small jewel).
thanks
Yeah, this was great.
Thanks for sharing! :)
Question...
crick, it sounds like you added this to the primary links that would appear in a place like the top right corner right? And not the navigation menu? If this is the case, the way to get it to disappear is by editing your template file and not user.module. There is code near the bottom of this thread that might be what you're looking for... http://drupal.org/node/58405. Let me know if that's it!
thats correct, the login
thats correct, the login link in question is indeed a "Primary Link"
the site in question is http://www.tommyross.net in case anyone wants a visual. the theme is simply a modified bluemarine. All of the basic elements of bluemarine are still present. I'm using nice_menu's in the right sidebar for user navigation.
I'll take a look at the link provided above.
edit: Ok I looked over your post at the above link. That looks like a good solution, my attempts at the top of this page was to try to get user.module to just function that way naturally. But it appears much easier to simply take "login" out of the Primary Links and code it into the theme.
I'll give it a try when I get home.
thanks.
excellent, your code worked
excellent, your code worked beautifully, i altered it slightly to suit my needs.
result:
<?php
print theme('links', $primary_links) . ' | ' ;
global $user;
if (!$user->uid) {
// Change the following line's text to whatever you want.
print l("Login", "user/login");
}
elseif ($user->uid) {
// The following line will display the log out link, once a user is logged in.
print l("Log out", "logout");
}
?>
thanks for the help.
Glad it worked out!
Glad it worked out!
change the primary link colour
i want to change the colour of primary links my page background colour is while when i change colour from style.css ehe colour of conten links means like login colour also changed please help me
start a new forum topic
Please start a new forum topic fot this, you will have more chance someone will reply.
This is related to theming by the way, check the handbooks about theming too...
--
I work for Ontwerpwerk
visibility settings
I would like to see page specific visibility settings added to the menu system the same as blocks have. That would make the menu system a lot more powerful and flexible.
I wonder if this has been discussed for 5.0 release. I don't know what would be the logistics behind this and how it would affect the menu cache. Maybe it should only be for user added menu items not module defined menu items. Or you can look at it as a visibility setting in the menu block and then it should not affect the menu system to much.
At the moment I have been grouping menu items that require the same visibility settings when controlling the visibility through the menu block. I don't like hacking modules menu hook.
Eg.
Show on every page except the listed pages.
Show on only the listed pages.
Show if the following PHP code returns TRUE (PHP-mode, experts only).
This is already available -
This is already available - disable the primary links in your theme, enable the primary links menu block in blocks and you're ready to go...
you can hack the theme hooks all you like, and modify the css to suit your needs
--
I work for Ontwerpwerk
I don't think you understand what I meant
What I would like to see is the ability to control each individual links visibility, not just the entire menu block. That way you can have dynamic menu link display. eg. Login link hides after login and Logout displays in place of the login link when the user is logged in, but all these links are part of the same menu.
I would also like to see the ability to set link attributes (eg. target, onclick....) to links.