Variables Available Within Hooks

A number of pre-determined vairables containing all the necessary information about the hook that was run, the task that triggered the hook, and the resulting data from the task are available in our PHP hook scripts.

Variables Always In The $data Array Before and After Hooks

Key Value Type
_task - array
_task['trigger'] The task that triggered the hook. string
_task['when'] 1 = before task ran; 2 = after task ran integer
_task['specific_trigger'] If a specific form or product was required to trigger the hook, this will contain the ID of the trigger. integer
_task['hook_id'] Database ID of the hook that ran. integer
_task['plugin'] Unique identifier of the plugin with which the hook is associated. If a plugin triggered the hook, you will have access to the plugin's methods anywhere in the hook's code using the $plugin variable. You can learn more about plugins here. string
<?php

var_dump($data['_task']);

echo $data(['_task']['plugin']); // Might output something like "twilio" if the twilio plugin owns the hook.

Available Variables In After Hooks

The additional keys held within the $data array vary based on which hook triggered the task, so you will have to reference each hook type individually to see what other keys are available in the array.

So for a "Member Created" hook, the $data array might look like this:

<?php

var_dump($data);

/*
array(7) {
  ["_task"]=>
  array(5) {
    ["trigger"]=>
    string(13) "member_create"
    ["when"]=>
    string(1) "2"
    ["specific_trigger"]=>
    string(16) "register-6701939"
    ["hook_id"]=>
    string(2) "38"
    ["plugin"]=>
    NULL
  }
  ["member_id"]=>
  string(16) "RETW-26868-42435"
  ["tracking_id"]=>
  string(0) ""
  ["data"]=>
  array(143) {
    ["id"]=>
    string(16) "RETW-26868-42435"
    [0]=>
    string(16) "RETW-26868-42435"
    ["username"]=>
    string(7) "test123"
    [1]=>
    string(7) "test123"
    ["password"]=>
    string(40) "842b704ae8dc6fd00e13786a14b2a5dca7d25bc4"
    [2]=>
    string(40) "842b704ae8dc6fd00e13786a14b2a5dca7d25bc4"
    ["salt"]=>
    string(4) "^sAO"
    [3]=>
    string(4) "^sAO"
    ["email"]=>
    string(17) "test@castlamp.com"
    [4]=>
    string(17) "test@castlamp.com"
    ["bounce_notice"]=>
    string(19) "0000-00-00 00:00:00"
    [5]=>
    string(19) "0000-00-00 00:00:00"
    ["joined"]=>
    string(19) "2018-07-18 18:27:15"
    [6]=>
    string(19) "2018-07-18 18:27:15"
    ["last_renewal"]=>
    string(19) "2018-07-18 18:27:15"
    [7]=>
    string(19) "2018-07-18 18:27:15"
    ["last_action"]=>
    string(19) "2018-07-18 18:27:15"
    [8]=>
    string(19) "2018-07-18 18:27:15"
    ["last_login"]=>
    string(19) "0000-00-00 00:00:00"
    [9]=>
    string(19) "0000-00-00 00:00:00"
    ["last_updated"]=>
    string(19) "2018-07-18 18:27:15"
    [10]=>
    string(19) "2018-07-18 18:27:15"
    ["last_date_check"]=>
    string(19) "2018-07-18 18:27:15"
    [11]=>
    string(19) "2018-07-18 18:27:15"
    ["next_action"]=>
    string(19) "0000-00-00 00:00:00"
    [12]=>
    string(19) "0000-00-00 00:00:00"
    ["last_updated_by"]=>
    string(0) ""
    [13]=>
    string(0) ""
    ["status"]=>
    string(1) "A"
    [14]=>
    string(1) "A"
    ["status_msg"]=>
    string(0) ""
    [15]=>
    string(0) ""
    ["conversion_id"]=>
    string(1) "0"
    [16]=>
    string(1) "0"
    ["source"]=>
    string(2) "12"
    [17]=>
    string(2) "12"
    ["concurrent_login_notices"]=>
    string(1) "0"
    [18]=>
    string(1) "0"
    ["concurrent_login_date"]=>
    string(19) "0000-00-00 00:00:00"
    [19]=>
    string(19) "0000-00-00 00:00:00"
    ["public"]=>
    string(1) "0"
    [20]=>
    string(1) "0"
    ["owner"]=>
    string(1) "2"
    [21]=>
    string(1) "2"
    ["email_pref"]=>
    string(4) "html"
    [22]=>
    string(4) "html"
    ["locked"]=>
    string(19) "0000-00-00 00:00:00"
    [23]=>
    string(19) "0000-00-00 00:00:00"
    ["locked_ip"]=>
    string(0) ""
    [24]=>
    string(0) ""
    ["login_attempts"]=>
    string(1) "0"
    [25]=>
    string(1) "0"
    ["account"]=>
    string(10) "GEN_MEMBER"
    [26]=>
    string(10) "GEN_MEMBER"
    ["email_optout"]=>
    string(1) "0"
    [27]=>
    string(19) "0000-00-00 00:00:00"
    ["sms_optout"]=>
    string(1) "0"
    [28]=>
    string(19) "0000-00-00 00:00:00"
    ["activation_code"]=>
    string(0) ""
    [29]=>
    string(0) ""
    ["activated"]=>
    string(19) "0000-00-00 00:00:00"
    [30]=>
    string(19) "0000-00-00 00:00:00"
    ["start_page"]=>
    string(0) ""
    [31]=>
    string(0) ""
    ["converted"]=>
    string(1) "0"
    [32]=>
    string(1) "0"
    ["converted_id"]=>
    string(1) "0"
    [33]=>
    string(1) "0"
    ["listing_display"]=>
    string(1) "0"
    [34]=>
    string(1) "0"
    ["member_type"]=>
    string(1) "1"
    [35]=>
    string(1) "1"
    ["member_id"]=>
    string(16) "RETW-26868-42435"
    [36]=>
    string(16) "RETW-26868-42435"
    ["first_name"]=>
    string(7) "jwefoij"
    [37]=>
    string(7) "jwefoij"
    ["last_name"]=>
    string(6) "oijoij"
    [38]=>
    string(6) "oijoij"
    ["address_line_1"]=>
    NULL
    [39]=>
    NULL
    ["address_line_2"]=>
    NULL
    [40]=>
    NULL
    ["city"]=>
    NULL
    [41]=>
    NULL
    ["state"]=>
    NULL
    [42]=>
    NULL
    ["zip"]=>
    NULL
    [43]=>
    NULL
    ["country"]=>
    NULL
    [44]=>
    NULL
    ["phone"]=>
    NULL
    [45]=>
    NULL
    ["fax"]=>
    NULL
    [46]=>
    NULL
    [47]=>
    string(1) "0"
    [48]=>
    string(1) "0"
    ["dob"]=>
    string(10) "0000-00-00"
    [49]=>
    string(10) "0000-00-00"
    ["industry"]=>
    string(0) ""
    [50]=>
    string(0) ""
    ["facebook"]=>
    string(0) ""
    [51]=>
    string(0) ""
    ["twitter"]=>
    string(0) ""
    [52]=>
    string(0) ""
    ["linkedin"]=>
    string(0) ""
    [53]=>
    string(0) ""
    ["cell"]=>
    string(0) ""
    [54]=>
    string(0) ""
    ["cell_carrier"]=>
    string(0) ""
    [55]=>
    string(0) ""
    ["alt_phone"]=>
    string(0) ""
    [56]=>
    string(0) ""
    ["office_phone"]=>
    string(0) ""
    [57]=>
    string(0) ""
    ["cvv"]=>
    NULL
    [58]=>
    NULL
    ["director_2078"]=>
    NULL
    [59]=>
    NULL
    ["company_name"]=>
    string(0) ""
    [60]=>
    string(0) ""
    ["url"]=>
    string(0) ""
    [61]=>
    string(0) ""
    ["occupation"]=>
    string(0) ""
    [62]=>
    string(0) ""
    ["bank_account_number"]=>
    NULL
    [63]=>
    NULL
    ["budget_97628"]=>
    NULL
    [64]=>
    NULL
    ["test_field"]=>
    NULL
    [65]=>
    NULL
    ["test_fie_87373"]=>
    NULL
    [66]=>
    NULL
    ["dawns_field"]=>
    NULL
    [67]=>
    NULL
    ["eligibility_group"]=>
    NULL
    [68]=>
    NULL
    ["eligibility_group_search"]=>
    NULL
    [69]=>
    NULL
    ["referral_24227"]=>
    NULL
    [70]=>
    NULL
    ["show_status"]=>
    string(91) "<a href="null.php" onclick="return popup('activate','id=');" id="member-status-">Active</a>"
    ["status_read"]=>
    string(6) "Active"
    ["mtype"]=>
    string(15) "Standard Member"
  }
  ["raw_data"]=>
  array(3) {
    ["member"]=>
    array(22) {
      ["username"]=>
      string(7) "test123"
      ["password"]=>
      string(7) "pass123"
      ["first_name"]=>
      string(7) "jwefoij"
      ["last_name"]=>
      string(6) "oijoij"
      ["email"]=>
      string(17) "test@castlamp.com"
      ["address_line_1"]=>
      string(0) ""
      ["address_line_2"]=>
      string(0) ""
      ["city"]=>
      string(0) ""
      ["state"]=>
      string(0) ""
      ["zip"]=>
      string(0) ""
      ["country"]=>
      string(0) ""
      ["id"]=>
      string(16) "RETW-26868-42435"
      ["source"]=>
      string(2) "12"
      ["account"]=>
      string(10) "GEN_MEMBER"
      ["status"]=>
      string(1) "A"
      ["member_type"]=>
      string(1) "1"
      ["last_updated"]=>
      string(19) "2018-07-18 18:27:15"
      ["last_renewal"]=>
      string(19) "2018-07-18 18:27:15"
      ["last_action"]=>
      string(19) "2018-07-18 18:27:15"
      ["last_login"]=>
      string(19) "2018-07-18 18:27:15"
      ["salt"]=>
      string(4) "^sAO"
      ["joined"]=>
      string(19) "2018-07-18 18:27:15"
    }
    ["content"]=>
    array(1) {
      [0]=>
      array(10) {
        ["id"]=>
        string(1) "5"
        [0]=>
        string(1) "5"
        ["item_id"]=>
        string(7) "6701939"
        [1]=>
        string(7) "6701939"
        ["type"]=>
        string(7) "content"
        [2]=>
        string(7) "content"
        ["grants_to"]=>
        string(2) "11"
        [3]=>
        string(2) "11"
        ["timeframe"]=>
        string(12) "001900000000"
        [4]=>
        string(12) "001900000000"
      }
    }
    ["newsletters"]=>
    array(0) {
    }
  }
  ["password"]=>
  string(7) "pass123"
  ["content"]=>
  array(1) {
    [0]=>
    array(10) {
      ["id"]=>
      string(1) "5"
      [0]=>
      string(1) "5"
      ["item_id"]=>
      string(7) "6701939"
      [1]=>
      string(7) "6701939"
      ["type"]=>
      string(7) "content"
      [2]=>
      string(7) "content"
      ["grants_to"]=>
      string(2) "11"
      [3]=>
      string(2) "11"
      ["timeframe"]=>
      string(12) "001900000000"
      [4]=>
      string(12) "001900000000"
    }
  }
}
*/

Other Variables Available Within the Hook's Code

Variable Description Type
$action Array containing the database row's content for the hook (ppSD_custom_actions) array
$plugin If the hook is part of a plugin, this will return a plugin object that has access to the plugin's classes and methods. plugin object
$member_id The ID of the member or contact that triggered the task. string
$member_type Either "member" or "contact" string to allow you to properly load the member or contact's data (learn more). string
<?php

var_dump($action);

/*
array(26) {
  ["id"]=>
  string(2) "38"
  [0]=>
  string(2) "38"
  ["name"]=>
  string(21) "Test Hook Data Output"
  [1]=>
  string(21) "Test Hook Data Output"
  ["trigger"]=>
  string(13) "member_create"
  [2]=>
  string(13) "member_create"
  ["trigger_type"]=>
  string(1) "0"
  [3]=>
  string(1) "0"
  ["specific_trigger"]=>
  string(0) ""
  [4]=>
  string(0) ""
  ["when"]=>
  string(1) "2"
  [5]=>
  string(1) "2"
  ["type"]=>
  string(1) "1"
  [6]=>
  string(1) "1"
  ["data"]=>
  string(52) "/path/to/test_hook_1.php"
  [7]=>
  string(52) "/path/to/test_hook_1.php"
  ["active"]=>
  string(1) "1"
  [8]=>
  string(1) "1"
  ["owner"]=>
  string(1) "1"
  [9]=>
  string(1) "1"
  ["created"]=>
  string(19) "2018-07-18 18:26:55"
  [10]=>
  string(19) "2018-07-18 18:26:55"
  ["plugin"]=>
  NULL
  [11]=>
  NULL
  ["order"]=>
  NULL
  [12]=>
  NULL
}
*/
<?php

var_dump($plugin);
<?php

echo $member_id;

// ZBHW-63976-54548
<?php

echo $member_type;

// member
// contact

Examples

Reading is one thing, seeing is another. We recommend you take a look at some example hooks to see exactly how this is used.

Last modified 4 months ago.