automator_before_disconnect_{dynamic}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filter to allow integrations to perform additional cleanup before default options are cleared Filters allow extra cleanup before default options are cleared during integration disconnection.
add_filter( 'automator_before_disconnect_{dynamic}', $callback, 10, 3 );
Description
Fires before an integration's default settings are cleared during disconnection. Developers can use this filter to register additional options for deletion or perform custom cleanup specific to the integration. The dynamic part of the hook name corresponds to the integration ID.
Usage
add_filter( 'automator_before_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
// Example: Add a custom check before disconnecting a specific integration (e.g., Google Calendar)
// This hook allows you to perform actions just before an integration's connection is severed.
add_filter( 'automator_before_disconnect_google_calendar', function( $response, $data, $settings_object ) {
// Check if the user initiating the disconnection is an administrator.
// If not an admin, prevent disconnection by returning an error response.
if ( ! current_user_can( 'manage_options' ) ) {
$response['success'] = false;
$response['message'] = __( 'Only administrators can disconnect integrations.', 'your-text-domain' );
// IMPORTANT: Return the modified response to halt further processing if needed.
return $response;
}
// If the user is an administrator, you might want to log this action.
// For demonstration, we'll just add a success flag if the above check passes.
// In a real scenario, you might perform cleanup tasks or checks specific to Google Calendar.
// Ensure the original response structure is maintained and potentially add custom data.
if ( ! isset( $response['success'] ) ) {
$response['success'] = true;
}
$response['message'] = __( 'Google Calendar integration disconnection check passed.', 'your-text-domain' );
// The original response array should be returned.
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:177
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
*
*