| 1 |
<?php |
| 2 |
/** |
| 3 |
* Alert Trigger abstract class. |
| 4 |
* |
| 5 |
* @package WP_Stream |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Stream; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class Alert_Trigger |
| 12 |
* |
| 13 |
* @package WP_Stream |
| 14 |
*/ |
| 15 |
abstract class Alert_Trigger { |
| 16 |
|
| 17 |
/** |
| 18 |
* Holds instance of plugin object |
| 19 |
* |
| 20 |
* @var Plugin |
| 21 |
*/ |
| 22 |
public $plugin; |
| 23 |
|
| 24 |
/** |
| 25 |
* Unique identifier |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public $slug; |
| 30 |
|
| 31 |
/** |
| 32 |
* Class constructor |
| 33 |
* |
| 34 |
* @param Plugin $plugin Instance of plugin object. |
| 35 |
*/ |
| 36 |
public function __construct( $plugin ) { |
| 37 |
$this->plugin = $plugin; |
| 38 |
|
| 39 |
add_action( 'wp_stream_alert_trigger_form_display', array( $this, 'add_fields' ), 10, 2 ); |
| 40 |
add_action( 'wp_stream_alert_trigger_form_save', array( $this, 'save_fields' ), 10, 1 ); |
| 41 |
add_filter( 'wp_stream_alert_trigger_check', array( $this, 'check_record' ), 10, 4 ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Checks if a record matches the criteria from the trigger. |
| 46 |
* |
| 47 |
* @filter wp_stream_alert_trigger_check |
| 48 |
* |
| 49 |
* @param bool $success Status of previous checks. |
| 50 |
* @param int $record_id Record ID. |
| 51 |
* @param array $recordarr Record data. |
| 52 |
* @param Alert $alert The Alert being worked on. |
| 53 |
* @return bool False on failure, otherwise should return original value of $success. |
| 54 |
*/ |
| 55 |
abstract public function check_record( $success, $record_id, $recordarr, $alert ); |
| 56 |
|
| 57 |
/** |
| 58 |
* Adds fields to the trigger form. |
| 59 |
* |
| 60 |
* @action wp_stream_alert_trigger_form_display |
| 61 |
* |
| 62 |
* @param Form_Generator $form The Form Object to add to. |
| 63 |
* @param Alert $alert The Alert being worked on. |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
abstract public function add_fields( $form, $alert ); |
| 67 |
|
| 68 |
/** |
| 69 |
* Validate and save Alert object |
| 70 |
* |
| 71 |
* @action wp_stream_alert_trigger_form_save |
| 72 |
* |
| 73 |
* @param Alert $alert The Alert being worked on. |
| 74 |
* @return void |
| 75 |
*/ |
| 76 |
abstract public function save_fields( $alert ); |
| 77 |
|
| 78 |
/** |
| 79 |
* Returns the trigger's value for the given alert. |
| 80 |
* |
| 81 |
* @param string $context The location this data will be displayed in. |
| 82 |
* @param Alert|null $alert Alert being processed. |
| 83 |
* @return string |
| 84 |
*/ |
| 85 |
abstract public function get_display_value( $context = 'normal', $alert = null ); |
| 86 |
|
| 87 |
/** |
| 88 |
* Allow connectors to determine if their dependencies is satisfied or not |
| 89 |
* |
| 90 |
* @return bool |
| 91 |
*/ |
| 92 |
public function is_dependency_satisfied() { |
| 93 |
return true; |
| 94 |
} |
| 95 |
} |
| 96 |
|