Filter uncanny-automator

automator_disable_object_cache

Filters to disable object cache on specific items, allowing custom caching logic.

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

Description

This filter allows developers to programmatically disable the object cache for the Uncanny Automator plugin. Return `true` to disable, and `false` (or the default) to keep the cache active. This is useful for debugging or specific caching environments. It's applied early in the process, before cache operations.


Usage

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

Parameters

$key (mixed)
This parameter represents the current status of the object cache, defaulting to false if no specific value has been set or filtered.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of using the 'automator_disable_object_cache' filter to conditionally disable object caching.
 *
 * This function will return true, effectively disabling the object cache, if the Automator plugin's
 * object cache option is not explicitly set to enabled, or if a specific cache key is on a
 * predefined exclusion list.
 */
add_filter( 'automator_disable_object_cache', function( $should_disable, $cache_key ) {

	// Define a list of specific cache keys that should *always* be disabled,
	// regardless of the plugin's general setting. This might be for debugging
	// or for caches that are known to be problematic with object caching.
	$excluded_cache_keys = array(
		'automator_debug_log_entries',
		'automator_transient_data_for_specific_process',
	);

	// Check if the current cache key is in our exclusion list.
	if ( in_array( $cache_key, $excluded_cache_keys, true ) ) {
		return true; // Disable object caching for this specific key.
	}

	// If the cache key is not explicitly excluded, we rely on the plugin's option.
	// The filter's default value ($should_disable = false) means the cache is enabled
	// by default. Returning false here means the filter doesn't force a disable.
	// The plugin's internal logic will then determine based on its options.
	// If you wanted to *force* disabling the cache unless explicitly enabled by the user,
	// you'd implement more complex logic here based on $should_disable and other conditions.
	// For this example, we're demonstrating how to exclude specific keys.
	return $should_disable; // Let the plugin's default or user setting decide.

}, 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/helpers/class-automator-cache-handler.php:609

public function is_cache_enabled( $key = '' ) {
		if ( null !== $this->cache_enabled ) {
			return $this->cache_enabled;
		}

		$value = automator_get_option( self::OPTION_NAME, '' );

		if ( '' === (string) $value ) {
			// Use filter to check if user has disabled object cache previously.
			// Once the value is saved, no need to run the filter, since it's redundant and inverse.
			// Since the filter is to 'Disable' the cache,
			// we need to inverse the value — true means cache is active.
			$value = ! apply_filters( 'automator_disable_object_cache', false, $key );
		}

		$this->cache_enabled = '0' === $value || false === $value ? false : true;

		return $this->cache_enabled;
	}


Scroll to Top