MACscr Posted March 8, 2019 Share Posted March 8, 2019 So I have a custom hook to run with a order of 0 for ClientAreaPage: add_hook('ClientAreaPage', 0, function($vars) { $_SESSION['foo'] = 'bar'; }); but the problem is that the hook doesnt run before my custom pages own init file and runs right after instead. Any ideas why it doesnt run before the init file is included? The hook creates some $_SESSION values that i need to access from my init.php. Here is a snippet from my custom page: <?php use WHMCS\Database\Capsule; define("CLIENTAREA", true); define("FORCESSL", true); // Uncomment to force the page to use https:// require("init.php"); if ($_GET['client_id'] && $_SESSION['adminid'] > 0 && $_SESSION['uid'] != $_GET['client_id']) { $_SESSION['uid'] = (int)$_GET['client_id']; } $capsule = new Capsule; $ca = new WHMCS_ClientArea(); // add directory where plugins are stored $smarty->addPluginsDir('./custom/smarty_plugins/'); $ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname')); $ca->initPage(); $ca->requireLogin(); $client_id = (int)$ca->getUserID(); if ($client_id == 0) { die('invalid user id'); } $ca->assign('client_id', $client_id); require("custom/init.php"); require("custom/functions.php"); I doubled checked the order by simply doing: var_dump('hook ran'); from the hook and then var_dump('init ran'); from each file/function to see the order it came up on the page. Its definitely not running the hook first. Any suggestions to solve the problem woudl be sincerely appreciated. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 8, 2019 Share Posted March 8, 2019 When you refer to your "init.php" file, do you mean the first one mentioned in your code or the one in the custom folder? I ask as it looks like you are calling WHMCS's init.php file and thus all the code behind it and so your hook would fire. If your init.php is the custom/init.php file, then you need to have the require for that above WHMC's init.php file in the code. 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted March 8, 2019 Author Share Posted March 8, 2019 The first one in the code is the whmcs one. Mine comes after. My init is still somehow running before the hook though. Why would you think my init should come before the whmcs one when the problem is the whmcs hook is running AFTER my init.php code? Now my init can access a bunch of whmcs stuff just fine, its just the problem with the hook timing. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 8, 2019 Share Posted March 8, 2019 Just misread. I tested this and got the expected result but the client area did not display and then troubleshooting that lead to not being able to reproduce the the result. Currently heading off to a biz meeting so can't test this further but will try to later . 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted March 10, 2019 Author Share Posted March 10, 2019 Any luck? I would think this hook would run during the core whmcs init.php. Whatever it is, I need to figure a way to get the hook to consistently run on all whmcs client pages and on my custom pages, before my init runs. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 12, 2019 Share Posted March 12, 2019 I am seeing the same behavior. In a included file and a hook I set a session value and used logmodulecall in both with the session variable being different for each one. The hook's logmodulecall provides the session value that is set in the included file. However, the included files logmodulecall does not provide the hook's session value until after reloading the page. I also tried moving the include after the ca->output() and oddly the logmodulecall isn't even called then for the included file. Could you use an addon module instead of a custom page? 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted March 12, 2019 Author Share Posted March 12, 2019 I have no idea how an addon module would work for something like this. I have a pretty complex platform created around WHMCS with many custom pages created for it. Grr. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 12, 2019 Share Posted March 12, 2019 In the addon module's _clientarea function, you would check for which page you are calling via a variable. So for example, a page of "blah" could either be /m=pages&page=blah where pages is the module name and blah is the actual page. To get a nicer URL, you could use rewrites in .htaccess that rewrite /pages/blah as /m=pages&page=blah internally. That is how the addon modules that make WHMCS a whole site work . So then in the _clientarea function, you could do a if page equals blah, then show this page generated by a template file and info from the database if needed. The advantage of an addon is you could have all the page's html stored in the database or use template files and smarty for example and use the _output function to manage them on the admin side. Also, there is no need for all the init bits for WHMCS as that is taken care of. Addon modules also have their own hooks file, so you can still hook in to events. 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted March 12, 2019 Author Share Posted March 12, 2019 Grr, thats a lot of work. This platform is 3 years old. Must be a proper way to do it through custom pages. 0 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.