Jump to content

WHMCS Action Hooks...Arrays & Variables & Migrains Oh My!


Mike Solstice

Recommended Posts

Ok...so I'm pretty new to WHMCS and PHP in general, trying to learn how to create action hooks. The basic idea here is that after WHMCS runs ModuleCreate which connects to cPanel/WHM, creates the user/domain/etc. it will execute this script to create a mysql database in the newly created user's account.

 

I have everything else working, if I manually put in the username & password, save/upload/execute the script goes off without a hitch. The problem is I can't figure out how to set the variables passed on by the AfterModuleCreate action hook.

 

If I

function create_forum_account($vars) {
    print_r($vars);
}
add_hook("AfterModuleCreate",1,"create_forum_account");

 

then when the account is created I get:

 

Array ( [params] => Array ( [accountid] => 123 [serviceid] => 123 [domain] => example.com [username] => abcdefg [password] => gfedcba [packageid] => 1 [pid] => 1 [serverid] => 1 [customfields] => Array ( ) [configoptions] => Array ( ) [type] => hostingaccount [producttype] => hostingaccount [moduletype] => cpanel [configoption1] => some_hosting_plan [configoption2] => 0 [configoption3] => 10 [configoption4] => 0 [configoption5] => 500 [configoption6] => [configoption7] => [configoption8] => 1 [configoption9] => [configoption10] => 0 [configoption11] => [configoption12] => 0 [configoption13] => x3 [configoption14] => 0 [configoption15] => [configoption16] => [configoption17] => 10 [configoption18] => 500 [configoption19] => [configoption20] => [configoption21] => [configoption22] => [configoption23] => [configoption24] => [clientsdetails] => Array ( [userid] => 10 [id] => 10 [firstname] => Ima [lastname] => Luser [companyname] => My Company [email] => User@Example.com [address1] => 123 Any St [address2] => [city] => Anytown [state] => NV [postcode] => 00000 [country] => US [countryname] => United States [phonenumber] => (702) 555-1212 [notes] => [password] => encrypted_password_here [currency] => 1 [cctype] => [cclastfour] => [securityqid] => 4 [securityqans] => My Answer [groupid] => 0 [status] => Active [credit] => 0.00 [taxexempt] => [latefeeoveride] => [overideduenotices] => [language] => [lastlogin] => No Login Logged [billingcid] => 0 ) [server] => 1 ) ) 

 

And a few other indexes I'm not including here for security purposes.

 

But then if I

$cpanel_user = $vars["username"];
$cpanel_password = $vars["password"];
$cpanel_host = $vars["domain"];

 

I get

Notice: Undefined index: username in /absolute/path/file-to-execute.php on line 8

Notice: Undefined index: password in /absolute/path/file-to-execute.php on line 9

Notice: Undefined index: domain in /absolute/path/file-to-execute.php on line 10

 

In the example action hook that comes with WHMCS $vars["indexname"] supposedly works fine. I've :rtfm: but the WHMCS documentation is absolutely worthless, staff are rude & the forum queens....don't get me started.

 

I hope this makes sense to someone. Any & all help would be greatly appreciated!

Link to comment
Share on other sites

Just to test my understanding, basically what's happening is that AfterModuleCreate is passing on an array within an array, so it's necessary to specify both in the var & b/c I didn't it was only looking at the first array & not finding the index in question? Am I even in the right ballpark here? lol

Link to comment
Share on other sites

  • 1 year later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.