Filter uncanny-automator

automator_modify_plugin_path

Filters the plugin path before it's used by the automator core for modifications.

add_filter( 'automator_modify_plugin_path', $callback, 10, 1 );

Description

Filters the plugin path used to check if an integration's required plugin is active. Developers can modify the plugin path to influence whether a plugin is considered active, potentially enabling or disabling integrations based on custom logic.


Usage

add_filter( 'automator_modify_plugin_path', 'your_function_name', 10, 1 );

Parameters

$this (mixed)
This parameter contains the file path of the plugin being checked for activation.

Return Value

The filtered value.


Examples

/**
 * Modify the plugin path for a specific integration if needed.
 *
 * This filter allows developers to dynamically change the plugin path that Uncanny Automator
 * uses to check if a specific integration's plugin is active. This is useful if, for example,
 * the integration plugin's main file is not in the standard 'plugin-folder/plugin-file.php' format.
 *
 * In this example, we'll assume we have a custom integration that resides in a different directory structure.
 * If the current integration being checked is for "My Custom Plugin", we'll adjust the path.
 *
 * @param string $plugin_path The default plugin path provided by Uncanny Automator.
 * @return string The modified plugin path, or the original if no modification is needed.
 */
add_filter( 'automator_modify_plugin_path', function ( $plugin_path ) {
	// In a real scenario, you'd likely determine which integration this is.
	// For demonstration, let's assume we have a way to get the current integration object
	// or its identifier if this filter were context-aware.
	// Since the hook is applied inside a class method, $this refers to the integration object.
	// We can access its properties or methods to identify it.
	// Let's assume the integration has a method like get_integration_id() or a property like $integration_id.
	// For this example, we'll hardcode a check for a hypothetical integration ID.

	// IMPORTANT: This is a simplified example. In a real Uncanny Automator integration,
	// the context of '$this' would be available and you would use it to identify the integration.
	// Since we're writing an add_filter callback outside that context, we can't directly use '$this'.
	// We'll simulate checking for an integration ID.

	// Let's assume the default $plugin_path looks like 'my-custom-plugin/my-custom-plugin.php'
	// and we want to check for 'another-plugin-folder/another-plugin-file.php' instead.
	$hypothetical_integration_id = 'my-custom-automation-plugin'; // Replace with an actual integration identifier

	// This check is illustrative. In the actual Uncanny Automator source, you would likely have access
	// to the integration object's properties to make this determination.
	// For example: if ( $this->get_integration_id() === $hypothetical_integration_id ) { ... }

	// Simulate a condition where we want to change the path for a specific integration.
	// If the original path contains 'some-unique-identifier', we'll assume it's our target.
	// A more robust solution would involve checking an integration ID property.
	if ( strpos( $plugin_path, 'uncanny-automator-addon-for-xyz/' ) !== false ) {
		// If this is our specific integration, return the correct plugin path.
		// This might be due to a different directory structure or file name.
		return 'xyz-plugin/xyz-plugin.php';
	}

	// If it's not our specific integration, return the original path.
	return $plugin_path;
}, 10, 1 ); // Priority 10, accepts 1 argument

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:161

public function plugin_active() {
		$plugin = apply_filters( 'automator_modify_plugin_path', $this->get_plugin_file_path() );

		include_once ABSPATH . 'wp-admin/includes/plugin.php';
		$active = ! empty( $plugin ) ? is_plugin_active( $plugin ) : false;

		return apply_filters( 'automator_is_integration_plugin_active', $active, $plugin, $this->get_plugin_file_path() );
	}


Scroll to Top