automator_field_resolver_condition_result_user_id
Filters the user ID used in AutomatorWP conditions, allowing modification before evaluation.
add_filter( 'automator_field_resolver_condition_result_user_id', $callback, 10, 1 );
Description
This filter allows developers to modify the `user_id` used in database queries for `conditions_result` meta values. It's primarily for internal use, enabling dynamic adjustment of the user context when resolving field conditions or logging trigger/action data. Ensure any modified `user_id` remains a valid integer.
Usage
add_filter( 'automator_field_resolver_condition_result_user_id', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Filters the user ID used when querying for condition results in the recipe log meta.
*
* This example demonstrates how to modify the user ID to potentially retrieve
* condition results for a different user, perhaps for debugging or testing purposes.
* In a real-world scenario, you might want to return the original user ID or
* fetch it based on other contextual information available within your WordPress setup.
*
* @param null|int $user_id The original user ID, which is null by default.
*
* @return int|null The modified user ID to be used in the query.
*/
add_filter( 'automator_field_resolver_condition_result_user_id', function( $user_id ) {
// In this example, we'll conditionally set the user ID.
// Let's say we want to fetch results for a specific debugging user ID.
$debug_user_id = 123; // Replace with your desired debug user ID
// You could also dynamically determine the user ID based on other factors.
// For instance, if this filter is called within a specific context where
// a different user is relevant, you might retrieve it like this:
// $current_user = wp_get_current_user();
// if ( $current_user && $current_user->ID !== $debug_user_id ) {
// return $debug_user_id;
// }
// For demonstration, we'll just return the debug user ID if it's not null.
if ( $debug_user_id ) {
return (int) $debug_user_id;
}
// If no specific user ID is set for modification, return the original (or null).
return $user_id;
}, 10, 1 );
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/services/resolver/fields-conditions-resolver.php:124
src/core/services/rest/endpoint/log-endpoint/resources/trigger-logs-resources.php:198
src/core/services/rest/endpoint/log-endpoint/resources/action-logs-resources.php:377
private function get_condition_summary( $params ) {
global $wpdb;
$condition_summary = array();
// @todo Move to a query class.
$conditions_results = $wpdb->get_results(
$wpdb->prepare(
"SELECT meta_value FROM {$wpdb->prefix}uap_recipe_log_meta
WHERE user_id = %d
AND recipe_id = %d
AND recipe_log_id = %d
AND meta_key = 'conditions_result'
",
apply_filters( 'automator_field_resolver_condition_result_user_id', null ),
$params['recipe_id'],
$params['recipe_log_id']
),
ARRAY_A
);
foreach ( $conditions_results as $condition_result ) {
$json_result = (array) json_decode( $condition_result['meta_value'], true );
foreach ( $json_result as $cond_id => $condition_item_result ) {
$condition_summary[ $cond_id ] = $condition_item_result;
}
}
return $condition_summary;
}