| [ Web Proxy ] |
| Viewing: https://docs.wpvip.com/security-controls/block-origin-requests-with-php/ | [Back] [Original] |
Ready to get started with WordPress VIP? Contact Us
The VIP_Request_Block utility class provides a programmatic way to block unwanted requests at the application level based on IP addresses, user agent strings, and other parameters using PHP.
If an incoming request is blocked by VIP_Request_Block, VIPs CDN will return a 403 Forbidden error response for that request.
VIP_Request_Block are blocked at the origin, not the edge (load balancer). If a request is served from the cache at the edge, it does not reach the origin and cannot be blocked by this class.VIP_Request_Block utility class is only effective for requests that require WordPress to be loaded (e.g. example.com/blog/post-name). The utility class is ineffective for direct file requests (e.g. example.com/wp-includes/blocks/index.php). vip-config/vip-config.php. This ensures that on VIP Platform environments, requests that are intended to be blocked are blocked early before WordPress Core is loaded.VIP_Request_Block are chargeable requests.if ( class_exists( 'VIP_Request_Block' ) ) check to avoid errors.Requests that are blocked with the VIP_Request_Block class are logged in the environment’s Runtime Logs. Any errors that occur related to the VIP_Request_Block class in custom code are also logged in the environment’s Runtime Logs.
Error output in Runtime Logs can be retrieved either in the VIP Dashboard or with VIP-CLI.
For example, if VIP_Request_Block::ip() is called with an invalid IP address, an error will be logged in Runtime Logs.
Logging can be disabled for requests blocked by VIP_Request_Block methods with the disable_logging() function.
Call disable_logging() just before calling the VIP_Request_Block method(s) that should not be logged. Re-enable logging for additional methods by calling enable_logging() then call the methods that should have logging enabled.
In this code example, logging is disabled for blocked requests from the IP address 13.37.13.37 and enabled for requests from User Agent SuspiciousBot/1.1:
// logging for blocked requests is enabled by default
if ( class_exists( 'VIP_Request_Block' ) ) {
// disable logging
VIP_Request_Block::disable_logging();
VIP_Request_Block::ip( '13.37.13.37' );
// enable logging
VIP_Request_Block::enable_logging();
VIP_Request_Block::ua( 'SuspiciousBot/1.1' );
}// logging for blocked requests is enabled by default
if ( class_exists( 'VIP_Request_Block' ) ) {
// disable logging
VIP_Request_Block::disable_logging();
VIP_Request_Block::ip( '13.37.13.37' );
// enable logging
VIP_Request_Block::enable_logging();
VIP_Request_Block::ua( 'SuspiciousBot/1.1' );
}Last updated: December 31, 2025
Documentation is licensed under a
Creative Commons Attribution-ShareAlike 4.0 International License
| Web Proxy Viewer | New URL | Original Page |