Jump to content

WHMCS Hooks, Global vars and includes


anderbytes

Recommended Posts

Hello folks, I hope someone can help me.

I'm a bit paranoid about organization and good standards of coding, and I've encountered a situation I couldn't find a solution in WHMCS.

I have several hooks with needs of constants to define customfields easily, the client ID used for testing, some API key, and other...

Today I'm forced to, inside the hook function, declare always the $var being used explicitely across the hook, because if I declare it outside, try to global it inside function, it won't recognize it.

Also.. my idea was to have a SINGLE Constants.php outside every hook php file, and have it included. Couldn't make it work either.

 

Has anyone succeded in that?

 

Link to comment
Share on other sites

It sounds like what you need is a custom include file specifically for those things (API key, etc). Typically, something like this would go in the software's configuration file, but WHMCS doesn't like to play nice with other development tools and things will break if you do that. So, you'll want to create your own... Say, call it customconfig.php or something. Then, in all your hooks , you can simply include the file from there, and use global $varname; at the top of the hook function you want to use.

 

If you put customconfig.php in whmcs/includes/hooks, you won't even have to call the file as an include, it should (in theory) be already loaded in. 

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