Action Since 6.9 uncanny-automator

automator_before_recipe_logs_cleared

Fires before all logs for a recipe are cleared. This hook allows extensions (like Pro) to perform cleanup before the log data is removed, such as cancelling scheduled actions in Action Scheduler. Fires before a recipe's logs are cleared, allowing cleanup actions for the specified recipe ID.

add_action( 'automator_before_recipe_logs_cleared', $callback, 10, 1 );

Description

Fires before all logs for a specific recipe are cleared. Developers can use this hook to perform necessary cleanup tasks, like cancelling scheduled actions from Action Scheduler, before the log data is permanently removed for the given recipe ID.


Usage

add_action( 'automator_before_recipe_logs_cleared', 'your_function_name', 10, 1 );

Parameters

$recipe_id (int)
The recipe ID whose logs are being cleared.

Examples

add_action( 'automator_before_recipe_logs_cleared', 'my_custom_log_cleanup_handler', 10, 1 );

/**
 * Example handler to clean up related external data before recipe logs are cleared.
 *
 * This function demonstrates how to use the 'automator_before_recipe_logs_cleared'
 * hook to perform custom cleanup actions. In this example, it simulates deleting
 * temporary cache entries associated with a specific recipe.
 *
 * @param int $recipe_id The ID of the recipe whose logs are about to be cleared.
 */
function my_custom_log_cleanup_handler( int $recipe_id ) {
	// In a real-world scenario, you might interact with a custom database table,
	// external API, or a caching mechanism.
	// For demonstration, we'll just log a message and simulate a cache clear.

	// Get a user-specific identifier for this recipe's logs.
	// In a real plugin, this might be derived from user meta or post meta.
	$cache_key_prefix = 'automator_recipe_' . $recipe_id . '_log_data_';

	// Simulate clearing any cached data related to this recipe's logs.
	// This could involve using delete_transient(), WP_Object_Cache, or a custom cache.
	// For this example, we'll just echo a message.
	error_log( sprintf( 'Custom cleanup: Clearing temporary cache for recipe ID %d. Cache key prefix: %s', $recipe_id, $cache_key_prefix ) );

	// If you were using transients, it might look something like this:
	// global $wpdb;
	// $transients = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", '%' . $wpdb->esc_like( $cache_key_prefix ) . '%' ) );
	// if ( ! empty( $transients ) ) {
	//     foreach ( $transients as $transient_key ) {
	//         delete_transient( str_replace( 'my_site_transient_', '', $transient_key ) ); // Assuming a pattern like my_site_transient_automator_recipe_...
	//     }
	// }

	// No return value is needed for an action hook.
}

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/global-functions.php:794

function clear_recipe_logs( $recipe_id ) {

	/**
	 * Fires before all logs for a recipe are cleared.
	 *
	 * This hook allows extensions (like Pro) to perform cleanup before the log data
	 * is removed, such as cancelling scheduled actions in Action Scheduler.
	 *
	 * @since 6.9
	 *
	 * @param int $recipe_id The recipe ID whose logs are being cleared.
	 */
	do_action( 'automator_before_recipe_logs_cleared', $recipe_id );

	Automator()->db->recipe->clear_activity_log_by_recipe_id( $recipe_id );
}

Internal Usage

Found in src/integrations/linkedin/helpers/linkedin-scheduled-posts-manager.php:93:

add_action( 'automator_before_recipe_logs_cleared', array( $this, 'unschedule_for_recipe' ), 10, 1 );

Found in uncanny-automator-pro/src/core/classes/async-actions.php:71:

add_action( 'automator_before_recipe_logs_cleared', array( $this, 'cancel_scheduled_actions_for_recipe' ), 10, 1 );
Scroll to Top