automator_after_disconnect_{dynamic}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filter to allow integrations to perform additional cleanup after default options are cleared Filters after an integration disconnects, allowing for custom cleanup actions with response and posted data.
add_filter( 'automator_after_disconnect_{dynamic}', $callback, 10, 3 );
Description
Fires after an integration's default settings are cleared during disconnection. Developers can use this filter to perform any custom cleanup actions specific to their integration, such as deleting custom database entries or removing associated files. The actual hook name is dynamic and includes the integration's ID.
Usage
add_filter( 'automator_after_disconnect_{dynamic}', 'your_function_name', 10, 3 );
Parameters
-
$response(array) - The current response array
-
$data(array) - The posted data
-
$this(object) - The integration settings object
Return Value
array Modified response array
Examples
add_filter( 'automator_after_disconnect_google_calendar', function( $response, $data, $google_calendar_settings ) {
// After disconnecting Google Calendar, ensure any cached tokens are removed from user meta.
// This prevents stale tokens from causing issues if the integration is reconnected later.
$user_id = get_current_user_id();
if ( $user_id ) {
delete_user_meta( $user_id, 'google_calendar_cached_token' );
}
// You could also log this event for auditing purposes if needed.
error_log( 'Google Calendar integration disconnected for user ID: ' . $user_id );
return $response;
}, 10, 3 );
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/settings/trait-premium-integration-rest-processing.php:213
private function handle_disconnect( $data = array() ) {
// Set default response
$response = array(
'success' => true,
'reload' => true,
);
// Allow integration to perform any cleanup before default options are cleared and modify response
$response = $this->before_disconnect( $response, $data );
/**
* Filter to allow integrations to perform additional cleanup before default options are cleared
*
* @param array $response The current response array
* @param array $data The posted data
* @param object $this The integration settings object
*
* @return array Modified response array
*
* @example
*
*