Action
uncanny-automator-pro
automator_webhook_index_rebuild
Fires after the webhook index is rebuilt, useful for custom post-rebuild actions.
add_action( 'automator_webhook_index_rebuild', $callback, 10, 1 );
Description
Fires after a webhook URL is updated for a trigger. Developers can hook into this action to perform custom tasks, such as re-indexing webhook data or triggering other processes that rely on the webhook URL. This hook ensures that any downstream actions dependent on the updated webhook URL are executed.
Usage
add_action( 'automator_webhook_index_rebuild', 'your_function_name', 10, 1 );
Examples
// Example of hooking into the 'automator_webhook_index_rebuild' action.
// This action is fired when webhook URLs are updated, indicating a need to rebuild the webhook index.
// This example demonstrates how to clear a cache related to webhook data to ensure
// the latest webhook configurations are reflected.
class My_Automator_Webhook_Handler {
/**
* Constructor.
*/
public function __construct() {
// Hook into the action with a priority of 10 and specify 0 accepted arguments.
// The '0' indicates that this callback function does not accept any arguments passed by the do_action call.
add_action( 'automator_webhook_index_rebuild', array( $this, 'clear_webhook_cache' ), 10, 0 );
}
/**
* Clears a custom cache for webhook data.
* This ensures that any cached webhook information is invalidated after a rebuild.
*/
public function clear_webhook_cache() {
// In a real-world scenario, this might involve deleting transient data,
// clearing an object cache, or performing other cache-related cleanup.
// For demonstration, we'll simulate clearing a cache.
$cache_key = 'automator_processed_webhooks';
// Example: Using WordPress Transients API to clear a cache.
// If you were using a more sophisticated caching mechanism, this would be different.
delete_transient( $cache_key );
// You could also log this event for debugging purposes.
error_log( "Automator webhook index rebuild initiated. Cache '{$cache_key}' cleared." );
}
}
// Instantiate the handler class to register the action.
// In a theme's functions.php or a plugin file, you would typically do this.
new My_Automator_Webhook_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
uncanny-automator-pro/src/core/webhook/class-webhook-url-handler.php:79
public function on_trigger_saved( int $recipe_id, int $trigger_id, string $trigger_code ): void {
$url = $this->generate_url( $recipe_id, $trigger_id, $trigger_code );
if ( null === $url ) {
return;
}
update_post_meta( $trigger_id, 'WEBHOOK_URL', $url );
// The Webhook_Index listener in this same package handles the rebuild.
do_action( 'automator_webhook_index_rebuild' );
}
Internal Usage
Found in uncanny-automator-pro/src/core/webhook/class-webhook-index.php:77:
add_action( 'automator_webhook_index_rebuild', array( $this, 'rebuild' ), 100 );