Filter uncanny-automator

automator_has_scheduled_actions

Filters whether scheduled actions exist for a recipe log entry before execution.

add_filter( 'automator_has_scheduled_actions', $callback, 10, 3 );

Description

Filters the count of scheduled actions for a recipe log. Developers can use this to modify the number of pending actions or to conditionally determine if a recipe log has scheduled actions before proceeding. This filter is applied internally by the database handler.


Usage

add_filter( 'automator_has_scheduled_actions', 'your_function_name', 10, 3 );

Parameters

$results (mixed)
This parameter contains the count of scheduled actions that are already completed.
$recipe_log_id (mixed)
The `$results` parameter contains the total count of scheduled actions that have been completed for a given recipe log.
$args (mixed)
This parameter represents the ID of the specific recipe log entry for which scheduled actions are being queried.

Return Value

The filtered value.


Examples

// Example: Prevent processing scheduled actions if a certain condition is met for a specific recipe log.
add_filter( 'automator_has_scheduled_actions', function ( $results, $recipe_log_id, $args ) {

	// Let's say we don't want to process scheduled actions for recipe logs that are older than 30 days.
	// In a real scenario, you would fetch the recipe log data to determine its age.
	// For this example, we'll simulate an older log.

	$thirty_days_ago = strtotime( '-30 days' );
	$current_time    = time();

	// Simulate checking if the recipe log is older than 30 days.
	// In a real application, you would likely retrieve the creation date of the $recipe_log_id
	// and compare it to $thirty_days_ago.
	$is_old_log = ( $current_time - $thirty_days_ago > 60 * 60 * 24 * 30 ); // Simplified for demonstration

	if ( $is_old_log && $recipe_log_id === 123 ) { // Example: Only apply this to a specific old recipe log ID
		// If it's an old log and matches our condition, return 0, indicating no scheduled actions.
		return 0;
	}

	// Otherwise, return the original results.
	return $results;

}, 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/utilities/db/class-automator-db-handler-recipes.php:272

public function get_scheduled_actions_count( $recipe_log_id, $args ) {

		global $wpdb;

		$tbl = Automator()->db->tables->action;

		$results = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}{$tbl} WHERE completed = 5 AND automator_recipe_log_id = %d", $recipe_log_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared

		return apply_filters( 'automator_has_scheduled_actions', absint( $results ), $recipe_log_id, $args );
	}

Scroll to Top