Filter uncanny-automator-pro

automator_async_batch_size

Filters the size of batches processed asynchronously by the Automator core functionality.

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

Description

Fires when determining the batch size for asynchronous actions processed by Action Scheduler. Developers can use this filter to modify the default batch size (100) to optimize performance or manage server load. The returned value will be used to control how many actions are processed in a single batch.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Increase the batch size for Uncanny Automator's asynchronous actions
 * if the site is experiencing high load or needs to process more items at once.
 *
 * @param int $batch_size The current batch size.
 * @return int The adjusted batch size.
 */
add_filter(
	'automator_async_batch_size',
	function( $batch_size ) {
		// Check if a specific option is set to override the default batch size.
		// For example, a user might want to set it to 200.
		$custom_batch_size = get_option( 'uncanny_automator_pro_custom_async_batch_size', 0 );

		if ( $custom_batch_size > 0 ) {
			// Ensure the custom batch size is at least the default.
			return max( (int) $batch_size, (int) $custom_batch_size );
		}

		// If no custom option is set, we can potentially increase it based on server resources,
		// though for this example, we'll stick to a direct override if available.
		// A more complex example might check for memory limits or other server metrics.

		// Return the original batch size if no custom override is found.
		return $batch_size;
	},
	10, // Priority
	1  // Accepted arguments
);

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/classes/async-actions.php:1471

public function adjust_batch_size( $batch_size ) {
		$automator_size = apply_filters( 'automator_async_batch_size', 100 );

		return max( (int) $batch_size, $automator_size );
	}


Scroll to Top