Skip to content

Creating a New Thrive Automator Action

iuliadezmirean1 edited this page Aug 16, 2021 · 8 revisions

About actions

The basic principle that lies behind it will always be a simple one: when , then . Therefore, actions are the last part of an automation and represent what happens if the conditions are met.

Creating your first action

In order to create your own Action you need to extend Thrive\Automator\Items\Action 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';
	}
  • 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.
	public static function get_required_action_fields(): array {
		return ['wp/user-role'];
	}
  • 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 an 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 ['wp/user-data'];
	}
  • 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

Registering the action

In order 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.