Action
uncanny-automator
automator_cache_reset_integrations_directory
Fires after the integrations directory cache is reset, allowing for custom actions related to the plugin and network-wide status.
add_action( 'automator_cache_reset_integrations_directory', $callback, 10, 2 );
Description
Fires after integration directories are reset. Developers can use this hook to clear any custom caches or perform actions related to integration directories being reset. This ensures data consistency across your WordPress site and any multisite networks.
Usage
add_action( 'automator_cache_reset_integrations_directory', 'your_function_name', 10, 2 );
Parameters
-
$plugin(mixed) - This parameter represents the plugin being processed.
-
$network_wide(mixed) - This parameter indicates the specific plugin for which the integration directory cache is being reset.
Examples
/**
* Example callback function for the 'automator_cache_reset_integrations_directory' action hook.
* This function demonstrates how to clear specific integration-related caches when the hook is fired.
*
* @param string|null $plugin The slug of the plugin for which to reset caches, or null for all plugins.
* @param bool $network_wide Whether to reset caches network-wide.
*/
function my_automator_reset_integration_caches( $plugin = null, $network_wide = false ) {
// In a real-world scenario, you'd likely interact with a caching service or object.
// For this example, we'll simulate clearing cache entries.
// Get an instance of the Automator cache handler (assuming it's accessible or can be instantiated)
// This part is hypothetical, as the original context shows a method within a class.
// In a real plugin, you'd call this from within a class that has access to the cache handler,
// or instantiate it if it's a standalone class.
if ( class_exists( 'Automator_Cache_Handler' ) ) {
$cache_handler = new Automator_Cache_Handler(); // Assuming a public constructor or singleton
// Clear specific cached data related to integrations
$cache_handler->remove( 'automator_integration_directories_loaded' );
$cache_handler->remove( 'automator_get_all_integrations' );
$cache_handler->remove( 'automator_actionified_triggers' );
// If $plugin is provided, you might want to clear plugin-specific cache keys.
if ( $plugin ) {
// Example: clear a cache key specific to this plugin
$cache_handler->remove( 'automator_integrations_' . sanitize_key( $plugin ) );
}
// If $network_wide is true, you might perform network-wide cache operations
if ( $network_wide ) {
// Example: In a multisite setup, you might iterate through sites or use network functions.
// This is highly dependent on the caching mechanism.
error_log( 'Automator: Network-wide integration cache reset requested.' );
}
error_log( 'Automator: Integration caches cleared.' );
} else {
error_log( 'Automator: Automator_Cache_Handler class not found. Cannot clear caches.' );
}
}
add_action( 'automator_cache_reset_integrations_directory', 'my_automator_reset_integration_caches', 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/helpers/class-automator-cache-handler.php:302
public function reset_integrations_directory( $plugin, $network_wide ) {
$this->remove( 'automator_integration_directories_loaded' );
$this->remove( 'automator_get_all_integrations' );
$this->remove( 'automator_actionified_triggers' );
do_action( 'automator_cache_reset_integrations_directory', $plugin, $network_wide );
}