-
-
Save peterwilsoncc/de643a6f3ae3271cb2ab6c47f6e2fdf4 to your computer and use it in GitHub Desktop.
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 | |
namespace PWCC\QV_Filter; | |
/** | |
* Test if query string contains phrase in deny list. | |
* | |
* On a production site this would need to be more complex. | |
* | |
* @return bool True: Deny request. False: Allow request | |
*/ | |
function deny() { | |
$query_string = $_SERVER['QUERY_STRING'] ?? ''; | |
$deny = false; | |
$deny_list = [ | |
'pwcc', | |
]; | |
foreach( $deny_list as $deny_item ) { | |
if ( false === stripos( $query_string, $deny_item ) ) { | |
continue; | |
} | |
$deny = true; | |
break; | |
} | |
return $deny; | |
} | |
/** | |
* Send headers. | |
*/ | |
add_filter( 'status_header', function( $status ) { | |
return 403; | |
} ); | |
/** | |
* Prevent query if deny() returns true. | |
*/ | |
add_filter( 'posts_pre_query', function( $null ) { | |
if ( deny() ) { | |
wp_die( 'Please do not do this' ); | |
} | |
return $null; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment