Jump to content

WHMCS Hook Manager


Recommended Posts

This class and associated code was created due to the fact that WHMCS does not allow multiple hooks calls on the same priority, or at-least it seems that way.

The issue comes with encrypted code you can not change. What if two functions were put in the same hook priority? It would not run as expected.

 

This was initially created as I found having 2 hooks calls to "inject" code into a client area page were canceling each other out. Somehow the array argument getting past was getting cleared/reset even when no result was returned from the hook function callback.

This was causing only 1 hook to function properly at a time. It also apparently occurred for that specific hook even on different priorities.

 

So this class solves that issue. You may read the README on the github page for more information and code examples.

 

GitHub: https://github.com/pcfreak30/WHMCS-Hook-Manager

 

Enjoy.

Link to comment
Share on other sites

I have multiple hooks running at the same points with the same priority without issue. However, I do avoid potential conflicts/issues with namespace and such amongst them though. For example, I have several hooks which run at the daily cron point all without issue; they all have a priority of 1.

Edited by WHMCS JamesX
Link to comment
Share on other sites

Perhaps I'm missing something here, but what do you mean by make my own hooks in my own scripts? I can and do do that now; using Action Hook hook points. Or are you referring to my adding hook points to my own software allowing the end-user to create a hook that my software will run at said hook points? If that's the case, while I have no particular need for it, I already can do that easily enough. Regarding the multiple hooks and priorities though, multiple hooks can have the same priority set for the same point.

Link to comment
Share on other sites

I am aware others could create code to do what I did as well. I had an issue, so I came up with my own solution. It may be useful to some so its here for anyone to use.

 

And I was referring to creating a hook point, not just hooking onto a hook's queue/list.

 

The problem I actually originally had was I had two ClientAreaPage hooks modifying data. However when both ran on the same page, only 1 worked at a time. I found that for what ever reason the array getting passed was not the modified version from the last hook call, so data was getting reverted back. I don't know what other hooks acted like this, but I created this as a solution for my code.

 

Hope this can be of use to someone besides me :).

Link to comment
Share on other sites

  • 4 months later...
I found that for what ever reason the array getting passed was not the modified version from the last hook call

 

That is because any modification within a function is done in the local scope. Unless the variable is passed into the function by reference rather than the standard manner of creating a copy then the internal modification is not available outside of the function. This means the second hook, no matter what its priority is does not have access to the changed "copy" of the variable.

 

To pass by reference &$variablename, Bear in mind this does have implications, It alters the original which may not be the desired effect later in the program. you should choose the method that works correctly.

 

Also, If you have two hooks for the same point that work on the same variable, you may be able to combine them both into one hook and thus any internal changes would be accessible in the second part you needed.

 

If you cant, then passing reference is what you need but as i say, be careful with it.

Edited by disgruntled
Link to comment
Share on other sites

  • 8 years later...

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