automator_trigger_filter_condition_matched_{dynamic}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Allow external developers to manipulate the true/false based on specific criteria. WARNING: THIS IS A CORE FUNCTIONALITY THAT MATCHES A VALUE BASED ON A CRITERIA, E.X., A USER ENTERED A SPECIFIC VALUE IN A FIELD. OVERRIDING THE LOGIC INCORRECTLY WILL RESULT IN FAILED RECIPE RUNS. USE IT WISELY! add_filter( 'automator_trigger_filter_condition_matched', function($condition_matched, $notation, $where, $condition, $recipe_id) { // doing something; return $condition_matched; // Must return boolean True or False. }, 99, 5 ); Filters if a trigger's condition criteria is met, allowing modification of the true/false match result for specific dynamic conditions.
add_filter( 'automator_trigger_filter_condition_matched_{dynamic}', $callback, 10, 3 );
Description
Filter a trigger's condition match result for a specific recipe. This hook allows precise control over whether a trigger condition is met, enabling custom logic beyond standard comparisons. Use cautiously, as incorrect modifications can lead to failed recipe executions by altering core matching behavior.
Usage
add_filter( 'automator_trigger_filter_condition_matched_{dynamic}', 'your_function_name', 10, 3 );
Parameters
-
$condition_matched(mixed) - - **$notation** `mixed`
-
$where(mixed) - - **$condition** `mixed`
-
$recipe_id(mixed)
Return Value
The filtered value.
Examples
add_filter( 'automator_trigger_filter_condition_matched_' . $recipe_id, function( $condition_matched, $notation, $where, $condition, $recipe_id ) {
// Example: If the condition is checking for a specific user role and the user doesn't have it,
// we might want to override the default behavior and force the condition to be unmatched.
// This could be useful for advanced scenarios where you want to exclude certain users
// from triggering a recipe based on their role, even if other conditions might match.
// Assume $recipe_id is globally available or passed correctly.
// For demonstration, let's assume we have a specific recipe_id that needs this custom logic.
$specific_recipe_id_to_modify = 123; // Replace with an actual recipe ID if known.
if ( $recipe_id === $specific_recipe_id_to_modify ) {
// Check if the condition is related to user roles and if the 'where' value is a specific role.
// This is a simplified example; real logic would involve inspecting $notation and $condition more deeply.
if ( str_contains( $notation, 'user_role' ) && $where === 'administrator' && $condition_matched === true ) {
// If the user is an administrator and the condition was initially matched,
// but we want to exclude administrators from this specific recipe,
// force the condition to be unmatched.
return false;
}
}
// If no special logic applies, return the original matched status.
return $condition_matched;
}, 10, 5 );
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-recipe-filters.php:400
private function conditions_matched( $notation, $where, $condition, $recipe_id ) {
// Process non-integer inputs.
if ( ! empty( $this->get_compare() ) && ( ! is_numeric( $where ) || ! is_numeric( $condition ) ) ) {
$condition_matched = ( $where === $condition );
$assert_message = gettype( $where ) . ":{$where} {$notation} " . gettype( $condition ) . ":$condition | Result: " . ( $condition_matched ? 'Matched' : 'Failed' );
// Special string_contains notation.
// @since 4.4
if ( 'string_contains' === $notation ) {
$add_slashes = apply_filters( 'automator_escape_matching_characters', '/._-:\' );
$condition_matched = preg_match( '/(' . addcslashes( $where, $add_slashes ) . ')/i', $condition );
$this->push_log( 'Asserting ' . $assert_message, 'assertions', $recipe_id );
return $condition_matched;
}
$this->push_log( 'Asserting (non-numeric)' . $assert_message, 'assertions', $recipe_id );
return $condition_matched;
}
// Otherwise, process with equality sign.
$condition_matched = $this->match_condition( $notation, $where, $condition );
/**
* Allow external developers to manipulate the true/false based on specific criteria.
*
* WARNING: THIS IS A CORE FUNCTIONALITY THAT MATCHES A VALUE BASED ON A CRITERIA, E.X.,
* A USER ENTERED A SPECIFIC VALUE IN A FIELD.
* OVERRIDING THE LOGIC INCORRECTLY WILL RESULT IN FAILED RECIPE RUNS. USE IT WISELY!
*
* add_filter( 'automator_trigger_filter_condition_matched', function($condition_matched, $notation, $where, $condition, $recipe_id) {
* // doing something;
* return $condition_matched; // Must return boolean True or False.
* }, 99, 5 );
*
* @since v4.8
* @author Saad S.
* @author Joseph G.
*/
$condition_matched = apply_filters( 'automator_trigger_filter_condition_matched_' . $recipe_id, $condition_matched, $notation, $where, $condition, $recipe_id );
$this->push_log(
'Asserting field option with value ' . gettype( $where ) . ":{$where} {$notation} " .
'given value ' . gettype( $condition ) . ":$condition | Result: " .
( $condition_matched ? 'Matched (with ' . gettype( $condition ) . ' data type converted to int)' : 'Failed' ),
'assertions',
$recipe_id
);
return $condition_matched;
}