SimplyDigitalHosting Posted January 6, 2013 Share Posted January 6, 2013 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. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS JamesX Posted January 7, 2013 Share Posted January 7, 2013 (edited) 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 January 7, 2013 by WHMCS JamesX 0 Quote Link to comment Share on other sites More sharing options...
SimplyDigitalHosting Posted January 7, 2013 Author Share Posted January 7, 2013 I definitely could be mistaken. Regardless this is dual purpose as now you can make your own "hooks" in your scripts since this is open source and not encoded. It worked for what I needed and we will be using with all addons we release so it does have its uses . 0 Quote Link to comment Share on other sites More sharing options...
WHMCS JamesX Posted January 7, 2013 Share Posted January 7, 2013 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. 0 Quote Link to comment Share on other sites More sharing options...
SimplyDigitalHosting Posted January 7, 2013 Author Share Posted January 7, 2013 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 . 0 Quote Link to comment Share on other sites More sharing options...
disgruntled Posted May 18, 2013 Share Posted May 18, 2013 (edited) 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 May 18, 2013 by disgruntled 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted July 19, 2021 Share Posted July 19, 2021 This doesnt work any more, so I submitted this as an idea to whmcs, maybe we can get some votes and get this done... https://requests.whmcs.com/idea/hook-return-issues-including-more-then-one-hook-point-compatibility-and-changes-to-smarty-variables 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.