Filter uncanny-automator

automator_maybe_integration_active

Filters whether an integration is considered active, before checking its status.

add_filter( 'automator_maybe_integration_active', $callback, 10, 2 );

Description

Filters whether an integration is considered active. Developers can use this hook to programmatically disable specific integrations based on custom logic or conditions, overriding the default active status.


Usage

add_filter( 'automator_maybe_integration_active', 'your_function_name', 10, 2 );

Parameters

$active (mixed)
This parameter indicates whether the integration is considered active.
$integration_code (mixed)
This parameter indicates whether the integration is considered active, and can be modified by the filter.

Return Value

The filtered value.


Examples

/**
 * Example filter for 'automator_maybe_integration_active' hook.
 *
 * This callback checks if a specific integration is active by verifying
 * if its corresponding plugin is currently installed and activated.
 *
 * @param bool   $active           The current active status of the integration (usually boolean true/false).
 * @param string $integration_code The unique code identifying the integration (e.g., 'zapier', 'slack').
 *
 * @return bool The updated active status.
 */
add_filter( 'automator_maybe_integration_active', function( $active, $integration_code ) {

	// If the integration code is known and the $active parameter is already true,
	// we can assume it's active and return early.
	if ( $active === true ) {
		return true;
	}

	// Define a mapping of integration codes to their corresponding plugin slugs.
	// This is a simplified example; in a real scenario, this mapping might be
	// more dynamic or come from a configuration.
	$integration_plugin_map = array(
		'zapier' => 'zapier-for-woocommerce/zapier-for-woocommerce.php',
		'slack'  => 'slack-notifications/slack-notifications.php',
		'discord' => 'discord-notifications/discord-notifications.php',
		// Add more integrations and their plugin slugs as needed
	);

	// Check if we have a plugin slug defined for the given integration code.
	if ( isset( $integration_plugin_map[ $integration_code ] ) ) {
		$plugin_slug = $integration_plugin_map[ $integration_code ];

		// Check if the plugin is installed and active using WordPress's built-in functions.
		// is_plugin_active() checks if a plugin is currently activated.
		if ( is_plugin_active( $plugin_slug ) ) {
			return true; // The integration's plugin is active.
		}
	}

	// If the integration code is not recognized or its plugin is not active,
	// return false to indicate the integration is not active.
	return false;

}, 10, 2 ); // Priority 10, accepts 2 arguments.

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/classes/class-set-up-automator.php:222
src/core/integration-loader/class-integration-registrar.php:182

( new Load_Error_Handler() )->handle( $class, $e );
				continue;
			}

			Utilities::add_class_instance( $class, $instance );
			$integration_code = method_exists( $instance, 'get_integration' ) ? $instance->get_integration() : $class::$integration;
			$active           = method_exists( $instance, 'get_integration' ) ? $instance->plugin_active() : $instance->plugin_active( 0, $integration_code );
			$active           = apply_filters( 'automator_maybe_integration_active', $active, $integration_code );

			// Store all integrations (active or not) for name/icon display.
			$integration_name = method_exists( $instance, 'get_name' ) ? $instance->get_name() : '';
			$integration_icon = method_exists( $instance, 'get_integration_icon' ) ? $instance->get_integration_icon() : '';

			if ( ! empty( $integration_icon ) && ! empty( $integration_name ) ) {
				Automator()->set_all_integrations(


Scroll to Top