Filter
uncanny-automator
automator_integration_connected
Filters the connected integration status, allowing modification of whether an integration is considered connected.
add_filter( 'automator_integration_connected', $callback, 10, 3 );
Description
This filter allows developers to modify the "connected" status of an integration before it's displayed in the UI. You can return `true` or `false` to programmatically control whether an integration is considered connected. The hook provides the integration object and its data for context.
Usage
add_filter( 'automator_integration_connected', 'your_function_name', 10, 3 );
Parameters
-
$this(mixed) - This parameter represents the integration object itself, providing access to its methods and properties.
-
$this(mixed) - This parameter likely represents the integration object itself, which is being passed to the filter.
-
$this(mixed) - This parameter holds the integration object for which the connection status is being checked.
Return Value
The filtered value.
Examples
add_filter(
'automator_integration_connected',
/**
* Example: Modify the 'connected' status of an integration based on specific conditions.
*
* This filter allows you to programmatically override the default 'connected' status
* of an integration. For instance, you might want to temporarily disable an integration
* if its associated API key has expired or if a required service is down.
*
* @param bool $is_connected The current 'connected' status of the integration (true/false).
* @param string $integration_slug The unique slug of the integration (e.g., 'google_sheets').
* @param object $integration_object The instance of the integration object.
*
* @return bool The modified 'connected' status.
*/
function( $is_connected, $integration_slug, $integration_object ) {
// Example: If the integration is for "My Custom Service" and the user is an administrator,
// we might want to force it to appear as not connected for testing purposes.
if ( 'my_custom_service' === $integration_slug && current_user_can( 'manage_options' ) ) {
// In a real-world scenario, you might check a transient, an option, or an API status.
// For demonstration, we'll just set it to false.
error_log( "Temporarily disabling 'My Custom Service' for admin user." );
return false;
}
// Example: If the integration is "Another Service" and a specific option is not set,
// ensure it's marked as not connected.
if ( 'another_service' === $integration_slug && ! get_option( 'another_service_api_key' ) ) {
return false;
}
// Otherwise, return the original connection status.
return $is_connected;
},
10, // Priority: Default WordPress priority
3 // Accepted arguments: The filter accepts $is_connected, $integration_slug, and $integration_object
);
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/recipe-parts/trait-integrations.php:218
src/core/lib/recipe-parts/abstract-integration.php:326
public function add_integration() {
$registration_data = array(
'name' => $this->get_name(),
'icon_svg' => $this->get_icon_url(),
'connected' => apply_filters( 'automator_integration_connected', $this->get_connected(), $this->integration, $this ),
'settings_url' => $this->get_settings_url(),
'loopable_tokens' => $this->get_loopable_tokens(),
'plugin_file_path' => $this->get_plugin_file_path(),
);
// If uses manifest trait, extract manifest data
if ( $this->uses_manifest_trait() && is_callable( array( $this, 'extract_manifest_data' ) ) ) {
/** @var array $manifest */
$manifest = call_user_func( array( $this, 'extract_manifest_data' ) );
$registration_data['manifest'] = $manifest;
}
Automator()->register->integration(
$this->integration,
$registration_data
);
}