Last active
December 3, 2024 22:37
-
-
Save lumpysimon/dd2c8043bc271acb497dc2dd8368ebde to your computer and use it in GitHub Desktop.
Exclude spammy searches from SearchWP
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
add_filter( 'searchwp\statistics\log', 'my_log_filter', 10, 2 ); | |
function my_log_filter( $enabled, $query ) { | |
$search_string = $query->get_keywords(); | |
$long = ( strlen( $search_string ) > 30 ); | |
$www = ( 'www' === substr( $search_string, 0, 3 ) ); | |
$slashes = ( false !== strpos( $search_string, '/' ) ); | |
if ( $long or $www or $slashes ) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment