Filter uncanny-automator

uncanny_automator_maybe_add_integration

Filters whether an integration should be added, allowing modification before it's activated.

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

Description

Fires to determine if an integration should be considered active. Developers can filter the $active status and the $integration code itself. This hook is called before an integration's status is finalized, allowing for custom logic to enable or disable integrations programmatically.


Usage

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

Parameters

$active (mixed)
This parameter indicates whether the integration is currently active.
$integration (mixed)
This parameter indicates whether the integration is currently active.

Return Value

The filtered value.


Examples

/**
 * Example: Conditionally deactivate a specific Uncanny Automator integration.
 *
 * This callback function demonstrates how to use the 'uncanny_automator_maybe_add_integration'
 * filter to programmatically control whether a specific integration is considered active.
 * In this example, we'll prevent the "Mailchimp" integration from being active.
 *
 * @param int    $active       The current active status of the integration (1 for active, 0 for inactive).
 * @param string $integration  The unique code identifier for the integration (e.g., 'mailchimp', 'zapier').
 *
 * @return int The modified active status (1 for active, 0 for inactive).
 */
add_filter(
	'uncanny_automator_maybe_add_integration',
	function ( $active, $integration ) {
		// Define the integration code we want to disable.
		$integration_to_disable = 'mailchimp';

		// If the current integration being checked is the one we want to disable,
		// and it's currently marked as active, force it to be inactive.
		if ( $integration === $integration_to_disable && $active === 1 ) {
			return 0; // Set to inactive
		}

		// Otherwise, return the original active status.
		return $active;
	},
	10, // Priority: 10 is the default.
	2   // Accepted arguments: The filter passes $active and $integration.
);

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/utilities/class-automator-integrations-status.php:58

public function get( $integration = null ) {

		// Sanity check that there was a trigger passed
		if ( null === $integration || ! is_string( $integration ) ) {
			Automator()->wp_error->add_error( 'get_plugin_status', 'ERROR: You are try to get a plugin's status without passing its proper integration code.', $this );

			return null;
		}

		$active = 0;

		if ( in_array( $integration, Set_Up_Automator::$active_integrations_code, true ) ) {
			$active = 1;
		}

		return absint( apply_filters( 'uncanny_automator_maybe_add_integration', $active, $integration ) );
	}

Scroll to Top