1. Home
  2. Knowledge Base
  3. Thrive Automator
  4. Managing Automations
  5. Creating a New Filter in Thrive Automator
  1. Home
  2. Knowledge Base
  3. Developer Documentation
  4. Creating a New Filter in Thrive Automator

Creating a New Filter in Thrive Automator

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 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

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.

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support
>