Filter
uncanny-automator
automator_total_completed_runs
Filters the total number of completed runs for automations, allowing modification of the count.
add_filter( 'automator_total_completed_runs', $callback, 10, 1 );
Description
Filters the total count of completed recipe runs. Developers can modify this count before it's returned, allowing for custom filtering or adjustments to the reported number of completed automations. The hook receives the count as `$results`.
Usage
add_filter( 'automator_total_completed_runs', 'your_function_name', 10, 1 );
Parameters
-
$results(mixed) - This parameter contains the total count of completed recipe runs.
Return Value
The filtered value.
Examples
/**
* Example: Add a suffix to the total completed runs count if it's above a certain threshold.
*
* This function demonstrates how to hook into 'automator_total_completed_runs'
* to modify the returned value. In this case, if the total completed runs
* exceed 1000, we'll append "(High Activity)" to the count.
*/
add_filter( 'automator_total_completed_runs', function( $results ) {
// Ensure $results is an integer before comparison.
$completed_runs_count = absint( $results );
// Define a threshold for high activity.
$high_activity_threshold = 1000;
if ( $completed_runs_count > $high_activity_threshold ) {
// Return the count with a descriptive suffix.
return sprintf( '%d (High Activity)', $completed_runs_count );
}
// If not above the threshold, return the original count.
return $completed_runs_count;
}, 10, 1 ); // Priority 10, accepts 1 argument.
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/utilities/class-automator-get-data.php:1379
public function total_completed_runs() {
global $wpdb;
$tbl = Automator()->db->tables->recipe;
$results = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}{$tbl} WHERE completed=1" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
return apply_filters( 'automator_total_completed_runs', absint( $results ) );
}