Filter
uncanny-automator
automator_get_recipe_data_query
Filters the query arguments used to retrieve recipe data, allowing modification before the data is fetched.
add_filter( 'automator_get_recipe_data_query', $callback, 10, 3 );
Description
Fires before Uncanny Automator retrieves saved recipe trigger or action data. Developers can modify the SQL query ($q) to filter or alter the data fetched based on recipe ID ($recipe_id) or type ($type). This allows for custom data retrieval logic.
Usage
add_filter( 'automator_get_recipe_data_query', 'your_function_name', 10, 3 );
Parameters
-
$q(mixed) - This parameter contains the SQL query string being built to retrieve recipe children, allowing for modification before execution.
-
$recipe_id(mixed) - This parameter contains the SQL query string being built to retrieve recipe children data.
-
$type(mixed) - The `$recipe_id` parameter represents the ID of the parent recipe for which child items are being queried.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the automator_get_recipe_data_query hook.
* This example modifies the SQL query to include a condition based on the recipe type.
*
* @param string $q The SQL query string.
* @param int $recipe_id The ID of the recipe.
* @param string $type The type of the recipe (e.g., 'trigger', 'action').
*
* @return string The modified SQL query string.
*/
add_filter( 'automator_get_recipe_data_query', function( $q, $recipe_id, $type ) {
// Let's assume $q is a valid SQL SELECT query.
// For this example, we'll add a condition if the recipe type is 'trigger'.
if ( $type === 'trigger' ) {
// In a real scenario, you'd parse $q and append conditions carefully.
// For simplicity here, we're directly appending. A more robust solution
// might involve using WPDB's query builder if available or complex string manipulation.
// This is a simplified demonstration and might break complex queries.
$q .= " AND recipe_type = 'trigger'";
}
// It's crucial to return the modified query.
return $q;
}, 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/lib/class-automator-functions.php:1522
public function get_recipe_children_query( $recipe_id, $type ) {
global $wpdb;
$q = $wpdb->prepare( "SELECT ID, post_status, menu_order, post_parent FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $recipe_id, $type );
if ( AUTOMATOR_POST_TYPE_ACTION === $type ) {
$q = "$q ORDER BY menu_order ASC";
}
$q = apply_filters_deprecated(
'q_get_recipe_data',
array(
$q,
$recipe_id,
$type,
),
'3.0',
'automator_get_recipe_data_query'
);
$q = apply_filters( 'automator_get_recipe_data_query', $q, $recipe_id, $type );
return $wpdb->get_results( $q, ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
Internal Usage
Found in uncanny-automator-pro/src/core/classes/pro-ui.php:16:
add_filter( 'automator_get_recipe_data_query', array( $this, 'q_get_recipe_data' ), 20, 3 );