1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85:
<?php
if ( !class_exists( 'Inbound_Automation_Action_Create_Lead' ) ) {
class Inbound_Automation_Action_Create_Lead {
function __construct() {
add_filter( 'inbound_automation_actions' , array( __CLASS__ , 'define_action' ) , 1 , 1);
}
public static function define_action( $actions ) {
$actions['create_lead'] = array (
'class_name' => get_class(),
'id' => 'create_lead',
'label' => __( 'Create Lead' , 'inbound-pro' ),
'description' => __( 'Create a lead from user creation event.' , 'inbound-pro' ),
'settings' => array ()
);
return $actions;
}
public static function run_action( $action , $trigger_data ) {
$args = array();
if ( isset($trigger_data['user_id']) ) {
$user = new WP_User( $trigger_data['user_id'] );
$trigger_data['lead_data']['email'] = $user->data->user_email;
$trigger_data['lead_data']['id'] = LeadStorage::lookup_lead_by_email($trigger_data['lead_data']['email']);
if (!$trigger_data['lead_data']['id']) {
$args = array(
'user_ID' => $trigger_data['user_id'],
'wpleads_email_address' => $trigger_data['lead_data']['email'],
'wpleads_first_name' => $user->data->display_name
);
$trigger_data['lead_data']['id'] = inbound_store_lead( $args );
}
}
inbound_record_log(
__( 'Created Lead' , 'inbound-pro') ,
$trigger_data['lead_data']['id'] . ' <pre>' . print_r($args , true) . '</pre>',
$action['rule_id'] ,
$action['job_id'] ,
'action_event'
);
}
}
new Inbound_Automation_Action_Create_Lead();
}