trolling Posted February 9, 2022 Share Posted February 9, 2022 Hi, I'm writing this post because i have problems when i use my hook. I have tested all the things we can do with hooks and I have the same ending and a similar errors . For an exemple and show you what was the problem, I took the hook who can move down an child item. That doesn't work corretly and the site crashes. I'm putting here the error message : Error: Call to a member function getChild() on null in /var/www/html/includes/hooks/testhook.php:6 Stack trace: #0 /var/www/html/vendor/whmcs/whmcs-foundation/lib/Hook/Manager.php(0): WHMCS\Utility\SafeInclude::{closure}() #1 /var/www/html/vendor/illuminate/support/Facades/Facade.php(261): WHMCS\Hook\Manager->run() #2 /var/www/html/includes/functions.php(0): Illuminate\Support\Facades\Facade::__callStatic() #3 /var/www/html/vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): run_hook() #4 /var/www/html/vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): WHMCS\ClientArea->outputWithoutExit() #5 /var/www/html/vendor/whmcs/whmcs-foundation/lib/Http/Message/AbstractViewableResponse.php(0): WHMCS\ClientArea->getOutputContent() #6 /var/www/html/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(41): WHMCS\Http\Message\AbstractViewableResponse->getBody() #7 /var/www/html/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(31): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emitBody() #8 /var/www/html/clientarea.php(0): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emit() #9 {main} I followed this doc https://developers.whmcs.com/themes/navigation/ I'm entering correctly the name of menu items but I don't know why that doesn't works. Here is my code if somebody could help me : use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) { $primarySidebar->getChild('Account')->getChild('Edit Account Details')->moveUp(); }); 0 Quote Link to comment Share on other sites More sharing options...
Evolve Web Hosting Posted April 20, 2022 Share Posted April 20, 2022 Sorry I don't know the exact answer but I think it has to use the 'order' function. I never had any luck with the code you're trying to use (caused a site error too). 0 Quote Link to comment Share on other sites More sharing options...
LosBooom Posted April 25, 2022 Share Posted April 25, 2022 $account = $primarySidebar->getChild('Account'); if (!is_null($account)) { $accountDetails = $account->getChild('Edit Account Details'); if (!is_null($account)) { $accountDetails->moveUp(); } } Somewhat late, but it will be useful for history. You must check for the existence of objects before calling them. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted April 25, 2022 Share Posted April 25, 2022 1 hour ago, LosBooom said: $account = $primarySidebar->getChild('Account'); if (!is_null($account)) { $accountDetails = $account->getChild('Edit Account Details'); if (!is_null($account)) { $accountDetails->moveUp(); } } Somewhat late, but it will be useful for history. You must check for the existence of objects before calling them. In addition to this reply, you need to check the correct Menu Name (documentation shows how). If you are trying to getChild() of a menu name that doesn’t exist, you will get the mentioned error (of null). You need to start from parent, then to child. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.