Filter
uncanny-automator
automator_calculation_result
Filters the calculation result before it's returned, allowing modifications to the automator's computed value.
add_filter( 'automator_calculation_result', $callback, 10, 2 );
Description
Fires after a calculation result is prepared. Developers can modify the final calculation result before it's returned. This hook passes the result and the calculation token object.
Usage
add_filter( 'automator_calculation_result', 'your_function_name', 10, 2 );
Parameters
-
$this(mixed) - The `$this` parameter contains the result of the calculation.
-
$this(mixed) - The `$this` parameter, when passed to the `automator_calculation_result` filter, represents the `CalculationToken` object itself, allowing modification of its properties or the calculation's outcome.
Return Value
The filtered value.
Examples
/**
* Modify the calculation result for a specific recipe trigger.
*
* This example checks if the calculation result is a numerical value
* and if so, adds 10 to it. It's useful for scenarios where you might
* want to increment a score or a counter based on a calculation.
*
* @param mixed $calculation_result The original calculation result.
* @param object $calculation_token The Calculation_Token object instance.
* @return mixed The modified calculation result.
*/
add_filter( 'automator_calculation_result', function( $calculation_result, $calculation_token ) {
// Check if the result is a number and if we want to apply this modification.
// In a real-world scenario, you might check for a specific meta key or
// other properties of $calculation_token to conditionally apply the change.
if ( is_numeric( $calculation_result ) ) {
$new_result = $calculation_result + 10;
return $new_result;
}
// If it's not a number or the condition isn't met, return the original result.
return $calculation_result;
}, 10, 2 ); // 10 is the priority, 2 is the number of accepted 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/integrations/advanced/tokens/calculation-token.php:133
src/core/classes/class-calculation-token.php:244
public function get_result() {
return apply_filters( 'automator_calculation_result', $this->result, $this );
}