Jump to content

Addon Hook


TeleMagic

Recommended Posts

Hi Guys

 

I am writing a custom addon hook to execute when a product Addon is Activated.

 

I have a hook that pulls $vars as a variable aray for the function. Now in the documentation here

http://docs.whmcs.com/Hooks:Addons

it shows just 4 variables passed is that just the specific variables?

 

Would it also pass things like serverusername, serverpassword etc the same as the module I created for the main product?

 

Also is there any way of passing debug information from a hook? Can I place a Die in the script?

 

Regards

Link to comment
Share on other sites

AddonActivation hook point gives you the following vars:

 

id - the ID of the addon service (tblhostingaddons.id)

userid - the client ID (tblclients.id)

serviceid - the ID of the product/service it is tied to (tblhosting.id)

addonid - the ID of the predefined addon it is assigned to (tbladdons.id)

With these variables you can literally retrieve everything you want. Simply play around with some JOIN to get the things done. You should JOIN userid/serviceid with tblhosting where you can get both server username and password.

Link to comment
Share on other sites

Also you can use Internal API functions inside you hook.

$command = "decryptpassword";
$adminuser = "admin";
$values["password2"] = "xxxxxx";

$results = localAPI($command,$values,$adminuser);

With this one you can retreive the client password.

$command = "getclientpassword";
$adminuser = "admin";
$values["userid"] = "1";

$results = localAPI($command,$values,$adminuser);

Link to comment
Share on other sites

Thats great.

 

Now how do I debug this hook. I have written the code which I think will do what I want but it does not seem to be doing anything?

 

How do I veryify and debug if the hook is actualling being called? And then if it is debug the actual hook code?

 

Regards

Link to comment
Share on other sites

In this case try with the brute way. Remove everything inside your function and just leave a mailto or an header to google.com. If you can't get the email or if you aren't redirected to Google probably you are referring in a wrong way to your function or you are using a wrong hook point. Please post the line you use to call your function.

Link to comment
Share on other sites

Something like this

function YourFunction($vars)
{
$to = "yourmail@example.com";
$subject = "Hello, i'm the hook!";
$message = "I'm fine";
$from = "whatever@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}

add_hook("AddonActivation",1,"YourFunction");

Link to comment
Share on other sites

Thanks for the Help Kian

 

I said it would be a schoolboy error, I wasnt expecting it to be something quite as stupid as it was though.

 

There was nothing wrong with the code or my hook, it actually worked first time, which is pretty good as I am not really a programmer and until last week when I started doing my VOIP modules for WHMCS had only ever done basic hacks to php scripts.

 

The only issue is that I was working on the wrong version of WHMCS. I have 2 dev licenses for 2 dev sites to keep code seperated between 2 groups of developers I freelance work to. I was working on the module code on one and trying to get it to execute by purchasing a product add-on on the other!

 

DOH!!!

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