Filter uncanny-automator

automator_integration_plugin_active

Filters whether a specific automator integration plugin is active, allowing modifications before its status is determined.

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

Description

This filter allows developers to programmatically control whether an integration's plugin is considered active. It's applied before the integration is fully loaded, giving you the power to override the default active status. Developers can return `false` to prevent an integration from loading or `true` to force it active, even if its conditions aren't met.


Usage

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

Parameters

$plugin_active (mixed)
This parameter holds a boolean value indicating whether the plugin related to the integration is currently active.
$this (mixed)
This parameter indicates whether the integration plugin is currently active.

Return Value

The filtered value.


Examples

/**
 * Example: Conditionally disable an integration if a specific plugin is not active.
 *
 * This filter allows developers to prevent an Uncanny Automator integration
 * from being marked as active if a prerequisite plugin is not installed or activated.
 *
 * @param bool $plugin_active The current status of the integration's plugin activity.
 * @param object $this The instance of the integration class calling the filter.
 * @return bool The modified status of the integration's plugin activity.
 */
add_filter( 'automator_integration_plugin_active', function( $plugin_active, $integration_instance ) {
	// Check if the integration instance is for our specific integration (e.g., 'woocommerce').
	// Replace 'woocommerce' with the actual integration slug you want to conditionally control.
	if ( 'woocommerce' === $integration_instance->get_integration() ) {
		// Define the slug of the plugin that must be active for this integration.
		$required_plugin_slug = 'woocommerce/woocommerce.php';

		// Check if the required plugin is active.
		if ( ! is_plugin_active( $required_plugin_slug ) ) {
			// If the required plugin is not active, force this integration to be considered inactive.
			$plugin_active = false;
		}
	}

	// Return the (potentially modified) plugin active status.
	return $plugin_active;
}, 10, 2 );

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/abstract-integration.php:103

final public function __construct( $helpers = null ) {
		$this->helpers = $helpers;
		$this->setup();

		$registration_data = array(
			'name'             => $this->get_name(),
			'icon_svg'         => $this->get_icon_url(),
			'is_third_party'   => $this->get_is_third_party(),
			'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()->set_all_integrations(
			$this->get_integration(),
			$registration_data
		);

		$plugin_active = $this->plugin_active();
		$plugin_active = apply_filters( 'automator_integration_plugin_active', $plugin_active, $this );
		if ( $plugin_active ) {
			Set_Up_Automator::set_active_integration_code( $this->get_integration() );

			$this->load_recipe_parts();

			add_action( 'automator_integrations', array( $this, 'register_integration' ) );
			add_filter( 'uncanny_automator_maybe_add_integration', array( $this, 'override_plugin_status' ), 10, 2 );
		}
	}

Scroll to Top