Filter uncanny-automator-pro

automator_pro_loop_filter_is_dependency_active

Filter to override the dependency active status for a specific loop filter. Filters dependency active status for a loop filter, allowing custom logic to determine if it's enabled.

add_filter( 'automator_pro_loop_filter_is_dependency_active', $callback, 10, 3 );

Description

This filter hook, `automator_pro_loop_filter_is_dependency_active`, allows developers to programmatically alter whether a specific loop filter's dependencies are considered active. It fires when Uncanny Automator Pro checks dependency status for a loop filter, enabling custom logic for activation or deactivation based on provided filter class name and instance.


Usage

add_filter( 'automator_pro_loop_filter_is_dependency_active', 'your_function_name', 10, 3 );

Parameters

$is_active (bool)
The dependency active status.
$class_name (string)
The filter class name.
$filter (object)
The filter instance.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Deactivate a specific filter's dependency under certain conditions.
 *
 * This example demonstrates how to hook into 'automator_pro_loop_filter_is_dependency_active'
 * to programmatically deactivate the dependency for a filter named 'Uncanny_Automator_Pro_Filters_WooCommerce_Order_Items'
 * if the order ID is greater than 100.
 */
add_filter(
	'automator_pro_loop_filter_is_dependency_active',
	function ( $is_active, $class_name, $filter ) {
		// Check if the current filter is the WooCommerce Order Items filter.
		if ( $class_name === 'Uncanny_Automator_Pro_Filters_WooCommerce_Order_Items' ) {
			// Access the order ID from the filter's arguments.
			// Assuming the order ID is stored in a specific property or method of the filter object.
			// This is a placeholder and might need adjustment based on the actual filter's structure.
			$order_id = false;
			if ( is_callable( array( $filter, 'get_order_id' ) ) ) {
				$order_id = $filter->get_order_id();
			} elseif ( isset( $filter->args['order_id'] ) ) { // Example if args are directly accessible
				$order_id = $filter->args['order_id'];
			}

			// If we successfully retrieved the order ID and it's greater than 100,
			// deactivate the dependency.
			if ( $order_id && absint( $order_id ) > 100 ) {
				return false; // Deactivate the dependency
			}
		}

		// For all other filters, or if the condition above is not met,
		// return the original active status.
		return $is_active;
	},
	10, // Priority: 10 is the default, adjust if needed.
	3   // Accepted arguments: $is_active, $class_name, $filter
);
?>

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

uncanny-automator-pro/src/core/loops/filter/base/entity-filter-base.php:264

protected function is_dependency_active() {
		$is_active = true;
		
		/**
		 * Filter to override the dependency active status for a specific loop filter.
		 *
		 * @param bool   $is_active The dependency active status.
		 * @param string $class_name The filter class name.
		 * @param object $filter The filter instance.
		 */
		return apply_filters( 'automator_pro_loop_filter_is_dependency_active', $is_active, get_class( $this ), $this );
	}

Scroll to Top