Filter uncanny-automator

automator_get_recipes_data

Filters recipe data before it is retrieved, allowing for modification based on recipe ID and context.

add_filter( 'automator_get_recipes_data', $callback, 10, 2 );

Description

Fires after recipe data is retrieved and cached. Developers can use this filter to modify or augment the array of recipe data before it's cached. This includes adding custom information or filtering specific recipes based on various criteria. The filter receives the recipe data array and the current recipe ID.


Usage

add_filter( 'automator_get_recipes_data', 'your_function_name', 10, 2 );

Parameters

$this (mixed)
This parameter represents the current instance of the Automator Functions class.
$recipe_id (mixed)
This parameter represents the current instance of the Automator Functions class, providing access to its methods and properties.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to hook into the 'automator_get_recipes_data' filter.
 * This example adds a custom flag to recipes that are scheduled to run within the next 24 hours.
 *
 * @param array $recipes_data The array of recipe data being filtered.
 * @param int   $recipe_id    The ID of the current recipe being processed.
 *
 * @return array The modified array of recipe data.
 */
function my_custom_automator_recipes_data_filter( $recipes_data, $recipe_id ) {

	// Check if the current recipe ID is part of the data being processed.
	if ( ! isset( $recipes_data[ $recipe_id ] ) ) {
		return $recipes_data;
	}

	// Assume there's a way to get the schedule information for a recipe.
	// In a real scenario, you'd likely query the database or use another Automator function.
	$recipe_schedule_info = get_post_meta( $recipe_id, '_automator_recipe_schedule', true );

	// Check if the recipe has schedule information and if it's due soon.
	if ( ! empty( $recipe_schedule_info ) && isset( $recipe_schedule_info['date'] ) ) {
		$schedule_date = strtotime( $recipe_schedule_info['date'] );
		$current_time  = time();
		$twenty_four_hours_in_seconds = 24 * 60 * 60;

		if ( $schedule_date > $current_time && $schedule_date <= ( $current_time + $twenty_four_hours_in_seconds ) ) {
			$recipes_data[ $recipe_id ]['scheduled_soon'] = true;
		} else {
			$recipes_data[ $recipe_id ]['scheduled_soon'] = false;
		}
	} else {
		// Default to false if no schedule info or not scheduled.
		$recipes_data[ $recipe_id ]['scheduled_soon'] = false;
	}

	return $recipes_data;
}
add_filter( 'automator_get_recipes_data', 'my_custom_automator_recipes_data_filter', 10, 2 );

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/class-automator-functions.php:923

$closures = array();
			}
			$this->recipes_data[ $recipe_id ]['closures'] = $closures;

			$this->recipes_data[ $recipe_id ]['completed_by_current_user'] = array_key_exists( $recipe_id, $recipes_completed ) ? $recipes_completed[ $recipe_id ] : false;
		}

		$this->recipes_data = apply_filters( 'automator_get_recipes_data', $this->recipes_data, $recipe_id );

		Automator()->cache->set( $this->cache->recipes_data, $this->recipes_data );

		// Persist to transient for non-persistent object cache environments.
		if ( ! wp_using_ext_object_cache() && $this->cache->is_cache_enabled() ) {
			$cacheable_data = array_map(
				static function ( $recipe ) {

Internal Usage

Found in uncanny-automator-pro/src/core/classes/actions-conditions.php:83:

add_filter( 'automator_get_recipes_data', array( $this, 'add_to_recipes_object' ), 10, 2 );
Scroll to Top