phpwhmcs

How to get the WHMCS root directory


I have made a simple WHMCS add on that uses the hook function in WHMCS. It works fine on my installation if I use require_once (ROOTDIR.'/modules/addons/module_name/modulefunction.php') because I use a sub domain for my WHMCS. But i tested it on another installation which does not use a sub domain and not it does not work, because the WHMCS directory is not included in the name.

Is there any way for me to get the name of the directory or just go from the hooks folder (includes/hooks/my_hook.php) backwards to the addons directory.

I tried using require_once '../../../modules/addons/module_name/modulefunction.php'; but it just says it cannot find the file.

Error:

Fatal error: require_once(): Failed opening required '../../../modules/addons/module_name/modulefunction.php' (include_path='/home/me/public_html/hosting/vendor/phpseclib/phpseclib/phpseclib:.:/usr/lib/php:/usr/local/lib/php:/usr/local/php/') in /home/me/public_html/hosting/includes/hooks/my_hook.php on line 55

Any assistance would be great :). Thank you.


Solution

  • From the includes/hooks folder, couldn't you just do:

    require_once dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . 'module_name' . DIRECTORY_SEPARATOR . 'modulefunction.php';
    

    I believe the double dirname on the DIR will get you into the root regardless of your installation.