What is a User-Agent?
A User-Agent is a small piece of information your browser, app, or tool sends along with each request to a server. It identifies the software making the request—such as the browser type, version, and operating system.
Servers use the User-Agent string to:
- Adjust responses for compatibility with different browsers or devices.
- Collect statistics about visitors.
- Detect unusual or invalid requests.
Filters
api_security_trusted_user_agents – Only use the trusted list for essential WordPress functionality that must bypass all security checks.
PHP
/**
* Add custom trusted user agents (use with caution)
*/
function my_custom_trusted_user_agents( $trusted_patterns, $user_agent ) {
$custom_patterns = array(
'*EssentialWordPressTool*',
'*CriticalSystemComponent*',
);
return array_merge( $trusted_patterns, $custom_patterns );
}
add_filter( 'api_security_trusted_user_agents', 'my_custom_trusted_user_agents', 10, 2 );
api_security_allowed_user_agents – the list of allowed user agent patterns.
PHP
/**
* Add custom allowed user agents for speed testing tools
*/
function my_custom_allowed_user_agents( $allowed_patterns, $user_agent ) {
// Add your custom patterns here
$custom_patterns = array(
'*MyCustomTool*',
'*AnotherSpeedTest*',
'*PerformanceMonitor*',
);
return array_merge( $allowed_patterns, $custom_patterns );
}
add_filter( 'api_security_allowed_user_agents', 'my_custom_allowed_user_agents', 10, 2 );
Contants
API_SECURITY_UA_REQUIRED
Need the User-Agent to be required for requests, set this constant in your wp-config.php
file to TRUE
.
PHP
define( 'API_SECURITY_UA_REQUIRED', true );