Action uncanny-automator

automator_cache_remove_all

Fires after all Automator caches are cleared, allowing for custom actions upon cache removal.

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

Description

Fires after all Uncanny Automator caches are cleared, including recipe types and the recipe manifest. Developers can hook into this action to perform custom cache clearing operations, ensuring complete data freshness. Use with caution as it triggers a full cache reset.


Usage

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

Examples

<?php

/**
 * Example function to clear additional caches when all Automator caches are removed.
 *
 * This function demonstrates how to hook into the 'automator_cache_remove_all'
 * action to perform custom cache clearing related to other parts of your WordPress site
 * or plugins when Uncanny Automator's main cache is flushed.
 */
class My_Custom_Cache_Handler {

	/**
	 * Initializes the custom cache handler.
	 */
	public function __construct() {
		add_action( 'automator_cache_remove_all', array( $this, 'clear_my_custom_cache' ), 10, 0 );
	}

	/**
	 * Clears custom cache groups or transients.
	 *
	 * This function is hooked into the 'automator_cache_remove_all' action.
	 * It's designed to clear any additional caches that might be affected
	 * by a full Automator cache flush, ensuring data consistency across
	 * different caching mechanisms.
	 *
	 * The 0 indicates that this action callback accepts no arguments.
	 */
	public function clear_my_custom_cache() {
		// Example: Delete a custom WordPress transient.
		// Replace 'my_custom_plugin_data_cache' with your actual transient name.
		delete_transient( 'my_custom_plugin_data_cache' );

		// Example: Delete a custom cache group if you are using a more advanced
		// caching plugin or mechanism that supports group deletion.
		// For instance, if you had a custom cache group named 'my_app_cache'.
		// Assuming a function like 'my_app_cache_delete_group' exists.
		// if ( function_exists( 'my_app_cache_delete_group' ) ) {
		//     my_app_cache_delete_group( 'my_app_cache' );
		// }

		// Log the action for debugging purposes (optional).
		error_log( 'My Custom Cache Handler: Additional caches cleared on Automator flush.' );
	}
}

// Instantiate the custom cache handler.
new My_Custom_Cache_Handler();

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/helpers/class-automator-cache-handler.php:438

public function remove_all() {

		$this->remove( 'automator_integration_directories_loaded' );
		$this->remove( 'automator_get_all_integrations' );
		$this->remove( 'automator_actionified_triggers' );
		$this->remove( $this->recipes_data );
		$this->remove( 'get_recipe_type' );

		// Rebuild the recipe manifest (active codes cache for demand-driven loading).
		Recipe_Manifest::reset();

		automator_cache_delete_group( 'automator' );

		do_action( 'automator_cache_remove_all' );
	}

Internal Usage

Found in uncanny-automator-pro/src/core/includes/automator-pro-cache-handler.php:32:

add_action( 'automator_cache_remove_all', array( $this, 'remove_all' ) );
Scroll to Top