Filter uncanny-automator

automator_api_timeout

Filters the API request timeout in seconds before making the request.

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

Description

Filters the API request timeout. Modify this filter to adjust the default 30-second timeout for API requests made by the core integration. Useful for handling slower API responses or custom integrations. The $request_url parameter allows for conditional timeout adjustments based on the specific API endpoint.


Usage

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

Parameters

$request_url (mixed)
This parameter specifies the default timeout duration in seconds for API requests.

Return Value

The filtered value.


Examples

/**
 * Extend the default API timeout for specific Automator requests.
 *
 * This function hooks into the 'automator_api_timeout' filter to conditionally
 * increase the timeout for API requests that are part of the Automator plugin's
 * internal workings, specifically targeting the license check endpoint.
 *
 * @param int    $timeout      The default timeout in seconds.
 * @param string $request_url The URL of the API request.
 * @return int The modified timeout in seconds.
 */
function my_automator_extended_api_timeout( $timeout, $request_url ) {

	// Check if the request URL matches our specific Automator license check endpoint.
	// Replace 'https://your-automator-domain.com/wp-json/automator/v1/license-check'
	// with the actual URL you want to target.
	$license_check_url_pattern = '/https://your-automator-domain.com/wp-json/automator/v1/license-check/';

	if ( preg_match( $license_check_url_pattern, $request_url ) ) {
		// Increase the timeout to 60 seconds for this specific endpoint.
		// This is useful if license checks might take longer under certain network conditions.
		return 60;
	}

	// For all other Automator API requests, return the original timeout.
	return $timeout;
}
add_filter( 'automator_api_timeout', 'my_automator_extended_api_timeout', 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/classes/class-api-server.php:155

public function default_api_timeout( $timeout, $request_url = '' ) {

		if ( empty( $request_url ) || ! $this->is_api_url( $request_url ) ) {
			return $timeout;
		}

		return apply_filters( 'automator_api_timeout', 30, $request_url );
	}

Scroll to Top