Action
uncanny-automator
automator_trigger_populated_from_query
Fires when an Automator trigger is populated from a query, allowing customization of the populated data.
add_action( 'automator_trigger_populated_from_query', $callback, 10, 3 );
Description
Fires after a trigger's data has been successfully populated from a query. Developers can use this hook to modify the populated post data, trigger ID, or GET parameters before they are used, or to perform additional actions based on the query results. Note that the $_GET parameter is passed without nonce verification.
Usage
add_action( 'automator_trigger_populated_from_query', 'your_function_name', 10, 3 );
Parameters
-
$post(mixed) - This parameter contains the post object that was populated from the query.
-
$trigger_id(mixed) - This parameter contains the WordPress post object that was retrieved or created as a result of the query.
-
$_GET(mixed) - This parameter contains the unique identifier for the specific trigger that was populated from the query.
Examples
<?php
/**
* Example function to hook into the 'automator_trigger_populated_from_query' action.
*
* This function demonstrates how to access and potentially modify data
* passed to the trigger when it's populated from a query. In this example,
* we're logging the trigger ID and the first element of the $_GET data
* to the WordPress debug log for inspection.
*
* @param mixed $post The post object or related data associated with the trigger.
* @param mixed $trigger_id The ID of the trigger being populated.
* @param mixed $_GET The contents of the $_GET superglobal array at the time of the action.
*/
function my_automator_populate_trigger_from_query_handler( $post, $trigger_id, $_GET ) {
// Ensure the WordPress debug log is enabled for this to have an effect.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
$log_message = sprintf(
'automator_trigger_populated_from_query triggered. Trigger ID: %s. GET data snippet: %s',
esc_html( $trigger_id ),
isset( $_GET ) && is_array( $_GET ) && ! empty( $_GET ) ? esc_html( reset( $_GET ) ) : 'No GET data'
);
error_log( $log_message );
}
// You could also perform other actions here, like:
// - Setting custom post meta based on $_GET parameters.
// - Triggering another action if a specific condition is met.
// - Validating the data before it's used.
// For this example, we're not modifying anything, just logging.
// If this were a filter, you would return the modified data.
}
// Hook the function to the 'automator_trigger_populated_from_query' action.
// The third parameter '3' indicates that this function accepts 3 arguments.
add_action( 'automator_trigger_populated_from_query', 'my_automator_populate_trigger_from_query_handler', 10, 3 );
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/classes/class-populate-from-query.php:194
public static function add_new_trigger() {
self::change_recipe_type();
$trigger_id = self::add_trigger();
// Trigger was created, check if its meta needs to be set
self::maybe_update_trigger( $trigger_id );
// add do_action for external hooks
do_action_deprecated(
'uap_trigger_populated_from_query',
array(
self::$post,
$trigger_id,
$_GET, // phpcs:ignore WordPress.Security.NonceVerification.Recommended
),
'3.0',
'automator_trigger_populated_from_query'
);
do_action( 'automator_trigger_populated_from_query', self::$post, $trigger_id, $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return true;
}