automator_register_trigger
Filters the triggers available for automations, allowing for customization and registration of new trigger types.
add_filter( 'automator_register_trigger', $callback, 10, 1 );
Description
This filter allows developers to modify or add data to trigger definitions before they are registered. It's crucial for customizing trigger behavior, adding metadata, or integrating with other systems. Developers can dynamically alter the `$trigger` array, influencing how triggers are processed and displayed.
Usage
add_filter( 'automator_register_trigger', 'your_function_name', 10, 1 );
Parameters
-
$trigger(mixed) - This parameter contains the complete definition of the trigger, including its author, support link, and other relevant metadata.
Return Value
The filtered value.
Examples
<?php
/**
* Example filter for the 'automator_register_trigger' hook.
*
* This example demonstrates how to modify the trigger data before it's registered
* by the Automator plugin. It adds a custom 'display_name' and a 'category'
* to the trigger if it meets certain criteria.
*
* @param array $trigger The trigger data array.
* @return array The modified trigger data array.
*/
add_filter( 'automator_register_trigger', function( $trigger ) {
// Check if the trigger is for a specific post type or has a known code.
// In a real-world scenario, you'd likely check for more specific conditions
// related to your custom trigger.
if ( isset( $trigger['post_type'] ) && 'your_custom_post_type' === $trigger['post_type'] ||
( isset( $trigger['code'] ) && 'your_custom_trigger_code' === $trigger['code'] ) ) {
// Add a more user-friendly display name for the trigger.
$trigger['display_name'] = __( 'Your Custom Trigger Name', 'your-text-domain' );
// Assign the trigger to a specific category for better organization.
$trigger['category'] = __( 'Your Custom Category', 'your-text-domain' );
// You could also add or modify other trigger properties here,
// such as 'description', 'support_link', etc.
}
// Always return the (potentially modified) trigger data.
return $trigger;
}, 10, 1 ); // Priority 10, accepts 1 argument.
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/recipe-parts/triggers/trait-trigger-setup.php:651
src/core/lib/recipe-parts/triggers/abstract-trigger.php:273
src/core/lib/utilities/class-automator-registration.php:161
protected function register_trigger() {
$trigger = array(
'author' => $this->get_author(), // author of the trigger.
'support_link' => $this->get_support_link(), // hyperlink to support page.
'type' => $this->get_trigger_type(), // user|anonymous. user by default.
'is_pro' => $this->get_is_pro(), // free or pro trigger.
'is_elite' => $this->get_is_elite(), // elite trigger.
'is_deprecated' => $this->get_is_deprecated(), // whether trigger is deprecated.
'integration' => $this->get_integration(), // trigger the integration belongs to.
'code' => $this->get_code(), // unique trigger code.
'meta_code' => $this->get_trigger_meta(), // trigger meta code.
'sentence' => $this->get_sentence(), // sentence to show in active state.
'select_option_name' => $this->get_readable_sentence(), // sentence to show in non-active state.
'action' => $this->get_action(), // trigger fire at this do_action().
'priority' => $this->get_action_priority(), // priority of the add_action().
'accepted_args' => $this->get_action_args_count(), // accepted args by the add_action().
'tokens' => $this->get_trigger_tokens(), // all the linked tokens of the trigger.
'token_parser' => $this->get_token_parser(), // v3.0, Pass a function to parse tokens.
'validation_function' => array( $this, 'validate' ), // function to call for add_action().
'uses_api' => $this->get_uses_api(),
'loopable_tokens' => $this->get_loopable_tokens(), //@since 5.10
);
if ( ! empty( $this->get_options() ) ) {
$trigger['options'] = $this->get_options();
}
if ( ! empty( $this->get_options_group() ) ) {
$trigger['options_group'] = $this->get_options_group();
}
if ( ! empty( $this->get_options_callback() ) ) {
$trigger['options_callback'] = $this->get_options_callback();
}
if ( ! empty( $this->get_buttons() ) ) {
$trigger['buttons'] = $this->get_buttons();
}
if ( ! empty( $this->get_inline_css() ) ) {
$trigger['inline_css'] = $this->get_inline_css();
}
if ( null !== $this->get_can_log_in_new_user() ) {
$trigger['can_log_in_new_user'] = $this->get_can_log_in_new_user();
}
// Extract manifest data if trait is used
if ( $this->uses_item_manifest_trait() && is_callable( array( $this, 'extract_item_manifest_data' ) ) ) {
$manifest = call_user_func( array( $this, 'extract_item_manifest_data' ) );
if ( ! empty( $manifest ) ) {
$trigger['manifest'] = $manifest;
}
}
$trigger = apply_filters( 'automator_register_trigger', $trigger );
// $this->trigger_tokens_filter returns false if trigger has no token.
$this->add_trigger_tokens_filter( $this->get_trigger_code(), $this->get_integration() );
Automator()->register->trigger( $trigger );
}