Adding an item for logged in users with WHMCS
Adding an item for logged in users with WHMCS
With the hooks and menu system available in WHMCS v6, it's entirely possible to have your users see a completely different menu item if they're logged in, as opposed to if they aren't. This quick blog post will guide you through adding an item for logged in users with WHMCS.
As always, if you need assistance, please, do contact us. If you'd like us to modify this for you, or put something similar together for you with our custom development experience? Again, contact us. We're absolutely here to help you out!
The problem:
Sometimes you just want your logged in users to see a link tosomething , but not make it publicly available to everyone else. Even better, sometimes you want the opposite, for your users who aren't logged in to see something , but not show it to your logged in users.Or maybe, you just want your logged in users to be directed to a separate URL. Well, this hook will help you there, too?
The solution:
The following code will assis you with adding an item for logged in users with WHMCS. Save it as a php file in your whmcs/includes/hooks directory . Of course, you want to edit it as necessary
<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
/** @var \WHMCS\User\Client $client */
$client = Menu::context('client');
/*are we logged in?*/
if (!is_null($client)) {
$primaryNavbar->addChild('Menu Name')
->setUri('https://www.example.com/')
->setOrder(70);
}
/*are we logged out?*/
if (is_null($client)) {
$primaryNavbar->addChild('Menu Name 2')
->setUri('https://www.example.com/')
->setOrder(70);
}
});See? Easy as pie. Or cake, if you prefer...
So, how can I use this to redirect to different urls if the client is logged in or not?
I'm glad you asked that. See the 'Menu Name' and 'Menu Name 2' items? Change them to what you want them to be. Then, change the setUri link to be appropriate. The menu item will show up as appropriate.
Reactions
Search
Categories
All Posts
All Categories
Business
7
development
15
News
2
Template modifications
2
Tips and Tricks
7
Uncategorized
2
WHMCS Modifications
17
Tags
Adding 2
Addon 1
Addons 7
Admin 1
Admin Area 5
Ahead 1
API 2
Around 1
Authentication 1
Barely 2
Basics 1
Bumps 1
Business 3
Capsule 1
Certificate 1
Changing 1
Client 1
Client Area 10
Coming 2
Communicating 1
Corner 1
cPanel 1
Cron Jobs 1
Cron Notifications 3
Database 12
development 12
Disabling 1
Discord 1
Display 1
Domain 3
Domains 3
Downs 1
Email 7
Extended 8
Factor 1
Farewell 2
Files 1
Further 1
GDPR 1
Hooks 7
Increase 1
Information 1
Invoice 1
Invoices 5
IP Control 3
Keeping 1
Laravel 3
Licensing 1
Logged 1
Login 1
Major 1
Modifications 1
Modules 10
Mynewaddon 1
MySQL 3
new platform 1
new site 1
News 2
Notification 2
Notification Methods 1
Notifications 9
Notify 10
Notify Extended 20
Password 1
PHP 15
Problem 1
Problems 1
Productivity 1
Pushalot 1
Pushbullet 1
Pushover 3
Queries 3
Quick 2
Renew 1
Renewal 1
Right 1
Schema 1
Security 4
Server 1
Service 1
Serving 1
Slack 2
Sneak 1
Speed 1
SSL 2
Stuff 1
Support Tickets 3
Telegram 2
Template 1
Templates 8
Tickets 8
Tips and Tricks 11
Tools 2
Track 1
Tricks 11
Troubleshooting 2
Twilio 5
Two Factor Authentication 1
Understand 1
Understanding 1
Uniquecolumn 1
updates 1
Upgrade 2
Upgrades 1
Upgrading 1
Username 1
Users 1
v3 1
Webhooks 1
website 1
Welcome 8
WhatsApp 8
WHMCS 51
whmcs guru 1
WHMCS Notify 19
WHMCS Notify Extended 18
WHMCS User 3
WHMCS User and IP Control 3
Wrong 1