Jump to content

change the menu of logged out users


Sybille

Recommended Posts

Hi,

 

I would like to change the navigation on the page (eg. Login page), when the user is NOT logged in.

 

At the moment the navigation shows Home | Network Status | Affiliation

For all three menu you have to log in.

1. I would like to remove “Affiliation”

2. I would like, that the user can visit the Network Status without to be logged in.

 

Thanks in advanced for yours support.

Sybille

Link to comment
Share on other sites

Sybille,

 

for 1. you can slightly modify a hook that I posted in the thread below...

 

http://forum.whmcs.com/showthread.php?105506-How-do-I-remove-the-affiliate-menu-for-non-affiliates&p=434254#post434254

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $client = Menu::context('client'); 

   if (is_null($client) and !is_null($primaryNavbar->getChild('Affiliates'))) {
           $primaryNavbar->removeChild('Affiliates');

   }
}); 

for 2., that can be changed in the settings by unticking a checkbox...

 

setup -> general settings -> support -> Service Status Require Login

Link to comment
Share on other sites

Hi Brian,

 

You’re great! :!:

Both solutions worked perfectly out for me. I was surprised, that the order of my code in the Clien-tAreaPrimaryNavbar.php matters. First I had the code for the mutation for the menu when the user is logged in. For example I removed "My Quotes", rearranged the menu and so one and added your code to the end of the script. The menu didn't change and "Affiliates" was still shown.

 

When I put your code first followed by the other changes for the menu for logged in users, it worked out perfectly. Do you know why this is like that?

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
// Menu changes, when logged OUT

// "Partner" ausblenden, wenn User ausgelogged
   $client = Menu::context('client'); 

   if (is_null($client) and !is_null($primaryNavbar->getChild('Affiliates'))) {
           $primaryNavbar->removeChild('Affiliates');

   }


// Menu changes, when logged IN

// Submenü "Offerte" unter "Rechnungen" ausblenden
   if (!is_null($primaryNavbar->getChild('Billing'))) {
       $primaryNavbar->getChild('Billing')->removeChild('My Quotes');
   }

// Re-arranging Submenu "Support"
   $navItem = $primaryNavbar->getChild('Support');
   if (is_null($navItem)) {
       return;
   }
$primaryNavbar->getChild('Support')->getChild('Network Status')->moveToFront();
$primaryNavbar->getChild('Support')->getChild('Knowledgebase')->moveUp();
$primaryNavbar->getChild('Support')->getChild('Knowledgebase')->moveUp();


// Mainmenü "Ticket eröffnen" ausblenden
   if (!is_null($primaryNavbar->getChild('Open Ticket'))) {
       $primaryNavbar->removeChild('Open Ticket');
   }

// add Menu Item "Kontakt"
    $primaryNavbar->addChild('Kontakt')
       ->setUri('contact_redIT.php')
       ->setOrder(70);
});

Link to comment
Share on other sites

the order shouldn't really matter - as long as you're not trying to do two contradictory things to the same menu - though looking at your code, I don't think you are...

 

if you just put the following into your hook, it should have still worked anywhere...

 

    $client = Menu::context('client'); 

   if (is_null($client) and !is_null($primaryNavbar->getChild('Affiliates'))) {
           $primaryNavbar->removeChild('Affiliates');

   }

btw, with regards to changing the order of the Support menu, you can use setOrder in there too instead of using multiple moveUp()...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
// Menu changes, when logged OUT

// "Partner" ausblenden, wenn User ausgelogged
   $client = Menu::context('client'); 

   if (is_null($client) and !is_null($primaryNavbar->getChild('Affiliates'))) {
           $primaryNavbar->removeChild('Affiliates');

   }

// Menu changes, when logged IN

// Submenü "Offerte" unter "Rechnungen" ausblenden
   if (!is_null($primaryNavbar->getChild('Billing'))) {
       $primaryNavbar->getChild('Billing')
                   ->removeChild('My Quotes');
   }

// Re-arranging Submenu "Support"
   if (!is_null($primaryNavbar->getChild('Support'))) {
       $primaryNavbar->getChild('Support')
                   ->getChild('Network Status')
                   ->setOrder(1);
       $primaryNavbar->getChild('Support')
                   ->getChild('Knowledgebase')
                   ->setOrder(2);
   }

// Mainmenü "Ticket eröffnen" ausblenden
   if (!is_null($primaryNavbar->getChild('Open Ticket'))) {
       $primaryNavbar->removeChild('Open Ticket');
   }

// add Menu Item "Kontakt"
   $primaryNavbar->addChild('Kontakt')
       ->setUri('contact_redIT.php')
       ->setOrder(70);
});

I think, by default, the menu (sub)item order values use multiples of 10, so 'Tickets' is 10, 'Announcements' is 20 etc - so by changing Network Status / KB order values to '1' and '2', they'll be shown first - in fact, any values less than 10 should do. :idea:

Link to comment
Share on other sites

  • 3 years later...

Hi, I'm lost. I followed all recommendations and tutorials here and at WHMCS like this:

https://developers.whmcs.com/themes/navigation/

but it doesn't solve my problem. The situation is as follow:

1. I have customized the top menu for all "clients" (doesn't matter if logged in or not) - it's working fine
2. For logged in customers I have removed all the top menu stuff, because it's not necessary for them
3. Now I'm trying to "customize" the menu for only logged in customers with adding my own menu items/subitems, but without success.

The problem would be probably by using the Lagom template as they have some "own" codes, not ususally used by WHMCS. Here my hook code for the top menu:

<?php

/***** START - Remove menu items *****/

add_hook('ClientAreaNavbars', -1, function () {
    $primaryNavbar = Menu::primaryNavbar();

    if ($primaryNavbar && !is_null($primaryNavbar->getChild('Home'))) {
        $primaryNavbar->removeChild('Home');
    }                               

    if ($primaryNavbar && !is_null($primaryNavbar->

    getChild('Store'))) {
    $primaryNavbar->removeChild('Store');
    }

    if ($primaryNavbar && !is_null($primaryNavbar->

    getChild('Affiliates'))) {
    $primaryNavbar->removeChild('Affiliates');
    }

    if ($primaryNavbar && !is_null($primaryNavbar->

    getChild('Knowledgebase'))) {
    $primaryNavbar->removeChild('Knowledgebase');
    }

    if ($primaryNavbar && !is_null($primaryNavbar->

    getChild('Announcements'))) {
    $primaryNavbar->removeChild('Announcements');
    }
});

    /***** END - Remove menu items *****/

    /***** START - Custom menu items *****/

add_hook('ClientAreaPrimaryNavbar', 1, function($primaryNavbar) {

    $client = Menu::context('client'); 
    
    if (is_null($client)) {
    
    $newMenu = $primaryNavbar->addChild(
    'hosting',
    array(
    'label' => Lang::trans('Hosting'),
    'uri' => '',
    'order' => 11,
    )
    );
    $newMenu->addChild(
    'sharedhosting',
    array(
    'label' => Lang::trans('Shared Hosting'),
    'uri' => 'cart.php?gid=1',
    'order' => 1,
    )
    );
    $newMenu->addChild(
    'wordpresshosting',
    array(
    'label' => Lang::trans('WordPress Hosting'),
    'uri' => 'cart.php?gid=34',
    'order' => 2,
    )
    );
    ///////////////////////////////////////////////
    $newMenu = $primaryNavbar->addChild(
    'ecommerce',
    array(
    'label' => Lang::trans('Ecommerce Hosting'),
    'uri' => '',
    'order' => 12,
    )
    );
    $newMenu->addChild(
    'ecommerce1',
    array(
    'label' => Lang::trans('CS-Cart Hosting'),
    'uri' => 'cart.php?gid=36',
    'order' => 1,
    )
    );
    $newMenu->addChild(
    'ecommerce2',
    array(
    'label' => Lang::trans('Magento Hosting'),
    'uri' => '',
    'order' => 2,
    )
    );
    ///////////////////////////////////////////////
    $newMenu = $primaryNavbar->addChild(
    'vps',
    array(
    'label' => Lang::trans('Virtual Private Servers'),
    'uri' => '',
    'order' => 13,
    )
    );
    $newMenu->addChild(
    'vps1',
    array(
    'label' => Lang::trans('VPS Cloud Shared'),
    'uri' => 'cart.php?gid=33',
    'order' => 1,
    )
    );
    $newMenu->addChild(
    'vps2',
    array(
    'label' => Lang::trans('VPS Cloud Dedicated'),
    'uri' => 'cart.php?gid=31',
    'order' => 2,
    )
    );
    ///////////////////////////////////////////////
    $newMenu = $primaryNavbar->addChild(
    'dedicated',
    array(
    'label' => Lang::trans('Dedicated Servers'),
    'uri' => 'cart.php?gid=14',
    'order' => 14,
    )
    );
    ///////////////////////////////////////////////
    $newMenu = $primaryNavbar->addChild(
    'cscart',
    array(
    'label' => Lang::trans('CS-Cart'),
    'uri' => '',
    'order' => 15,
    )
    );
    $newMenu->addChild(
    'cscartlicenses',
    array(
    'label' => Lang::trans('CS-Cart Licenses'),
    'uri' => 'cart.php?gid=2',
    'order' => 1,
    )
    );
    $newMenu->addChild(
    'cscarthosting',
    array(
    'label' => Lang::trans('CS-Cart Hosting'),
    'uri' => 'cart.php?gid=36',
    'order' => 2,
    )
    );
    }
});

This code below has removed the menu items from the top menu, if a customer is logged in:

$client = Menu::context('client'); 
    
    if (is_null($client)

Then, if a customer is logged in, in the top menu remain items only for logged in customer, what would be ok (see the screenshot)

But how can I add new menu items to the "logged in" users, or remove the current visible with a hook?

For example I will add the "Knowledge Base" again there or "Affiliates" which is missing or completely a new menu item with some "childs".

Thanks for any recommendations.

 

screenshot-21_56_37.jpg

Edited by isixhosting
Link to comment
Share on other sites

19 hours ago, isixhosting said:

Hi, I'm lost. I followed all recommendations and tutorials here and at WHMCS like this:

I think you've really overcomplicated this by using multiple hooks and the way you're using each of them - it can be simplified to something more clearer... in fact, it could be reduced far more than i'm going to post here as i'm trying to keep it understandable for all.

19 hours ago, isixhosting said:

1. I have customized the top menu for all "clients" (doesn't matter if logged in or not) - it's working fine

to a certain extent, that bit is fine... i'd argue that removing the affiliates link for everyone, then wanting to add it back just for clients, is a little silly - just remove it for non-clients.

19 hours ago, isixhosting said:

2. For logged in customers I have removed all the top menu stuff, because it's not necessary for them

i'm not sure that you have going from that screenshot.

19 hours ago, isixhosting said:

3. Now I'm trying to "customize" the menu for only logged in customers with adding my own menu items/subitems, but without success.

you have to be careful because just one character wrong and it won't necessarily throw an error, the hook just won't work.

19 hours ago, isixhosting said:

The problem would be probably by using the Lagom template as they have some "own" codes, not usually used by WHMCS.

out of the box, I don't think that Lagom does anything kinky with the navbars (other than to split the primary / secondary locations) - using hooks on them should still work...

and i'm speaking as someone who was generously given a Lagom developers license by a client. 😎

one way I would write that hook would be...

<?php

add_hook('ClientAreaPrimaryNavbar', 1, function($primaryNavbar) {

	$client = Menu::context('client');
	
	# remove for all
	
	if (!is_null($primaryNavbar->getChild('Home'))) {
		$primaryNavbar->removeChild('Home');
	}                               

	# remove for non-clients
	
	if (is_null($client) && !is_null($primaryNavbar->getChild('Store'))) {
		$primaryNavbar->removeChild('Store');
	}  	
	if (is_null($client) && !is_null($primaryNavbar->getChild('Affiliates'))) {
		$primaryNavbar->removeChild('Affiliates');
	}
	if (is_null($client) && !is_null($primaryNavbar->getChild('Knowledgebase'))) {
		$primaryNavbar->removeChild('Knowledgebase');
	}
	if (is_null($client) && !is_null($primaryNavbar->getChild('Announcements'))) {
		$primaryNavbar->removeChild('Announcements');
	}	

	# add for non-clients

	if (is_null($client)) {
		$primaryNavbar->addChild('hosting')->setLabel(Lang::trans('Hosting'))->setOrder(11);
		if (!is_null($primaryNavbar->getChild('hosting'))) {
			$primaryNavbar->getChild('hosting')->addChild('sharedhosting')->setLabel(Lang::trans('Shared Hosting'))->setURI('cart.php?gid=1')->setOrder(1);
			$primaryNavbar->getChild('hosting')->addChild('wordpresshosting')->setLabel(Lang::trans('WordPress Hosting'))->setURI('cart.php?gid=34')->setOrder(2);
		}
		$primaryNavbar->addChild('ecommerce')->setLabel(Lang::trans('Ecommerce Hosting'))->setOrder(12);
		if (!is_null($primaryNavbar->getChild('ecommerce'))) {
			$primaryNavbar->getChild('ecommerce')->addChild('ecommerce1')->setLabel(Lang::trans('CS-Cart Hosting'))->setURI('cart.php?gid=36')->setOrder(1);
			$primaryNavbar->getChild('ecommerce')->addChild('ecommerce2')->setLabel(Lang::trans('Magento Hosting'))->setOrder(2);
		}
		$primaryNavbar->addChild('vps')->setLabel(Lang::trans('Virtual Private Servers'))->setOrder(13);
		if (!is_null($primaryNavbar->getChild('vps'))) {		
			$primaryNavbar->getChild('vps')->addChild('vps1')->setLabel(Lang::trans('VPS Cloud Shared'))->setURI('cart.php?gid=33')->setOrder(1);
			$primaryNavbar->getChild('vps')->addChild('vps2')->setLabel(Lang::trans('VPS Cloud Dedicated'))->setURI('cart.php?gid=31')->setOrder(2);
		}
		$primaryNavbar->addChild('dedicated')->setLabel(Lang::trans('Dedicated Servers'))->setURI('cart.php?gid=14')->setOrder(14);
		$primaryNavbar->addChild('cscart')->setLabel(Lang::trans('CS-Cart'))->setOrder(15);
		if (!is_null($primaryNavbar->getChild('cscart'))) {		
			$primaryNavbar->getChild('cscart')->addChild('cscartlicenses')->setLabel(Lang::trans('CS-Cart Licenses'))->setURI('cart.php?gid=2')->setOrder(1);
			$primaryNavbar->getChild('cscart')->addChild('cscarthosting')->setLabel(Lang::trans('CS-Cart Hosibg'))->setURI('cart.php?gid=36')->setOrder(2);
		}
	}
	
	# add for clients only
	
	if (!is_null($client)) {
		$primaryNavbar->addChild('kb')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('knowledgebase.php')->setOrder(50);
	}
}); 

possibly an oversight on your part, but the magento child doesn't contain a link.

19 hours ago, isixhosting said:

But how can I add new menu items to the "logged in" users

in terms of how to add menu items for logged in users, i've done that at the end of the above hook where i've added a kb link back in for clients only.

19 hours ago, isixhosting said:

or remove the current visible with a hook?

if you mean Services/Domains/Billing/Support, and removing them entirely/individually, then you don't really need to check whether the user is logged in or not - the same as you don't need to (though I do in the above hook) check that the client is not logged in when removing the "Store" link... it doesn't matter because only non-clients see the store link, clients don't (at least out of the box)...

as an aside, you could nuke them with about 4 lines of code if you had to - but there are only four elements to remove, so let's not be deploying weapons of mass destruction for something so small. ☢️

note this quick method works because these default navbar children have unique names - if you had a situation where a link exists in both logged non-logged navbars (home being the obvious example), and you wanted to change their links depending on client logged in status, then under those circumstances, you would check first whether they were logged in or not... but I think for your purpose, you won't have to.

so if you wanted to remove the Services tab for logged in users...

	if (!is_null($primaryNavbar->getChild('Services'))) {
		$primaryNavbar->removeChild('Services');
	}

that works because it checks to see of the parent exists, and only if it does, does it try to remove it - so for a non-client, it wouldn't get past the if statement.

19 hours ago, isixhosting said:

For example I will add the "Knowledge Base" again there or "Affiliates" which is missing or completely a new menu item with some "childs".

for kb, see above; for affiliates, I solved the issue by only removing it for non-logged in users - for new menu items, see above (re: kb and how I added the non-logged in parents with their kids).

Link to comment
Share on other sites

 

1 hour ago, isixhosting said:

I think WE all who are using @brian! s great codes/tweaks and other helpfull stuff

Sure, but there is a massive users that also using those code and we never see them here because they only comes here without login. I think perhaps I am who spent more time logged in this community. Average daily logged in users perhaps less than 30...

image.thumb.png.65438c6669b40ba1ef20c98702cfcaaa.png

1 hour ago, isixhosting said:

we should make some donation to him

Would be great if a community guidelines cover something like that (regarding donations), making it not be treated hidden on inbox (guidelines I guess do not allow that 3.4), while it would not be known after several posts and even new users. Perhaps 90% of users on community knows Brian or have a see their posts more then all of community staff. If you have a suggestions feel free.

1 hour ago, isixhosting said:

not just hitting the "LIKE BUTTON". Shouldn't we?

While donation did not start working, Like button is the fastest way to be courteousness for someone spent their time and share their precious knowledge in most cases with strange.

If you have a idea in mind, please share it with us, perhaps we found a balance.👍

 

Link to comment
Share on other sites

12 hours ago, zitu4life said:

Sure, but there is a massive users that also using those code and we never see them here because they only comes here without login. I think perhaps I am who spent more time logged in this community. Average daily logged in users perhaps less than 30...

I wouldn't worry about that - i'm in control of what I decide to post here, especially when it comes to hooks and code - anything "clever", or commercially sensitive/valuable simply doesn't get posted publicly anymore... which on one level is a real shame, but on the other hand, "developers" were happily selling the unaltered code as their own work... helping users is one thing, subsidising a living to those who do no real work to justify it is another matter - i'm wise to what's going on here (on a whole number of levels!)... I could go further, but I would expect this thread to get nuked/locked, so i'll take my auto screenshot and leave it there. 📸

links to old hooks, or tweaks of those old hooks is fine... as is (especially) helping someone who at least had a go at doing it themselves... and new hooks that are only a few lines long on variations i've already written.

off-topic, I was wandering through the file structure today and found a new undocumented feature - well it's got a throwaway line mention in the v7.10 changelog, but nothing obvious in the release notes... but at it's core is code that I effectively posted here years ago... that warmed the cockles of my heart to see that! in years gone by, i'd have posted a tutorial about using that feature (as it's ripe for exploitation and enhancement)... no point these days. 🙁

sadly, there are often threads I can answer, but to do so, would likely need me to share commercially written code... so they often get bookmarked until I can think of a convenient solution for all.... aagh, just about to reply to one of them.

there is a reason why there are so few knowledgeable users replying to threads here - it takes time, knowledge and inclination - and sadly it's a rare (dying) breed that has all three.

WHMCS life was oh so much simpler, and fun, years ago... sighs.. it really was fun here once... I miss having sentq around the place to share the load.

14 hours ago, zitu4life said:

Would be great if a community guidelines cover something like that (regarding donations), making it not be treated hidden on inbox (guidelines I guess do not allow that 3.4),

3.4 wouldn't be an issue - that's more to stop users spamming each other via the PM, e.g sending unsolicited PMs saying "have you heard about my new telepathic navbar menu hook generating addon - if interested, click here" (the link is fake, nobody get excited!) 😲

I would expect donations to be a private issue between the two parties that WHMCS wouldn't want to get involved in - maybe I should just add a PayPal donate button to my signature! 🤑

15 hours ago, zitu4life said:

Perhaps 90% of users on community knows Brian or have a see their posts more then all of community staff. If you have a suggestions feel free.

90% ? everyone should know my name! ("Cheers!" theme reference!) 🎵

9 hours ago, isixhosting said:

with your help, this has now been done with a great result.

it looks good! 😎

btw - one of the quirks of Lagom, and to an extent Six, is that there can often be no clear way to become an affiliate - so on your site, users that are not logged in can't see the affiliate link - so how do they become affiliates? even if they find the link, they would need to log in, but they might not be able to login because they're not users... and without the registration page, you can't become an affiliate without buying something first... vicious circle!

Link to comment
Share on other sites

1 hour ago, brian! said:

btw - one of the quirks of Lagom, and to an extent Six, is that there can often be no clear way to become an affiliate - so on your site, users that are not logged in can't see the affiliate link - so how do they become affiliates? even if they find the link, they would need to log in, but they might not be able to login because they're not users... and without the registration page, you can't become an affiliate without buying something first... vicious circle!

That's absolutelly right and I know about this "odd" circle a long time. Now I did it in this way:

1. removed the default affiliate menu item

2. created a new page with an "Activate Affiliate" button/link to Affiliate support departement

3. The customer has to send a request message with his personal and contact details

4. we will create an account for him and it will be sent a welcome message to him with login credentials

And by this long "way" just because of the fact you described above. Leaving the option for registration of non customers enabled is a faith with spammers.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated