Version Description
- Settings for search history size and recording duplicates can now be altered in filters. See the code for details. (Thanks to Dan Harrison)
- Fixed a problem with saving hit counts. (Thanks to vrocks)
Download this release
Release Info
Developer | bennettmcelwee |
Plugin | Search Meter |
Version | 2.11 |
Comparing to | |
See all releases |
Code changes from version 2.10 to 2.11
- readme.txt +5 -1
- search-meter.php +30 -31
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://thunderguy.com/semicolon/donate/
|
|
4 |
Tags: search, meter, search-meter, statistics, widget, admin, keywords, terms, search terms
|
5 |
Requires at least: 3.2
|
6 |
Tested up to: 4.3
|
7 |
-
Stable tag: 2.
|
8 |
|
9 |
Search Meter tracks what your readers are searching for on your blog. View full details of recent searches or stats for the last day, week or month.
|
10 |
|
@@ -79,6 +79,10 @@ The [Search Meter home page](http://thunderguy.com/semicolon/wordpress/search-me
|
|
79 |
|
80 |
== Changelog ==
|
81 |
|
|
|
|
|
|
|
|
|
82 |
= 2.10 =
|
83 |
* Add an option to ignore searches made by logged-in administrators, so administrators can test searches without cluttering up the search stats.
|
84 |
* Requires WP 3.2.
|
4 |
Tags: search, meter, search-meter, statistics, widget, admin, keywords, terms, search terms
|
5 |
Requires at least: 3.2
|
6 |
Tested up to: 4.3
|
7 |
+
Stable tag: 2.10
|
8 |
|
9 |
Search Meter tracks what your readers are searching for on your blog. View full details of recent searches or stats for the last day, week or month.
|
10 |
|
79 |
|
80 |
== Changelog ==
|
81 |
|
82 |
+
= 2.11 =
|
83 |
+
* Settings for search history size and recording duplicates can now be altered in filters. See the code for details. (Thanks to Dan Harrison)
|
84 |
+
* Fixed a problem with saving hit counts. (Thanks to vrocks)
|
85 |
+
|
86 |
= 2.10 =
|
87 |
* Add an option to ignore searches made by logged-in administrators, so administrators can test searches without cluttering up the search stats.
|
88 |
* Requires WP 3.2.
|
search-meter.php
CHANGED
@@ -3,12 +3,12 @@
|
|
3 |
Plugin Name: Search Meter
|
4 |
Plugin URI: http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
|
5 |
Description: Keeps track of what your visitors are searching for. After you have activated this plugin, you can check the Search Meter section in the Dashboard to see what your visitors are searching for on your blog.
|
6 |
-
Version: 2.
|
7 |
Author: Bennett McElwee
|
8 |
Author URI: http://thunderguy.com/semicolon/
|
9 |
Donate link: http://thunderguy.com/semicolon/donate/
|
10 |
|
11 |
-
$Revision:
|
12 |
|
13 |
|
14 |
INSTRUCTIONS
|
@@ -27,7 +27,7 @@ INSTRUCTIONS
|
|
27 |
sm_list_recent_searches() template tags.
|
28 |
* For full details, see http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
|
29 |
|
30 |
-
Thanks to
|
31 |
|
32 |
|
33 |
Copyright (C) 2005-15 Bennett McElwee (bennett at thunderguy dotcom)
|
@@ -51,25 +51,6 @@ function tguy_sm_array_value(&$array, $key) {
|
|
51 |
}
|
52 |
|
53 |
|
54 |
-
// Parameters (you can change these if you know what you're doing)
|
55 |
-
|
56 |
-
define('TGUY_SM_HISTORY_SIZE', 500);
|
57 |
-
// The number of recent searches that will be saved. The table can
|
58 |
-
// contain up to 100 more rows than this number
|
59 |
-
|
60 |
-
define('TGUY_SM_ALLOW_EMPTY_REFERER', false);
|
61 |
-
// Searches with an empty referer header are often bogus requests
|
62 |
-
// from Google's AdSense crawler or something similar, so they are
|
63 |
-
// excluded. Set this to true to record all such searches.
|
64 |
-
|
65 |
-
define('TGUY_SM_ALLOW_DUPLICATE_SAVES', false);
|
66 |
-
// It may be that the filter gets called more than once for a given
|
67 |
-
// request. Search Meter ignores these duplicates. Set this to true
|
68 |
-
// to record duplicates (the fact that it's a dupe will be recorded
|
69 |
-
// in the details). This will mess up the stats, but could be useful
|
70 |
-
// for troubleshooting.
|
71 |
-
|
72 |
-
|
73 |
if (is_admin()) {
|
74 |
require_once dirname(__FILE__) . '/admin.php';
|
75 |
register_activation_hook(__FILE__, 'tguy_sm_init');
|
@@ -277,11 +258,18 @@ function tguy_sm_save_search($posts) {
|
|
277 |
// This is a filter but does not change the posts.
|
278 |
global $wpdb, $wp_query, $tguy_sm_save_count;
|
279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
if (is_search()
|
281 |
&& !is_paged() // not the second or subsequent page of a previously-counted search
|
282 |
&& !is_admin() // not using the administration console
|
283 |
-
&& (0 === $tguy_sm_save_count ||
|
284 |
-
&& (tguy_sm_array_value($_SERVER, 'HTTP_REFERER')
|
285 |
) {
|
286 |
$options = get_option('tguy_search_meter');
|
287 |
|
@@ -304,7 +292,7 @@ function tguy_sm_save_search($posts) {
|
|
304 |
// Other useful details of the search
|
305 |
$details = '';
|
306 |
if (tguy_sm_array_value($options, 'sm_details_verbose')) {
|
307 |
-
if (
|
308 |
$details .= "Search Meter save count: $tguy_sm_save_count\n";
|
309 |
}
|
310 |
foreach (array('REQUEST_URI','REQUEST_METHOD','QUERY_STRING','REMOTE_ADDR','HTTP_USER_AGENT','HTTP_REFERER')
|
@@ -318,20 +306,31 @@ function tguy_sm_save_search($posts) {
|
|
318 |
INSERT INTO `{$wpdb->prefix}searchmeter_recent` (`terms`,`datetime`,`hits`,`details`)
|
319 |
VALUES (%s, NOW(), %d, %s)",
|
320 |
$search_string,
|
321 |
-
$
|
322 |
$details
|
323 |
));
|
|
|
324 |
if ($success) {
|
325 |
-
|
326 |
$rowcount = $wpdb->get_var(
|
327 |
"SELECT count(`datetime`) as rowcount
|
328 |
FROM `{$wpdb->prefix}searchmeter_recent`");
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
"SELECT `datetime`
|
333 |
FROM `{$wpdb->prefix}searchmeter_recent`
|
334 |
-
ORDER BY `datetime` DESC LIMIT
|
|
|
335 |
$query = "DELETE FROM `{$wpdb->prefix}searchmeter_recent` WHERE `datetime` < '$dateZero'";
|
336 |
$success = $wpdb->query($query);
|
337 |
}
|
3 |
Plugin Name: Search Meter
|
4 |
Plugin URI: http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
|
5 |
Description: Keeps track of what your visitors are searching for. After you have activated this plugin, you can check the Search Meter section in the Dashboard to see what your visitors are searching for on your blog.
|
6 |
+
Version: 2.11
|
7 |
Author: Bennett McElwee
|
8 |
Author URI: http://thunderguy.com/semicolon/
|
9 |
Donate link: http://thunderguy.com/semicolon/donate/
|
10 |
|
11 |
+
$Revision: 1247517 $
|
12 |
|
13 |
|
14 |
INSTRUCTIONS
|
27 |
sm_list_recent_searches() template tags.
|
28 |
* For full details, see http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
|
29 |
|
30 |
+
Thanks to everyone who has suggested improvements. It takes a village to build a plugin.
|
31 |
|
32 |
|
33 |
Copyright (C) 2005-15 Bennett McElwee (bennett at thunderguy dotcom)
|
51 |
}
|
52 |
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
if (is_admin()) {
|
55 |
require_once dirname(__FILE__) . '/admin.php';
|
56 |
register_activation_hook(__FILE__, 'tguy_sm_init');
|
258 |
// This is a filter but does not change the posts.
|
259 |
global $wpdb, $wp_query, $tguy_sm_save_count;
|
260 |
|
261 |
+
// The filter may get called more than once for a given request. We ignore these duplicates.
|
262 |
+
// Recording duplicate searches can be enabled by adding this line to functions.php:
|
263 |
+
// add_filter('search_meter_record_duplicates', function() { return true; });
|
264 |
+
// Setting to true will record duplicates (the fact that it's a dupe will be recorded in the
|
265 |
+
// details). This will mess up the stats, but could be useful for troubleshooting.
|
266 |
+
$record_duplicates = apply_filters('search_meter_record_duplicates', false);
|
267 |
+
|
268 |
if (is_search()
|
269 |
&& !is_paged() // not the second or subsequent page of a previously-counted search
|
270 |
&& !is_admin() // not using the administration console
|
271 |
+
&& (0 === $tguy_sm_save_count || $record_duplicates)
|
272 |
+
&& (tguy_sm_array_value($_SERVER, 'HTTP_REFERER')) // proper referrer (otherwise could be search engine, cache...)
|
273 |
) {
|
274 |
$options = get_option('tguy_search_meter');
|
275 |
|
292 |
// Other useful details of the search
|
293 |
$details = '';
|
294 |
if (tguy_sm_array_value($options, 'sm_details_verbose')) {
|
295 |
+
if ($record_duplicates) {
|
296 |
$details .= "Search Meter save count: $tguy_sm_save_count\n";
|
297 |
}
|
298 |
foreach (array('REQUEST_URI','REQUEST_METHOD','QUERY_STRING','REMOTE_ADDR','HTTP_USER_AGENT','HTTP_REFERER')
|
306 |
INSERT INTO `{$wpdb->prefix}searchmeter_recent` (`terms`,`datetime`,`hits`,`details`)
|
307 |
VALUES (%s, NOW(), %d, %s)",
|
308 |
$search_string,
|
309 |
+
$hit_count,
|
310 |
$details
|
311 |
));
|
312 |
+
|
313 |
if ($success) {
|
314 |
+
|
315 |
$rowcount = $wpdb->get_var(
|
316 |
"SELECT count(`datetime`) as rowcount
|
317 |
FROM `{$wpdb->prefix}searchmeter_recent`");
|
318 |
+
|
319 |
+
// History size can be overridden by a user by adding a line like this to functions.php:
|
320 |
+
// add_filter('search_meter_history_size', function() { return 50000; });
|
321 |
+
$history_size = apply_filters('search_meter_history_size', 500);
|
322 |
+
|
323 |
+
// Ensure history table never grows larger than (history size) + 100; truncate it
|
324 |
+
// to (history size) when it gets too big. (This we way will only truncate the table
|
325 |
+
// every 100 searches, rather than every time.)
|
326 |
+
if ($history_size + 100 < $rowcount)
|
327 |
+
{
|
328 |
+
// find time of ($history_size)th entry; delete everything before that
|
329 |
+
$dateZero = $wpdb->get_var($wpdb->prepare(
|
330 |
"SELECT `datetime`
|
331 |
FROM `{$wpdb->prefix}searchmeter_recent`
|
332 |
+
ORDER BY `datetime` DESC LIMIT %d, 1", $history_size));
|
333 |
+
|
334 |
$query = "DELETE FROM `{$wpdb->prefix}searchmeter_recent` WHERE `datetime` < '$dateZero'";
|
335 |
$success = $wpdb->query($query);
|
336 |
}
|