Created
January 20, 2022 15:05
-
-
Save paulgoodchild/1ccc4a8b665da74d506f002b34778c30 to your computer and use it in GitHub Desktop.
Customize whether a request is blocked in Shield
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare( strict_types=1 ); | |
/** | |
* Use this filter to tell Shield to block a request. | |
* | |
* By default, Shield will block requests solely based on the IP reputation for that site. | |
* | |
* With this filter, you can change these criteria. | |
* | |
* In this example we want to block all access to the WP admin and WP login areas and | |
* restrict it to only IP addresses found on the IP Bypass list. We have to be careful | |
* to not block access to AJAX. | |
*/ | |
add_filter( 'shield/is_request_blocked', function ( $isBlocked ) { | |
// $isBlocked defaults to true if the IP is blocked by Shield. False otherwise. | |
if ( !$isBlocked && !is_ajax() && \Shield\get_ip_state() !== 'bypass' ) { | |
$isBlocked = is_admin() || | |
\FernleafSystems\Wordpress\Services\Services::WpGeneral()->isLoginUrl(); | |
} | |
// ALWAYS return $isBlocked. | |
return $isBlocked; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment