| 1 |
<?php |
| 2 |
/** |
| 3 |
* Integration Action |
| 4 |
* |
| 5 |
* @package AutomatorWP\Classes\Integration_Action |
| 6 |
* @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
class AutomatorWP_Integration_Action { |
| 13 |
|
| 14 |
/** |
| 15 |
* Integration |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
* |
| 19 |
* @var string $integration |
| 20 |
*/ |
| 21 |
public $integration = ''; |
| 22 |
|
| 23 |
/** |
| 24 |
* Trigger |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
* |
| 28 |
* @var string $action |
| 29 |
*/ |
| 30 |
public $action = ''; |
| 31 |
|
| 32 |
/** |
| 33 |
* Filter result |
| 34 |
* |
| 35 |
* @since 1.0.0 |
| 36 |
* |
| 37 |
* @var string $result |
| 38 |
*/ |
| 39 |
public $result = ''; |
| 40 |
|
| 41 |
public function __construct() { |
| 42 |
|
| 43 |
$this->hooks(); |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Register required hooks |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
*/ |
| 52 |
public function hooks() { |
| 53 |
|
| 54 |
if ( ! did_action( 'automatorwp_init' ) ) { |
| 55 |
// Default hook to register |
| 56 |
add_action('automatorwp_init', array( $this, 'register' ) ); |
| 57 |
add_action('init', array( $this, 'register_labels' ) ); |
| 58 |
} else { |
| 59 |
// Hook for triggers registered from the theme's functions |
| 60 |
add_action( 'after_setup_theme', array( $this, 'register' ) ); |
| 61 |
} |
| 62 |
|
| 63 |
// Execute action hook |
| 64 |
//add_action( 'automatorwp_execute_action', array( $this, 'maybe_execute' ), 10, 5 ); |
| 65 |
// NOTE: Needs to run on "maybe_execute" to pass correctly the arguments |
| 66 |
add_action( 'automatorwp_execute_action_' . $this->action, array( $this, 'maybe_execute' ), 10, 5 ); |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Register the action |
| 72 |
* |
| 73 |
* @since 1.0.0 |
| 74 |
*/ |
| 75 |
public function register() { |
| 76 |
// Override |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Register again to update labels (due to textdomain init requirement) |
| 81 |
* |
| 82 |
* @since 1.0.0 |
| 83 |
*/ |
| 84 |
public function register_labels() { |
| 85 |
$this->register(); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Checks if maybe should call or not to the execute() function |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
* |
| 93 |
* @param stdClass $action The action object |
| 94 |
* @param int $user_id The user ID |
| 95 |
* @param array $event Event information |
| 96 |
* @param array $action_options The action's stored options (with tags already passed) |
| 97 |
* @param stdClass $automation The action's automation object |
| 98 |
*/ |
| 99 |
public function maybe_execute( $action, $user_id, $event, $action_options, $automation ) { |
| 100 |
|
| 101 |
// Bail if action type don't match this action |
| 102 |
if( $action->type !== $this->action ) { |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
$this->execute( $action, $user_id, $action_options, $automation ); |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Action execution function |
| 112 |
* |
| 113 |
* @since 1.0.0 |
| 114 |
* |
| 115 |
* @param stdClass $action The action object |
| 116 |
* @param int $user_id The user ID |
| 117 |
* @param array $action_options The action's stored options (with tags already passed) |
| 118 |
* @param stdClass $automation The action's automation object |
| 119 |
*/ |
| 120 |
public function execute( $action, $user_id, $action_options, $automation ) { |
| 121 |
// Override |
| 122 |
} |
| 123 |
|
| 124 |
} |