| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abstract Trigger Class |
| 4 |
* |
| 5 |
* @package WPbot_Automator |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPbot_Automator\Triggers; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Abstract Class Trigger |
| 16 |
*/ |
| 17 |
abstract class Trigger { |
| 18 |
|
| 19 |
/** |
| 20 |
* Trigger ID |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
protected $id; |
| 25 |
|
| 26 |
/** |
| 27 |
* Trigger Title |
| 28 |
* |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
protected $title; |
| 32 |
|
| 33 |
/** |
| 34 |
* Trigger Group (e.g., 'WordPress', 'WooCommerce') |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
protected $group; |
| 39 |
|
| 40 |
/** |
| 41 |
* Get Trigger ID |
| 42 |
*/ |
| 43 |
public function get_id() { |
| 44 |
return $this->id; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get Trigger Title |
| 49 |
*/ |
| 50 |
public function get_title() { |
| 51 |
return $this->title; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get Trigger Group |
| 56 |
*/ |
| 57 |
public function get_group() { |
| 58 |
return $this->group; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Register the trigger (hooks) |
| 63 |
*/ |
| 64 |
abstract public function register(); |
| 65 |
|
| 66 |
/** |
| 67 |
* Process the trigger execution |
| 68 |
* |
| 69 |
* @param array $data Data passed from the hook. |
| 70 |
*/ |
| 71 |
protected function run( $data = array() ) { |
| 72 |
// This will call the Workflow Engine to find and run matching workflows. |
| 73 |
$full_trigger_id = $this->id; |
| 74 |
if ( isset( $data['sub_id'] ) ) { |
| 75 |
$full_trigger_id .= ':' . $data['sub_id']; |
| 76 |
} |
| 77 |
|
| 78 |
\WPbot_Automator\Engine\Workflow_Runner::run_workflows_for_trigger( $full_trigger_id, $data['data'] ); |
| 79 |
} |
| 80 |
} |
| 81 |
|