Filter
uncanny-automator
automator_trigger_entry_args
Filters the arguments passed to a trigger entry before it's processed, allowing for custom modification.
add_filter( 'automator_trigger_entry_args', $callback, 10, 2 );
Description
Filters the arguments passed to a trigger entry. Developers can use this hook to modify or add to the trigger's arguments before they are processed. This hook fires after the trigger has been identified but before its arguments are finalized and set.
Usage
add_filter( 'automator_trigger_entry_args', 'your_function_name', 10, 2 );
Parameters
-
$this(mixed) - This parameter represents the current object instance of the trigger being processed.
-
$args(mixed) - This parameter refers to the current instance of the Trigger Process trait, providing access to trigger-specific methods and properties.
Return Value
The filtered value.
Examples
<?php
/**
* Modify the trigger arguments for a specific Automator recipe trigger.
*
* This example demonstrates how to conditionally add custom data to the trigger arguments
* based on the type of WordPress post being processed. If the trigger is associated
* with a specific post type, we'll pass its ID along.
*
* @param array $trigger_args The current trigger arguments.
* @param mixed $original_args The original arguments passed to the trigger.
* @return array The modified trigger arguments.
*/
add_filter( 'automator_trigger_entry_args', function( $trigger_args, $original_args ) {
// Assuming $original_args might contain information about the post being processed.
// This is a hypothetical scenario; the actual structure of $original_args
// would depend on the specific trigger that fired.
if ( isset( $original_args['post_id'] ) && is_numeric( $original_args['post_id'] ) ) {
$post_id = (int) $original_args['post_id'];
$post_type = get_post_type( $post_id );
// Example: Only add post type information if it's a 'page'.
if ( 'page' === $post_type ) {
$trigger_args['processed_post_type'] = $post_type;
$trigger_args['processed_post_id'] = $post_id;
}
}
// Always return the potentially modified arguments.
return $trigger_args;
}, 10, 2 ); // Priority 10, accepting 2 arguments.
?>
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-process.php:226
protected function prepare_entry_args( $args ) {
$pass_args = array(
'code' => $this->get_trigger_code(),
'meta' => $this->get_trigger_meta(),
'user_id' => $this->get_user_id(),
'integration' => $this->get_integration(),
);
if ( null !== $this->get_post_id() && null === $this->get_trigger_to_match() && null === $this->get_recipe_to_match() ) {
$pass_args['post_id'] = $this->get_post_id();
}
if ( null !== $this->get_trigger_to_match() ) {
$pass_args['trigger_to_match'] = $this->get_trigger_to_match();
}
if ( null !== $this->get_recipe_to_match() ) {
$pass_args['recipe_to_match'] = $this->get_recipe_to_match();
}
if ( null !== $this->get_is_signed_in() ) {
$pass_args['is_signed_in'] = $this->get_is_signed_in();
}
if ( $this->is_ignore_post_id() ) {
$pass_args['ignore_post_id'] = $this->is_ignore_post_id();
}
$this->set_trigger_args( $pass_args );
return apply_filters( 'automator_trigger_entry_args', $this->get_trigger_args(), $args );
}