A Trigger will be executed at all times, but there are cases in which we might not want to run the action. The main purpose of a Filter is to decide whether we want to run an action or not, based on the data we have.

Creating your first filter

In order to create your own Filter you need to extend Thrive\Automator\Items\Filter and implement the required basic methods.

  • abstract public static function get_id(): string - should return a unique identifier that will be used together with the Data_Object. To avoid conflicts or overwrites we suggest using a prefix.

public static function get_id(): string { 
return 'wp/user-filter';
}
  • abstract public static function get_name(): string - should return a string containing the name of the filter.

public static function get_name(): string { 
return 'User filter';
}
  • abstract public static function get_operators(): array - returns an array of operators that will be used in the admin UI when setting the automation.

public static function get_operators(): array { 
return [
'new' => [
'label' => 'is fresh user',
],
'old' => [ 'label' => 'is old user',
],
];
}
  • abstract public static function filter( $data ): bool - this method receives as parameter an array of $data from the Data_Field value and should return true or false.

public static function filter( $data ): bool { 
//verifications and validations
return true;
}

Other methods

  • abstract public static function prepare_data( $data ) - receives the data that was set when creating the automation and saves it on the instance so it can be compared later.

public static function prepare_data( $data ) { 
if ( isset( $data['value'] ) ) {
$this->value = $data['value'];
}
}

Registering the filter

In order to register a Filter so it can be used inside an automation, we should use the thrive_automator_register_filter function which receives as the only parameter, the class name.

Did this answer your question?