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

Creating Data Objects

About Data Objects

Data objects represent a structured object that is provided by a Trigger.

After a WordPress action is triggered, parameters will be passed to the Trigger which will transform them into Data_Object.

The reason why we're doing this is to better understand what each trigger provides so we can later use this data to match what actions are compatible.

Data is set inside the process_params function of the Trigger through the constructor of the Data_Object. For special situations, we have the get_value and set_value functions which can be overwritten to fit the current structure.

Creating your first data object

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

  • abstract public static function get_id(): string - should return a unique identifier that will be used as a key in arrays. To avoid conflicts or overwrites, we suggest using a prefix
PHP
|
<?php
public static function get_id(): string { 
    return 'wp/user-data'; 
}

  • abstract public static function get_fields(): array - returns an array of Data_Field keys that the current Data_Object provides. Filters might want to know this in order to provide filtering. An Action might want to get those fields so it can know what it can use.
PHP
|
<?php
public static function get_fields(): array { 
    return return [ Username_Data_Field::get_id(), User_Email_Data_Field::get_id() ]; 
}

  • public static function get_nice_name(): string - should return a name that is displayed inside the editor, inside dropdowns when mapping fields
PHP
|
<?php
public static function get_nice_name() { 
    return ''; 
}

  • abstract public static function create_object( $param ): array - this method is called inside the constructor and it's used to create the object from the raw data received from the Trigger. This object should contain information about all the fields mentioned in the get_fields method from above.
PHP
|
<?php
public static function create_object( $user_id ): array { 
    $user = get_userdata($user_id); 
        if( $user === null ) { 
            $user_data = []; 
        } else { 
            $user_data = [ 
                  'wp/username' => $user->user_login, 
                  'wp/email' => $user->user_email, 
        ]; 
        } 
           return $user_data; 
}


Other methods

  • public function replace_dynamic_data( $value ) - on automation execution, this function will replace dynamic data specific to Data_Object1 structure. The $value parameter can contain one or multiple shortcodes which are replaced with actual values.

Registering the data object

In order to register a data object so it can be used by triggers, actions and filters, we should use the thrive_automator_register_data_object function which receives as the only parameter, the class name.

Updated 03 Mar 2023
Did this page help you?
Yes
No
Docs powered by archbee 
TABLE OF CONTENTS
About Data Objects
Creating your first data object
Other methods
Registering the data object