Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@paulgoodchild
Created January 20, 2022 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulgoodchild/1ccc4a8b665da74d506f002b34778c30 to your computer and use it in GitHub Desktop.
Save paulgoodchild/1ccc4a8b665da74d506f002b34778c30 to your computer and use it in GitHub Desktop.
Customize whether a request is blocked in Shield
<?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