website logo
Thrive Themes
Navigate through spaces
Thrive Themes
⌘K
General
⚙️Thrive Themes Action Hooks & Custom Functions
⚙️How Can You Extend Thrive Themes Capabilities as a Developer
⚙️How to Integrate Your Thrive Themes Site to a Third Party Autoresponder
Thrive Architect
⚙️How to Develop Custom Rules For the Conditional Display Option
Thrive Automator
Untitled doc
⚙️Thrive Automator for Developers - Extending Automations' Capabilities
⚙️What Type of Data Do Thrive Automator Triggers and Actions Use?
⚙️Creating a New Start Trigger
⚙️Creating a New Filter in Thrive Automator
⚙️Creating a New Action in Thrive Automator
⚙️Creating Data Fields
⚙️Creating Trigger Fields
⚙️Creating Action Fields
⚙️Creating Apps
⚙️Creating Data Objects
Docs powered by archbee 
15min

Creating Data Fields

About Data Fields

Data fields represent the data that is stored in a Data_Object and are mostly used for filtering inside an automation.

For example, you might run a login trigger, but you want to execute an action, just for a specific user role, ID, or last login date.

Creating your first Data_Field

To create your own Data_Field you need to extend Thrive\Automator\Items\Data_Field 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
PHP
|
<?php
public static function get_id(): string { 
    return 'wp/username'; 
}

  • abstract public static function get_name(): string - the name of the field that will be displayed in the admin UI when creating a filter
PHP
|
<?php
public static function get_name(): string { 
    return 'Username'; 
}

  • abstract public static function get_description(): string - a short description for the field to help users understand what it represents
PHP
|
<?php
public static function get_description(): string {  
    return 'The username used by the user to login'; 
}

  • abstract public static function get_placeholder(): string - placeholder to be used for inputs in the admin UI
PHP
|
<?php
public static function get_placeholder(): string { 
    return 'username'; 
}

  • abstract public static function get_supported_filters(): array - return an array of filters that are supported by our field. Some filters are already implemented by Thrive Automator plugin (check inc/classes/items/filters), but more can be added.
PHP
|
<?php
public static function get_supported_filters(): array { 
    return [ 'string_contains', 'string_equals', 'dropdown' ]; 
}


Other methods

  • abstract public static function is_ajax_field(): bool - determine if the values used for filtering in admin UI are returned directly or through an ajax request. By default, this method returns false.
PHP
|
<?php
public static function is_ajax_field(): bool { 
    return true; 
}

  • abstract public static function get_field_value_type(): string - return field value's type. Based on this we determine whether the field can be used as dynamic data.
PHP
|
<?php
public static function get_field_value_type(): string { 
    return true; 
}

  • abstract public static function get_options_callback(): array - return an array of ID/label arrays that will be used to display values in filters. In case is_ajax_field() method returns true, values for filter compare will be retrieved with an ajax request. Ajax options values are usually used for select dropdowns.
PHP
|
<?php
public static function get_options_callback(): array { 
   return return [ 
             [ 
                 'id' => 1, 'label' => 'Label 1', 
             ], 
          ]; 
}

  • public static function primary_key(): array - return an array of Data_Objects ids of those data objects that can be initialized by this field value. Those are used for Webhook and Advanced Data Mapping items where you can map a text/number to a dataset
PHP
|
<?php
public static function primary_key(): array { 
    return [ User_Data::get_id() ]; 
}


Registering the data field

To register a Data_Field so it can be used by data objects and filters, we should use the thrive_automator_register_data_field function which receives as the only parameter, the class name.

Updated 03 Mar 2023
Did this page help you?
Yes
No
UP NEXT
Creating Trigger Fields
Docs powered by archbee 
TABLE OF CONTENTS
About Data Fields
Creating your first Data_Field
Other methods
Registering the data field