Do you want to use filters so you can determine which actions need to be performed and the others ignored? You can create Filters to execute selective actions in Thrive Automator.
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
To create your own Filter
you need to extend ThriveAutomatorItemsFilter
and implement the required basic methods.
abstract public static function get_id(): string
– should return a unique identifier that will be used together with theData_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 theData_Field
value and should returntrue
orfalse
.
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
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.