From a9f3bf0252b01d3a1732c21a41be1e64c9e1dce7 Mon Sep 17 00:00:00 2001 From: Markus Begerow <44146279+markusbegerow@users.noreply.github.com> Date: Thu, 30 Dec 2021 12:49:05 +0100 Subject: [PATCH 1/2] Prevent empty and spammy Searches --- search-meter.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/search-meter.php b/search-meter.php index a1e9eae..0a3ecc7 100644 --- a/search-meter.php +++ b/search-meter.php @@ -10,7 +10,7 @@ Text Domain: search-meter Domain Path: /languages -$Revision: 2278181 $ +$Revision: 2542977 $ INSTRUCTIONS @@ -279,12 +279,17 @@ function tguy_sm_save_search($posts) { // Setting to true will record duplicates (the fact that it's a dupe will be recorded in the // details). This will mess up the stats, but could be useful for troubleshooting. $record_duplicates = apply_filters('search_meter_record_duplicates', false); + $search_string = $wp_query->query_vars['s']; + $len = (strlen($search_string) > 0); + $www = ('www' === substr($search_string, 0, 3)); + $slashes = (false !== strpos($search_string, '/')); if (is_search() && !is_paged() // not the second or subsequent page of a previously-counted search && !tguy_is_admin_interface() // not using the administration console && (0 === $tguy_sm_save_count || $record_duplicates) && (tguy_sm_array_value($_SERVER, 'HTTP_REFERER')) // proper referrer (otherwise could be search engine, cache...) + && ($len or $www or $slashes) ) { $options = get_option('tguy_search_meter'); @@ -295,7 +300,7 @@ function tguy_sm_save_search($posts) { // Get all details of this search // search string is the raw query - $search_string = $wp_query->query_vars['s']; + // search terms is the words in the query $search_terms = $search_string; $search_terms = preg_replace('/[," ]+/', ' ', $search_terms); From 8e905b64bb81ec50edfd3ed9126ee130bd80d996 Mon Sep 17 00:00:00 2001 From: Markus Begerow <44146279+markusbegerow@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:20:03 +0100 Subject: [PATCH 2/2] Update search-meter.php --- search-meter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/search-meter.php b/search-meter.php index 0a3ecc7..44c67d6 100644 --- a/search-meter.php +++ b/search-meter.php @@ -279,6 +279,9 @@ function tguy_sm_save_search($posts) { // Setting to true will record duplicates (the fact that it's a dupe will be recorded in the // details). This will mess up the stats, but could be useful for troubleshooting. $record_duplicates = apply_filters('search_meter_record_duplicates', false); + + // Get all details of this search + // Filter search string $search_string = $wp_query->query_vars['s']; $len = (strlen($search_string) > 0); $www = ('www' === substr($search_string, 0, 3)); @@ -297,9 +300,6 @@ function tguy_sm_save_search($posts) { if (tguy_sm_array_value($options, 'sm_ignore_admin_search') && current_user_can("manage_options")) { return $posts; // EARLY EXIT } - - // Get all details of this search - // search string is the raw query // search terms is the words in the query $search_terms = $search_string;