Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Last active December 22, 2016 21:20
Show Gist options
  • Save atwellpub/11f67b0a5e98271a0bd9e8d4f7bde465 to your computer and use it in GitHub Desktop.
Save atwellpub/11f67b0a5e98271a0bd9e8d4f7bde465 to your computer and use it in GitHub Desktop.
<?php
/*
Trigger Name: WordPress user creation event
Trigger Description: This fires whenever a new user is created
Trigger Author: Inbound Now
Contributors: Hudson Atwell
*/
/* First lets make sure this class is being called nowhere else */
/* When repurpousing this class for a new use please replace User_Register with the appropiate string */
if ( !class_exists( 'Inbound_Automation_Trigger_User_Register' ) ) {
class Inbound_Automation_Trigger_User_Register {
static $trigger; /* static variable containing name of hook to listen for */
/**
* Initiate class
*/
function __construct() {
/* set value of static variable to the hook we want to turn into a trigger */
self::$trigger = 'user_register';
/* Add this filter to list of available filters - no changes here */
add_filter( 'inbound_automation_triggers' , array( __CLASS__ , 'define_trigger' ) , 1 , 1);
}
/**
* This is where we build the trigger definitions
*/
public static function define_trigger( $triggers ) {
/* BELOW WE'LL SETUP THE TRIGGER FITLERS
/* We should know ahead of time what data is passed with the action hook.
/* The bit of code below tells our definition that the action hook user_register has one paramter called user_id
/* we give the argument an id and a label
/* We also wrap the whole thing in a custom filter to allow 3rd parties to edit this information if needed
/* Set & Extend Trigger Argument Filters */
$arguments = apply_filters('trigger/'.self::$trigger.'/trigger_arguments/' , array(
'user_id' => array(
'id' => 'user_id',
'label' => __( 'User ID' , 'inbound-pro')
)
) );
/* BELOW WE'LL SETUP THE ACTION FITLERS */
/* Here we want to defined what action filters are available. When coding them we are calling them db arguments
/* DB arguments are defined as query definitions in a separate PHP file. A separate tutorial example will show how to craft them.
/* Core queries already added include a query to look up information about users and a quer to look up information about leads. The example below enables the user query.
/* We are also wrapping this data in a filter to allow 3rd parties to modify the data for this trigger if needed.
/* Set & Extend Action DB Lookup Filters */
$db_lookup_filters = apply_filters( 'trigger/'.self::$trigger.'/db_arguments' , array (
array(
'id' => 'user_data', /* id of db query */
'label' => __( 'Validate User Data', 'inbound-pro' ), /* label of db query */
'class_name' => 'Inbound_Automation_Query_User' /* class name of query definition */
)
));
/* BELOW WE'LL SETUP WHICH ACTIONS THIS TRIGGER CAN USE */
/* We also wrap this in a filter */
/* Set & Extend Available Actions */
$actions = apply_filters('trigger/'.self::$trigger.'/actions' , array(
'create_lead' ,'add_remove_lead_list','send_email' , 'wait' , 'relay_data'
) );
/* BELOW WE'LL COMPLETE THE TRIGGER DEFINITION */
/* Now setup trigger data */
$triggers[ self::$trigger ] = array (
'label' => __('On new WP user creation' , 'inbound-pro'), /* label for trigger */
'description' => __('This trigger fires whenever new user is created inside the WordPress system.' , 'inbound-pro'), /* description for trigger */
'action_hook' => self::$trigger , /* the action hook to listen to */
'arguments' => $arguments, /* arguments used for trigger filters */
'db_lookup_filters' => $db_lookup_filters, /* queries we can run for this trigger */
'actions' => $actions /* actions we can run for this trigger */
);
return $triggers;
}
}
/* Load Trigger */
$Inbound_Automation_Trigger_User_Register = new Inbound_Automation_Trigger_User_Register;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment