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
– this will help you 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
– this returns an array ofAction_Field
ids that are required in the admin UI in order to set up the action. Those fields will be used inside thedo_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
– this returns an array ofData_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. It is received as a parameter an array ofData_Object
Other Methods
public function is_compatible_with_trigger( $trigger ): bool
– you’ll need to check to see if an action is compatible with a specificTrigger
By default, an action is compatible with a trigger if it has all the requiredData_Object
public function can_run( $data = [] ): bool
– you’ll need to check if the current action has all the data needed in order to startpublic function prepare_data( $data = [] ): void
– can be used to set up additional fields inside the current class
Usually used to extract values set for eachAction_Field
from admin UIpublic function provides_data_objects()
– while the automation is running, the action itself can create and add aData_Object
to the automation data
This can enable other availableAction
, so by specifying here, theAction
will be available in the editorpublic function get_action_mapped_fields()
– while setting up the automation, this can be used to dynamically alter the structure of the already set requiredAction_Field
(s)public function get_search_keywords()
– inside the editor, in order for theAction
to be more easily found, extra search tags can be addedpublic function is_compatible_with_trigger($provided_data_objects)
– inside the editor, theAction
will usually be available if theTrigger
provides the requiredData_Object
(s).
Using this can overwrite that rulepublic function is_top_level()
– inside the editor, the triggers are grouped under a category which usually represents the application for which it was developedIf theAction
is required to be outside a category and be a standalone item, this can be set to truepublic function sync_trigger_data()
– inside the editor, while setting up the automation, certainTrigger_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 recommend you to use the thrive_automator_register_action
function which receives the class name as the only parameter.