Jump to content

Grab Primary Navbar Object For Logged In Users


Recommended Posts

Hi All,

I am trying to grab the primary (and secondary) navbar for a logged-in user from within my module. I'm trying to pull the object so I can store it for later use. I'm able to grab the navbar for a non-logged in user easily, but for some reason, it's not changing when I set the session UID to a specific client ID and run navbar hooks.

Example:

$_SESSION['uid'] = 1;

$primaryNavbar = Menu::primaryNavbar();
$secondaryNavbar = Menu::secondaryNavbar();

run_hook('ClientAreaPrimaryNavbar', $primaryNavbar);
run_hook('ClientAreaSecondaryNavbar', $secondaryNavbar);

If I try to return the $primaryNavbar, it returns the non-logged in user. Is there a better way to set the user ID and grab what the $primaryNavbar would look like?

Edit: I forgot to mention that I am trying to pull this information into the admin-side of my module, not the client-side (frontend).

Edited by SwiftModders LLC
Link to comment
Share on other sites

Hi there,

Hopefully this will help you, here's how I do it in /includes/hooks/menu.php:

use WHMCS\View\Menu\Item as MenuItem;

/*----------  Navigation Menus  ----------*/
add_hook('ClientAreaNavbars', 1, function () {
    // Get the current navigation bars.
    $primaryNavbar   = Menu::primaryNavbar();
    $secondaryNavbar = Menu::secondaryNavbar();
    // Is client logged in?
    $client = Menu::context('client');
    /*----------  logged in menu customisations  ----------*/
    if (!is_null($client)) {
		// your code here
	}
})

 

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