Relevanssi – A Better Search - Version 3.5.3

Version Description

  • New filter relevanssi_user_searches_limit to adjust the number of user searches shown in the logs.
  • Old data check is only done on Relevanssi settings page, not on all admin pages. That should improve admin performance.
  • Fixed a fatal error when searching includes private posts.
  • New filter: relevanssi_remote_addr can be used to modify the IP address logged to Relevanssi logs.
  • Blocked CFDB and WooCommerce shortcodes that are causing problems with Relevanssi.
Download this release

Release Info

Developer msaari
Plugin Icon 128x128 Relevanssi – A Better Search
Version 3.5.3
Comparing to
See all releases

Code changes from version 3.5.2 to 3.5.3

lib/common.php CHANGED
@@ -23,8 +23,7 @@ function relevanssi_wpml_filter($data) {
23
  }
24
  elseif (function_exists('icl_object_id') && function_exists('pll_is_translated_post_type')) {
25
  if (pll_is_translated_post_type($hit->post_type)) {
26
- global $polylang;
27
- if ($polylang->model->get_post_language($hit->ID)->slug == ICL_LANGUAGE_CODE) {
28
  $filtered_hits[] = $hit;
29
  }
30
  else if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, ICL_LANGUAGE_CODE)) {
@@ -91,10 +90,12 @@ function relevanssi_object_sort(&$data, $key, $dir = 'desc') {
91
  }
92
 
93
  function relevanssi_show_matches($data, $hit) {
94
- isset($data['body_matches'][$hit]) ? $body = $data['body_matches'][$hit] : $body = "";
95
- isset($data['title_matches'][$hit]) ? $title = $data['title_matches'][$hit] : $title = "";
96
- isset($data['tag_matches'][$hit]) ? $tag = $data['tag_matches'][$hit] : $tag = "";
97
- isset($data['comment_matches'][$hit]) ? $comment = $data['comment_matches'][$hit] : $comment = "";
 
 
98
  isset($data['scores'][$hit]) ? $score = round($data['scores'][$hit], 2) : $score = 0;
99
  isset($data['term_hits'][$hit]) ? $term_hits_a = $data['term_hits'][$hit] : $term_hits_a = array();
100
  arsort($term_hits_a);
@@ -106,8 +107,8 @@ function relevanssi_show_matches($data, $hit) {
106
  }
107
 
108
  $text = get_option('relevanssi_show_matches_text');
109
- $replace_these = array("%body%", "%title%", "%tags%", "%comments%", "%score%", "%terms%", "%total%");
110
- $replacements = array($body, $title, $tag, $comment, $score, $term_hits, $total_hits);
111
 
112
  $result = " " . str_replace($replace_these, $replacements, $text);
113
 
@@ -138,7 +139,7 @@ function relevanssi_update_log($query, $hits) {
138
  }
139
  }
140
 
141
- get_option('relevanssi_log_queries_with_ip') == "on" ? $ip = $_SERVER['REMOTE_ADDR'] : $ip = '';
142
  $q = $wpdb->prepare("INSERT INTO " . $relevanssi_variables['log_table'] . " (query, hits, user_id, ip, time) VALUES (%s, %d, %d, %s, NOW())", $query, intval($hits), $user->ID, $ip);
143
  $wpdb->query($q);
144
  }
@@ -171,8 +172,13 @@ function relevanssi_default_post_ok($post_ok, $doc) {
171
  else {
172
  // Basic WordPress version
173
  $type = relevanssi_get_post_type($doc);
174
- $cap = 'read_private_' . $type . 's';
175
- $cap = apply_filters('relevanssi_private_cap', $cap);
 
 
 
 
 
176
  if (current_user_can($cap)) {
177
  $post_ok = true;
178
  }
23
  }
24
  elseif (function_exists('icl_object_id') && function_exists('pll_is_translated_post_type')) {
25
  if (pll_is_translated_post_type($hit->post_type)) {
26
+ if (PLL()->model->get_post_language($hit->ID)->slug == ICL_LANGUAGE_CODE) {
 
27
  $filtered_hits[] = $hit;
28
  }
29
  else if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, ICL_LANGUAGE_CODE)) {
90
  }
91
 
92
  function relevanssi_show_matches($data, $hit) {
93
+ isset($data['body_matches'][$hit]) ? $body = $data['body_matches'][$hit] : $body = 0;
94
+ isset($data['title_matches'][$hit]) ? $title = $data['title_matches'][$hit] : $title = 0;
95
+ isset($data['tag_matches'][$hit]) ? $tag = $data['tag_matches'][$hit] : $tag = 0;
96
+ isset($data['category_matches'][$hit]) ? $category = $data['category_matches'][$hit] : $category = 0;
97
+ isset($data['taxonomy_matches'][$hit]) ? $taxonomy = $data['taxonomy_matches'][$hit] : $taxonomy = 0;
98
+ isset($data['comment_matches'][$hit]) ? $comment = $data['comment_matches'][$hit] : $comment = 0;
99
  isset($data['scores'][$hit]) ? $score = round($data['scores'][$hit], 2) : $score = 0;
100
  isset($data['term_hits'][$hit]) ? $term_hits_a = $data['term_hits'][$hit] : $term_hits_a = array();
101
  arsort($term_hits_a);
107
  }
108
 
109
  $text = get_option('relevanssi_show_matches_text');
110
+ $replace_these = array("%body%", "%title%", "%tags%", "%categories%", "%taxonomies%", "%comments%", "%score%", "%terms%", "%total%");
111
+ $replacements = array($body, $title, $tag, $category, $taxonomy, $comment, $score, $term_hits, $total_hits);
112
 
113
  $result = " " . str_replace($replace_these, $replacements, $text);
114
 
139
  }
140
  }
141
 
142
+ get_option('relevanssi_log_queries_with_ip') == "on" ? $ip = apply_filters('relevanssi_remote_addr', $_SERVER['REMOTE_ADDR']) : $ip = '';
143
  $q = $wpdb->prepare("INSERT INTO " . $relevanssi_variables['log_table'] . " (query, hits, user_id, ip, time) VALUES (%s, %d, %d, %s, NOW())", $query, intval($hits), $user->ID, $ip);
144
  $wpdb->query($q);
145
  }
172
  else {
173
  // Basic WordPress version
174
  $type = relevanssi_get_post_type($doc);
175
+ if (isset($GLOBALS['wp_post_types'][$type]->cap->read_private_posts)) {
176
+ $cap = $GLOBALS['wp_post_types'][$type]->cap->read_private_posts;
177
+ }
178
+ else {
179
+ // guessing here
180
+ $cap = 'read_private_' . $type . 's';
181
+ }
182
  if (current_user_can($cap)) {
183
  $post_ok = true;
184
  }
lib/excerpts-highlights.php CHANGED
@@ -23,6 +23,7 @@ function relevanssi_do_excerpt($t_post, $query) {
23
 
24
  // These shortcodes cause problems with Relevanssi excerpts
25
  remove_shortcode('layerslider');
 
26
 
27
  $content = apply_filters('relevanssi_pre_excerpt_content', $post->post_content, $post, $query);
28
  $content = apply_filters('the_content', $content);
@@ -74,7 +75,7 @@ function relevanssi_do_excerpt($t_post, $query) {
74
 
75
  $highlight = get_option('relevanssi_highlight');
76
  if ("none" != $highlight) {
77
- if (!is_admin()) {
78
  $query = relevanssi_add_synonyms($query);
79
  $excerpt = relevanssi_highlight_terms($excerpt, $query);
80
  }
@@ -435,10 +436,10 @@ function relevanssi_count_matches($words, $fulltext) {
435
  // The only exception is where we have only two matches in which case we just take the
436
  // first as will be equally distant.
437
  function relevanssi_determine_snip_location($locations, $prevcount) {
438
- if (!is_array($locations)) return 0;
439
 
440
  // If we only have 1 match we dont actually do the for loop so set to the first
441
- $startpos = $locations[0];
442
  $loccount = count($locations);
443
  $smallestdiff = PHP_INT_MAX;
444
 
23
 
24
  // These shortcodes cause problems with Relevanssi excerpts
25
  remove_shortcode('layerslider');
26
+ remove_shortcode('responsive-flipbook');
27
 
28
  $content = apply_filters('relevanssi_pre_excerpt_content', $post->post_content, $post, $query);
29
  $content = apply_filters('the_content', $content);
75
 
76
  $highlight = get_option('relevanssi_highlight');
77
  if ("none" != $highlight) {
78
+ if ( !is_admin() || ( defined( 'DOING_AJAX' ) || DOING_AJAX ) ) {
79
  $query = relevanssi_add_synonyms($query);
80
  $excerpt = relevanssi_highlight_terms($excerpt, $query);
81
  }
436
  // The only exception is where we have only two matches in which case we just take the
437
  // first as will be equally distant.
438
  function relevanssi_determine_snip_location($locations, $prevcount) {
439
+ if (!is_array($locations) || empty($locations)) return 0;
440
 
441
  // If we only have 1 match we dont actually do the for loop so set to the first
442
+ $startpos = $locations[0];
443
  $loccount = count($locations);
444
  $smallestdiff = PHP_INT_MAX;
445
 
lib/indexing.php CHANGED
@@ -311,14 +311,16 @@ function relevanssi_index_doc($indexpost, $remove_first = false, $custom_fields
311
  }
312
 
313
  $index_titles = true;
314
- if (apply_filters('relevanssi_index_titles', $index_titles)) {
315
- $filtered_title = apply_filters('relevanssi_post_title_before_tokenize', $post->post_title, $post);
316
- $titles = relevanssi_tokenize(apply_filters('the_title', $filtered_title, $post->ID), apply_filters('relevanssi_remove_stopwords_in_titles', true));
317
-
318
- if (count($titles) > 0) {
319
- foreach ($titles as $title => $count) {
320
- $n++;
321
- isset($insert_data[$title]['title']) ? $insert_data[$title]['title'] += $count : $insert_data[$title]['title'] = $count;
 
 
322
  }
323
  }
324
  }
@@ -363,7 +365,26 @@ function relevanssi_index_doc($indexpost, $remove_first = false, $custom_fields
363
  remove_shortcode('php'); // PHP Code for Posts
364
  remove_shortcode('watupro'); // Watu PRO doesn't co-operate
365
  remove_shortcode('starbox'); // Starbox shortcode breaks Relevanssi
366
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  $post_before_shortcode = $post;
368
  $contents = do_shortcode($contents);
369
  $post = $post_before_shortcode;
311
  }
312
 
313
  $index_titles = true;
314
+ if (!empty($post->post_title)) {
315
+ if (apply_filters('relevanssi_index_titles', $index_titles)) {
316
+ $filtered_title = apply_filters('relevanssi_post_title_before_tokenize', $post->post_title, $post);
317
+ $titles = relevanssi_tokenize(apply_filters('the_title', $filtered_title, $post->ID), apply_filters('relevanssi_remove_stopwords_in_titles', true));
318
+
319
+ if (count($titles) > 0) {
320
+ foreach ($titles as $title => $count) {
321
+ $n++;
322
+ isset($insert_data[$title]['title']) ? $insert_data[$title]['title'] += $count : $insert_data[$title]['title'] = $count;
323
+ }
324
  }
325
  }
326
  }
365
  remove_shortcode('php'); // PHP Code for Posts
366
  remove_shortcode('watupro'); // Watu PRO doesn't co-operate
367
  remove_shortcode('starbox'); // Starbox shortcode breaks Relevanssi
368
+ remove_shortcode('cfdb-save-form-post'); // Contact Form DB
369
+ remove_shortcode('cfdb-datatable');
370
+ remove_shortcode('cfdb-table');
371
+ remove_shortcode('cfdb-json');
372
+ remove_shortcode('cfdb-value');
373
+ remove_shortcode('cfdb-count');
374
+ remove_shortcode('cfdb-html');
375
+ remove_shortcode('woocommerce_cart'); // WooCommerce
376
+ remove_shortcode('woocommerce_checkout');
377
+ remove_shortcode('woocommerce_order_tracking');
378
+ remove_shortcode('woocommerce_my_account');
379
+ remove_shortcode('woocommerce_edit_account');
380
+ remove_shortcode('woocommerce_change_password');
381
+ remove_shortcode('woocommerce_view_order');
382
+ remove_shortcode('woocommerce_logout');
383
+ remove_shortcode('woocommerce_pay');
384
+ remove_shortcode('woocommerce_thankyou');
385
+ remove_shortcode('woocommerce_lost_password');
386
+ remove_shortcode('woocommerce_edit_address');
387
+
388
  $post_before_shortcode = $post;
389
  $contents = do_shortcode($contents);
390
  $post = $post_before_shortcode;
lib/interface.php CHANGED
@@ -437,7 +437,8 @@ function relevanssi_query_log() {
437
 
438
  echo '<h3>' . __("Common Queries", 'relevanssi') . '</h3>';
439
 
440
- $lead = __("Here you can see the 20 most common user search queries, how many times those
 
441
  queries were made and how many results were found for those queries.", 'relevanssi');
442
 
443
  echo "<p>$lead</p>";
@@ -508,13 +509,15 @@ function relevanssi_date_queries($d, $title, $version = 'good') {
508
  global $wpdb, $relevanssi_variables;
509
  $log_table = $relevanssi_variables['log_table'];
510
 
 
 
511
  if ($version == 'good')
512
  $queries = $wpdb->get_results("SELECT COUNT(DISTINCT(id)) as cnt, query, hits
513
  FROM $log_table
514
  WHERE TIMESTAMPDIFF(DAY, time, NOW()) <= $d
515
  GROUP BY query
516
  ORDER BY cnt DESC
517
- LIMIT 20");
518
 
519
  if ($version == 'bad')
520
  $queries = $wpdb->get_results("SELECT COUNT(DISTINCT(id)) as cnt, query, hits
@@ -523,7 +526,7 @@ function relevanssi_date_queries($d, $title, $version = 'good') {
523
  AND hits = 0
524
  GROUP BY query
525
  ORDER BY cnt DESC
526
- LIMIT 20");
527
 
528
  if (count($queries) > 0) {
529
  echo "<table class='widefat'><thead><tr><th colspan='3'>$title</th></tr></thead><tbody><tr><th>" . __('Query', 'relevanssi') . "</th><th>#</th><th>" . __('Hits', 'relevanssi') . "</th></tr>";
@@ -1221,6 +1224,17 @@ function relevanssi_options_form() {
1221
  EOH;
1222
  }
1223
  ?>
 
 
 
 
 
 
 
 
 
 
 
1224
  </table>
1225
 
1226
  <br /><br />
437
 
438
  echo '<h3>' . __("Common Queries", 'relevanssi') . '</h3>';
439
 
440
+ $limit = apply_filters('relevanssi_user_searches_limit', 20);
441
+ $lead = __("Here you can see the $limit most common user search queries, how many times those
442
  queries were made and how many results were found for those queries.", 'relevanssi');
443
 
444
  echo "<p>$lead</p>";
509
  global $wpdb, $relevanssi_variables;
510
  $log_table = $relevanssi_variables['log_table'];
511
 
512
+ $limit = apply_filters('relevanssi_user_searches_limit', 20);
513
+
514
  if ($version == 'good')
515
  $queries = $wpdb->get_results("SELECT COUNT(DISTINCT(id)) as cnt, query, hits
516
  FROM $log_table
517
  WHERE TIMESTAMPDIFF(DAY, time, NOW()) <= $d
518
  GROUP BY query
519
  ORDER BY cnt DESC
520
+ LIMIT $limit");
521
 
522
  if ($version == 'bad')
523
  $queries = $wpdb->get_results("SELECT COUNT(DISTINCT(id)) as cnt, query, hits
526
  AND hits = 0
527
  GROUP BY query
528
  ORDER BY cnt DESC
529
+ LIMIT $limit");
530
 
531
  if (count($queries) > 0) {
532
  echo "<table class='widefat'><thead><tr><th colspan='3'>$title</th></tr></thead><tbody><tr><th>" . __('Query', 'relevanssi') . "</th><th>#</th><th>" . __('Hits', 'relevanssi') . "</th></tr>";
1224
  EOH;
1225
  }
1226
  ?>
1227
+ <tr style="display:none">
1228
+ <td>
1229
+ Helpful little control field
1230
+ </td>
1231
+ <td>
1232
+ <input type='checkbox' name='relevanssi_index_type_bogus' id='relevanssi_index_type_bogus' checked="checked" />
1233
+ </td>
1234
+ <td>
1235
+ This is our little secret, just for you and me
1236
+ </td>
1237
+ </tr>
1238
  </table>
1239
 
1240
  <br /><br />
lib/search.php CHANGED
@@ -440,16 +440,30 @@ function relevanssi_search($args) {
440
  }
441
 
442
  if ($post_type) {
443
- // the -1 is there to get user profiles and category pages
444
- $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
445
- WHERE posts.post_type IN ($post_type))) OR (doc = -1))";
 
 
 
 
 
 
 
446
  // Clean: $post_type is escaped
447
  }
448
 
449
  if ($post_status) {
450
- // the -1 is there to get user profiles and category pages
451
- $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
452
- WHERE posts.post_status IN ($post_status))) OR (doc = -1))";
 
 
 
 
 
 
 
453
  // Clean: $post_status is escaped
454
  }
455
 
@@ -552,7 +566,6 @@ function relevanssi_search($args) {
552
  // Clean: $query_restrictions is escaped, $term_cond is escaped
553
 
554
  $query = apply_filters('relevanssi_query_filter', $query);
555
-
556
  $matches = $wpdb->get_results($query);
557
 
558
  if (count($matches) < 1) {
@@ -794,7 +807,12 @@ function relevanssi_do_query(&$query) {
794
  else
795
  $q = trim(stripslashes(strtolower($query->query_vars["s"])));
796
 
797
- if (isset($query->query_vars['searchblogs'])) {
 
 
 
 
 
798
  $multi_args['search_blogs'] = $query->query_vars['searchblogs'];
799
  $multi_args['q'] = $q;
800
 
440
  }
441
 
442
  if ($post_type) {
443
+ global $wp_query;
444
+ if ($wp_query->is_admin) {
445
+ $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
446
+ WHERE posts.post_type IN ($post_type))))";
447
+ }
448
+ else {
449
+ $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
450
+ WHERE posts.post_type IN ($post_type))) OR (doc = -1))";
451
+ // the -1 is there to get user profiles and category pages
452
+ }
453
  // Clean: $post_type is escaped
454
  }
455
 
456
  if ($post_status) {
457
+ global $wp_query;
458
+ if ($wp_query->is_admin) {
459
+ $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
460
+ WHERE posts.post_status IN ($post_status))))";
461
+ }
462
+ else {
463
+ // the -1 is there to get user profiles and category pages
464
+ $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
465
+ WHERE posts.post_status IN ($post_status))) OR (doc = -1))";
466
+ }
467
  // Clean: $post_status is escaped
468
  }
469
 
566
  // Clean: $query_restrictions is escaped, $term_cond is escaped
567
 
568
  $query = apply_filters('relevanssi_query_filter', $query);
 
569
  $matches = $wpdb->get_results($query);
570
 
571
  if (count($matches) < 1) {
807
  else
808
  $q = trim(stripslashes(strtolower($query->query_vars["s"])));
809
 
810
+ $search_multisite = false;
811
+ if (isset($query->query_vars['searchblogs']) && (string) get_current_blog_id() != $query->query_vars['searchblogs']) {
812
+ $search_multisite = true;
813
+ }
814
+
815
+ if (isset($query->query_vars['searchblogs']) && $search_multisite) {
816
  $multi_args['search_blogs'] = $query->query_vars['searchblogs'];
817
  $multi_args['q'] = $q;
818
 
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: msaari
3
  Donate link: http://www.relevanssi.com/buy-premium/
4
  Tags: search, relevance, better search
5
- Requires at least: 3.3
6
- Tested up to: 4.4.1
7
- Stable tag: 3.5.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -386,6 +386,13 @@ removing those words helps to make the index smaller and searching faster.
386
 
387
  == Changelog ==
388
 
 
 
 
 
 
 
 
389
  = 3.5.2 =
390
  * Added correct support for `term_taxonomy_id` in the `fields` parameter in tax_queries.
391
 
2
  Contributors: msaari
3
  Donate link: http://www.relevanssi.com/buy-premium/
4
  Tags: search, relevance, better search
5
+ Requires at least: 4.0
6
+ Tested up to: 4.5
7
+ Stable tag: 3.5.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
386
 
387
  == Changelog ==
388
 
389
+ = 3.5.3 =
390
+ * New filter `relevanssi_user_searches_limit` to adjust the number of user searches shown in the logs.
391
+ * Old data check is only done on Relevanssi settings page, not on all admin pages. That should improve admin performance.
392
+ * Fixed a fatal error when searching includes private posts.
393
+ * New filter: `relevanssi_remote_addr` can be used to modify the IP address logged to Relevanssi logs.
394
+ * Blocked CFDB and WooCommerce shortcodes that are causing problems with Relevanssi.
395
+
396
  = 3.5.2 =
397
  * Added correct support for `term_taxonomy_id` in the `fields` parameter in tax_queries.
398
 
relevanssi.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Relevanssi
4
  Plugin URI: http://www.relevanssi.com/
5
  Description: This plugin replaces WordPress search with a relevance-sorting search.
6
- Version: 3.5.2
7
  Author: Mikko Saari
8
  Author URI: http://www.mikkosaari.fi/
9
  */
@@ -101,6 +101,9 @@ function relevanssi_didyoumean($query, $pre, $post, $n = 5, $echo = true) {
101
  }
102
 
103
  function relevanssi_check_old_data() {
 
 
 
104
  if (is_admin()) {
105
  // Version 3.3 removes the cache feature
106
  $cache = get_option('relevanssi_enable_cache', 'nothing');
3
  Plugin Name: Relevanssi
4
  Plugin URI: http://www.relevanssi.com/
5
  Description: This plugin replaces WordPress search with a relevance-sorting search.
6
+ Version: 3.5.3
7
  Author: Mikko Saari
8
  Author URI: http://www.mikkosaari.fi/
9
  */
101
  }
102
 
103
  function relevanssi_check_old_data() {
104
+ $screen = get_current_screen();
105
+ if ($screen->base != 'settings_page_relevanssi-premium/relevanssi') return;
106
+
107
  if (is_admin()) {
108
  // Version 3.3 removes the cache feature
109
  $cache = get_option('relevanssi_enable_cache', 'nothing');
uninstall.php CHANGED
@@ -24,6 +24,7 @@ function relevanssi_uninstall() {
24
  delete_option('relevanssi_excerpt_type');
25
  delete_option('relevanssi_excerpt_allowable_tags');
26
  delete_option('relevanssi_log_queries');
 
27
  delete_option('relevanssi_excat');
28
  delete_option('relevanssi_extag');
29
  delete_option('relevanssi_cat');
24
  delete_option('relevanssi_excerpt_type');
25
  delete_option('relevanssi_excerpt_allowable_tags');
26
  delete_option('relevanssi_log_queries');
27
+ delete_option('relevanssi_log_queries_with_ip');
28
  delete_option('relevanssi_excat');
29
  delete_option('relevanssi_extag');
30
  delete_option('relevanssi_cat');