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

Creating a New Action in Thrive Automator

The basic principle that lies behind it will always be a simple one: when → then.

Therefore, actions are the last part of automation and represent what happens if the conditions are met.

Creating your first action

To create your own Action, you need to extend ThriveAutomatorItemsAction and implement the required basic 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

public static function get_id(): string { 
    return 'wp/create-user'; 
}
  • abstract public static function get_name(): string – the name of the action.

public static function get_name(): string { 
    return 'Create user'; 
}
  • abstract public static function get_description(): string -short description of the action that will be displayed in the tooltip.

public static function get_description(): string { 
    return 'Create a new wordpress user'; 
}
  • abstract public static function get_image(): string – return the image that will be displayed near the action – ideally, the dimensions should be 32 x 32.

public static function get_image(): string { 
    return 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/Wordpress_Blue_logo.png/1200px-Wordpress_Blue_logo.png'; 
}
  • abstract public static function get_app_name(): string – get the name of the app to which the hook belongs. If you have multiple actions from the same app, make sure to have the same name here.

public static function get_app_name(): string { 
    return WordPress_App::get_id();
}
  • abstract public static function get_required_action_fields(): array – return an array of Action_Field ids that are required in the admin UI in order to set up the action. Those fields will be used inside the do_action function

public static function get_required_action_fields(): array { 
    return [ Register_Role_Field::get_id() ]; 
}
  • abstract public static function get_required_data_objects(): array – return an array of Data_Object IDs that are required in order to complete this action. When setting automation in the admin UI, actions will be available only for the triggers that provide the same data. An action would require data from a trigger if it wants to use that specific data (e.g. when a user submits a form, create a new user with that email).

public static function get_required_data_objects(): array { 
    return [ User_Data::get_id() ]; 
}
  • abstract public static function do_action( $data = [] ) – the actual implementation of the action. receives as a parameter an array of Data_Object

Other methods

  • public function is_compatible_with_trigger( $trigger ): bool – check to see if an action is compatible with a specific Trigger
    By default, an action is compatible with a trigger if it has all the required Data_Object

  • public function can_run( $data = [] ): bool – check if the current action has all the data needed in order to start

  • public function prepare_data( $data = [] ): void – can be used to set up additional fields inside the current class
    Usually used to extract values set for each Action_Field from admin UI

  • public function provides_data_objects() – while the automation is running, the action itself can create and add a Data_Object to the automation data
    This can enable other available Action, so by specifying here, the Action will be available in the editor

  • public function get_action_mapped_fields() – while setting up the automation, this can be used to dynamically alter the structure of the already set required Action_Field(s)

  • public function get_search_keywords() – inside the editor, in order for the Action to be more easily found, extra search tags can be added

  • public function is_compatible_with_trigger($provided_data_objects) – inside the editor, the Action will usually be available if the Trigger provides the required Data_Object(s).
    Using this can overwrite that rule

  • public function is_top_level() – inside the editor, the triggers are grouped under a category which usually represents the application for which it was developed

    If we require the Action to be outside a category and be a standalone item, this can be set to true

  • public function sync_trigger_data() – inside the editor, while setting up the automation, certain Trigger_Field/Action may alter the provided data objects and some more actions can be enabled.

Registering the action

To register this action so it can appear in the admin area, we should use the thrive_automator_register_action 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
>