Filter
uncanny-automator
automator_rest_authentication_service
Filters the authentication service for Uncanny Automator REST API requests before permission verification.
add_filter( 'automator_rest_authentication_service', $callback, 10, 1 );
Description
Allows developers to customize the REST API authentication service used by Uncanny Automator. This filter hook fires when the REST API authentication is being set up. Developers can return a different callable to replace the default permission verification, enabling custom authentication logic or disabling nonce checks during development.
Usage
add_filter( 'automator_rest_authentication_service', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter(
'automator_rest_authentication_service',
function ( $authentication_callback ) {
// Example: In a staging environment, bypass the default permission check for easier testing.
// In a real scenario, you would check for a specific constant or option.
if ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE === 'staging' ) {
// Return a callback that always returns true, effectively disabling the check.
// Ensure this callback is safe and doesn't introduce security vulnerabilities.
return function () {
return true;
};
}
// Otherwise, return the original callback to maintain default behavior.
return $authentication_callback;
},
10, // Priority
1 // Accepted args
);
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/services/rest-routes.php:50
* @since 4.12
*/
function rest_api_init( WP_REST_Server $wp_rest_server ) {
require_once UA_ABSPATH . 'src/core/services/rest/auth/auth.php';
// Overwride with a function that returns true to disable nonce check. This is done during development mode.
$authentication = apply_filters(
'automator_rest_authentication_service',
array( Uncanny_AutomatorRestAuthAuth::class, 'verify_permission' )
);
/**
* Registers the email endpoint for testing.
*