Skip to content

Commit

Permalink
allow filtering fields, actions, and triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
picocodes committed Oct 15, 2023
1 parent b03b09c commit 8a80a17
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
41 changes: 38 additions & 3 deletions src/Objects/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public function __construct() {
public function load_automation_rules( $rules ) {

// Register triggers.
foreach ( $this->get_triggers() as $key => $args ) {
foreach ( $this->get_all_triggers() as $key => $args ) {
$rules->add_trigger(
new Trigger( $key, $args, $this )
);
}

// Register actions.
foreach ( $this->get_actions() as $key => $args ) {
foreach ( $this->get_all_actions() as $key => $args ) {
$rules->add_action(
new Action( $this->type, $key, $args )
);
Expand All @@ -100,14 +100,25 @@ public function get_triggers() {
return array();
}

/**
* Retrieves all filtered triggers.
*
*/
public function get_all_triggers() {
return apply_filters(
'noptin_object_triggers_' . $this->type,
$this->get_triggers(),
$this
);
}

/**
* Triggers actions.
*
* @param string $trigger The trigger name.
* @param array $args The trigger args.
*/
public function trigger( $trigger, $args ) {
noptin_error_log( $args, $trigger );
do_action( 'noptin_fire_object_trigger_' . $trigger, $args );
}

Expand All @@ -120,12 +131,36 @@ public function get_actions() {
return array();
}

/**
* Retrieves all filtered actions.
*
*/
public function get_all_actions() {
return apply_filters(
'noptin_object_actions_' . $this->type,
$this->get_actions(),
$this
);
}

/**
* Retrieves available fields.
*
*/
abstract public function get_fields();

/**
* Retrieves all filtered fields.
*
*/
public function get_all_fields() {
return apply_filters(
'noptin_object_fields_' . $this->type,
$this->get_fields(),
$this
);
}

/**
* Retrieves a single record.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function fields( $type ) {
return array();
}

return $collection->get_fields();
return $collection->get_all_fields();
}

/**
Expand Down

0 comments on commit 8a80a17

Please sign in to comment.