Relevanssi – A Better Search - Version 4.14.4

Version Description

  • Minor fix: relevanssi_orderby did not always accept an array-format orderby parameter.
  • Minor fix: Removes a highlighting problem stemming from uppercase search terms.
  • Minor fix: Relevanssi removes highlights better from inside multiline HTML tags.
  • Minor fix: When image attachment indexing was disabled, saving image attachments would still index the images. Image attachment blocking is now a relevanssi_indexing_restriction filter function, which means it's always active.
Download this release

Release Info

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

Code changes from version 4.14.3 to 4.14.4

lib/common.php CHANGED
@@ -1785,6 +1785,7 @@ function relevanssi_bot_block_list() : array {
1785
  'Sogou' => 'Sogou',
1786
  'Exalead' => 'Exabot',
1787
  'Majestic' => 'MJ12Bot',
 
1788
  );
1789
  return $bots;
1790
  }
1785
  'Sogou' => 'Sogou',
1786
  'Exalead' => 'Exabot',
1787
  'Majestic' => 'MJ12Bot',
1788
+ 'Ahrefs' => 'AhrefsBot',
1789
  );
1790
  return $bots;
1791
  }
lib/excerpts-highlights.php CHANGED
@@ -573,7 +573,7 @@ function relevanssi_highlight_terms( $content, $query, $convert_entities = false
573
  );
574
 
575
  if ( ! is_array( $query ) ) {
576
- $query = explode( ' ', $query );
577
  }
578
 
579
  $body_stopwords = function_exists( 'relevanssi_fetch_body_stopwords' )
@@ -687,7 +687,7 @@ function relevanssi_highlight_terms( $content, $query, $convert_entities = false
687
  $content
688
  );
689
 
690
- if ( preg_match_all( '/<.*>/U', $content, $matches ) > 0 ) {
691
  // Remove highlights from inside HTML tags.
692
  foreach ( $matches as $match ) {
693
  $new_match = str_replace( $start_emp_token, '', $match );
573
  );
574
 
575
  if ( ! is_array( $query ) ) {
576
+ $query = explode( ' ', relevanssi_strtolower( $query ) );
577
  }
578
 
579
  $body_stopwords = function_exists( 'relevanssi_fetch_body_stopwords' )
687
  $content
688
  );
689
 
690
+ if ( preg_match_all( '/<.*>/Us', $content, $matches ) > 0 ) {
691
  // Remove highlights from inside HTML tags.
692
  foreach ( $matches as $match ) {
693
  $new_match = str_replace( $start_emp_token, '', $match );
lib/indexing.php CHANGED
@@ -9,6 +9,30 @@
9
  */
10
 
11
  add_filter( 'relevanssi_index_get_post_type', 'relevanssi_index_get_post_type', 1, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  /**
14
  * Returns the total number of posts to index.
@@ -99,14 +123,6 @@ function relevanssi_generate_indexing_query( $valid_status, $extend = false, $re
99
  global $wpdb, $relevanssi_variables;
100
  $relevanssi_table = $relevanssi_variables['relevanssi_table'];
101
 
102
- if ( 'off' === get_option( 'relevanssi_index_image_files', 'off' ) ) {
103
- $restriction .= "
104
- AND post.ID NOT IN (
105
- SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment'
106
- AND post_mime_type LIKE 'image%' )
107
- ";
108
- }
109
-
110
  /**
111
  * Filters the WHERE restriction for indexing queries.
112
  *
9
  */
10
 
11
  add_filter( 'relevanssi_index_get_post_type', 'relevanssi_index_get_post_type', 1, 2 );
12
+ add_filter( 'relevanssi_indexing_restriction', 'relevanssi_image_filter' );
13
+
14
+ /**
15
+ * Blocks image attachments from the index.
16
+ *
17
+ * @param array $restriction An array with two values: 'mysql' for the MySQL
18
+ * query and 'reason' for the blocking reason.
19
+ *
20
+ * @return array The image attachment blocking MySQL code, if the image
21
+ * attachments are blocked.
22
+ */
23
+ function relevanssi_image_filter( $restriction ) {
24
+ if ( 'off' === get_option( 'relevanssi_index_image_files', 'off' ) ) {
25
+ global $wpdb;
26
+
27
+ $restriction['mysql'] .= "
28
+ AND post.ID NOT IN (
29
+ SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment'
30
+ AND post_mime_type LIKE 'image%' )";
31
+ $restriction['reason'] .= ' ' . __( 'Relevanssi image attachment filter', 'relevanssi' );
32
+ }
33
+
34
+ return $restriction;
35
+ }
36
 
37
  /**
38
  * Returns the total number of posts to index.
123
  global $wpdb, $relevanssi_variables;
124
  $relevanssi_table = $relevanssi_variables['relevanssi_table'];
125
 
 
 
 
 
 
 
 
 
126
  /**
127
  * Filters the WHERE restriction for indexing queries.
128
  *
lib/log.php CHANGED
@@ -26,27 +26,6 @@ function relevanssi_update_log( $query, $hits ) {
26
  return false;
27
  }
28
 
29
- // Bot filter, by Justin_K.
30
- // See: http://wordpress.org/support/topic/bot-logging-problem-w-tested-solution.
31
- $user_agent = '';
32
- if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
33
- $user_agent = $_SERVER['HTTP_USER_AGENT'];
34
-
35
- /**
36
- * Filters the bots Relevanssi should block from logs.
37
- *
38
- * Lets you filter the bots that are blocked from Relevanssi logs.
39
- *
40
- * @param array $bots An array of bot user agents.
41
- */
42
- $bots = apply_filters( 'relevanssi_bots_to_not_log', relevanssi_bot_block_list() );
43
- foreach ( array_values( $bots ) as $lookfor ) {
44
- if ( false !== stristr( $user_agent, $lookfor ) ) {
45
- return false;
46
- }
47
- }
48
- }
49
-
50
  /**
51
  * Filters the current user for logs.
52
  *
@@ -55,16 +34,11 @@ function relevanssi_update_log( $query, $hits ) {
55
  *
56
  * @param WP_User The current user object.
57
  */
58
- $user = apply_filters( 'relevanssi_log_get_user', wp_get_current_user() );
59
- if ( 0 !== $user->ID && get_option( 'relevanssi_omit_from_logs' ) ) {
60
- $omit = explode( ',', get_option( 'relevanssi_omit_from_logs' ) );
61
- $omit = array_map( 'trim', $omit );
62
- if ( in_array( strval( $user->ID ), $omit, true ) ) {
63
- return false;
64
- }
65
- if ( in_array( $user->user_login, $omit, true ) ) {
66
- return false;
67
- }
68
  }
69
 
70
  $ip = '';
@@ -295,3 +269,37 @@ function relevanssi_export_log() {
295
  echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
296
  die();
297
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  return false;
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  /**
30
  * Filters the current user for logs.
31
  *
34
  *
35
  * @param WP_User The current user object.
36
  */
37
+ $user = apply_filters( 'relevanssi_log_get_user', wp_get_current_user() );
38
+ $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
39
+
40
+ if ( ! relevanssi_is_ok_to_log( $user ) ) {
41
+ return false;
 
 
 
 
 
42
  }
43
 
44
  $ip = '';
269
  echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
270
  die();
271
  }
272
+
273
+ /**
274
+ * Checks if logging the query is ok.
275
+ *
276
+ * Returns false if the user agent is on the blocked bots list or if the
277
+ * current user is on the relevanssi_omit_from_logs option list.
278
+ *
279
+ * @param WP_User $user The current user. If null, gets the value from
280
+ * wp_get_current_user().
281
+ *
282
+ * @return boolean True, if the user is not a bot or not on the omit list.
283
+ */
284
+ function relevanssi_is_ok_to_log( $user = null ) : bool {
285
+ if ( relevanssi_user_agent_is_bot() ) {
286
+ return false;
287
+ }
288
+
289
+ if ( ! $user ) {
290
+ $user = wp_get_current_user();
291
+ }
292
+
293
+ if ( 0 !== $user->ID && get_option( 'relevanssi_omit_from_logs' ) ) {
294
+ $omit = explode( ',', get_option( 'relevanssi_omit_from_logs' ) );
295
+ $omit = array_map( 'trim', $omit );
296
+ if ( in_array( strval( $user->ID ), $omit, true ) ) {
297
+ return false;
298
+ }
299
+ if ( in_array( $user->user_login, $omit, true ) ) {
300
+ return false;
301
+ }
302
+ }
303
+
304
+ return true;
305
+ }
lib/search.php CHANGED
@@ -1577,19 +1577,23 @@ function relevanssi_sort_results( &$hits, $orderby, $order, $meta_query ) {
1577
  */
1578
  $orderby = apply_filters( 'relevanssi_orderby', $orderby );
1579
 
1580
- /**
1581
- * Filters the order parameter before Relevanssi sorts posts.
1582
- *
1583
- * @param string $order The order parameter, either 'asc' or 'desc'.
1584
- * Default 'desc'.
1585
- */
1586
- $order = apply_filters( 'relevanssi_order', $order );
1587
-
1588
- if ( 'relevance' !== $orderby ) {
1589
- // Results are by default sorted by relevance, so no need to sort
1590
- // for that.
1591
- $orderby_array = array( $orderby => $order );
1592
- relevanssi_object_sort( $hits, $orderby_array, $meta_query );
 
 
 
 
1593
  }
1594
  }
1595
  }
1577
  */
1578
  $orderby = apply_filters( 'relevanssi_orderby', $orderby );
1579
 
1580
+ if ( is_array( $orderby ) ) {
1581
+ relevanssi_object_sort( $hits, $orderby, $meta_query );
1582
+ } else {
1583
+ /**
1584
+ * Filters the order parameter before Relevanssi sorts posts.
1585
+ *
1586
+ * @param string $order The order parameter, either 'asc' or 'desc'.
1587
+ * Default 'desc'.
1588
+ */
1589
+ $order = apply_filters( 'relevanssi_order', $order );
1590
+
1591
+ if ( 'relevance' !== $orderby ) {
1592
+ // Results are by default sorted by relevance, so no need to sort
1593
+ // for that.
1594
+ $orderby_array = array( $orderby => $order );
1595
+ relevanssi_object_sort( $hits, $orderby_array, $meta_query );
1596
+ }
1597
  }
1598
  }
1599
  }
lib/tabs/overview-tab.php CHANGED
@@ -90,14 +90,6 @@ function relevanssi_overview_tab() {
90
  <p><?php printf( esc_html__( 'If you like Relevanssi, leaving a five-star review on WordPress.org will help others discover Relevanssi. %1$sYou can add your review here%2$s.', 'relevanssi' ), "<a href='https://wordpress.org/support/plugin/relevanssi/reviews/#new-post'>", '</a>' ); ?></p>
91
  </td>
92
  </tr>
93
- <tr>
94
- <th scope="row">
95
- <?php esc_html_e( 'Relevanssi on Facebook', 'relevanssi' ); ?>
96
- </th>
97
- <td>
98
- <p><a href="https://www.facebook.com/relevanssi"><?php esc_html_e( 'Check out the Relevanssi page on Facebook for news and updates about Relevanssi.', 'relevanssi' ); ?></a></p>
99
- </td>
100
- </tr>
101
  <?php if ( ! RELEVANSSI_PREMIUM ) { ?>
102
  <tr>
103
  <th scope="row">
90
  <p><?php printf( esc_html__( 'If you like Relevanssi, leaving a five-star review on WordPress.org will help others discover Relevanssi. %1$sYou can add your review here%2$s.', 'relevanssi' ), "<a href='https://wordpress.org/support/plugin/relevanssi/reviews/#new-post'>", '</a>' ); ?></p>
91
  </td>
92
  </tr>
 
 
 
 
 
 
 
 
93
  <?php if ( ! RELEVANSSI_PREMIUM ) { ?>
94
  <tr>
95
  <th scope="row">
lib/utils.php CHANGED
@@ -70,7 +70,7 @@ function relevanssi_average_array( array &$array, array $counts ) {
70
  array_walk(
71
  $array,
72
  function ( &$value, $key ) use ( $counts ) {
73
- $value = $value / $counts[ $key ];
74
  }
75
  );
76
  }
@@ -1433,3 +1433,31 @@ function relevanssi_update_sanitized( array $request, string $option, bool $auto
1433
  update_option( $option, $value, $autoload );
1434
  }
1435
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  array_walk(
71
  $array,
72
  function ( &$value, $key ) use ( $counts ) {
73
+ $value = round( $value / $counts[ $key ], 2 );
74
  }
75
  );
76
  }
1433
  update_option( $option, $value, $autoload );
1434
  }
1435
  }
1436
+
1437
+ /**
1438
+ * Returns true if $_SERVER['HTTP_USER_AGENT'] is on the bot block list.
1439
+ *
1440
+ * Looks for bot user agents in the $_SERVER['HTTP_USER_AGENT'] and returns true
1441
+ * if a match is found.
1442
+ *
1443
+ * @return bool True if $_SERVER['HTTP_USER_AGENT'] is a bot.
1444
+ */
1445
+ function relevanssi_user_agent_is_bot() : bool {
1446
+ if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
1447
+ /**
1448
+ * Filters the bots Relevanssi should block from search queries.
1449
+ *
1450
+ * Lets you filter the bots that are blocked from Relevanssi search
1451
+ * queries.
1452
+ *
1453
+ * @param array $bots An array of bot user agents.
1454
+ */
1455
+ $bots = apply_filters( 'relevanssi_bots_to_block', relevanssi_bot_block_list() );
1456
+ foreach ( array_values( $bots ) as $lookfor ) {
1457
+ if ( false !== stristr( $_SERVER['HTTP_USER_AGENT'], $lookfor ) ) {
1458
+ return true;
1459
+ }
1460
+ }
1461
+ }
1462
+ return false;
1463
+ }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: search, relevance, better search, product search, woocommerce search
5
  Requires at least: 4.9
6
  Tested up to: 5.8.1
7
  Requires PHP: 7.0
8
- Stable tag: 4.14.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -59,9 +59,6 @@ Do note that using Relevanssi may require large amounts (hundreds of megabytes)
59
  * [Related posts](https://www.relevanssi.com/knowledge-base/related-posts/).
60
  * [Redirects for searches](https://www.relevanssi.com/user-manual/redirects/).
61
 
62
- = Relevanssi in Facebook =
63
- You can find [Relevanssi in Facebook](https://www.facebook.com/relevanssi).
64
-
65
  == Screenshots ==
66
 
67
  1. Overview page
@@ -131,6 +128,12 @@ Each document database is full of useless words. All the little words that appea
131
  * John Calahan for extensive 4.0 beta testing.
132
 
133
  == Changelog ==
 
 
 
 
 
 
134
  = 4.14.3 =
135
  * Security fix: User searches page had a XSS vulnerability.
136
 
@@ -252,7 +255,10 @@ Each document database is full of useless words. All the little words that appea
252
  * Minor fix: In some cases, having less than or greater than symbols in PDF content would block that PDF content from being indexed.
253
 
254
  == Upgrade notice ==
255
- = 4.14.3
 
 
 
256
  * Security fix: User searches page had a XSS vulnerability.
257
 
258
  = 4.14.2 =
5
  Requires at least: 4.9
6
  Tested up to: 5.8.1
7
  Requires PHP: 7.0
8
+ Stable tag: 4.14.4
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
59
  * [Related posts](https://www.relevanssi.com/knowledge-base/related-posts/).
60
  * [Redirects for searches](https://www.relevanssi.com/user-manual/redirects/).
61
 
 
 
 
62
  == Screenshots ==
63
 
64
  1. Overview page
128
  * John Calahan for extensive 4.0 beta testing.
129
 
130
  == Changelog ==
131
+ = 4.14.4 =
132
+ * Minor fix: `relevanssi_orderby` did not always accept an array-format orderby parameter.
133
+ * Minor fix: Removes a highlighting problem stemming from uppercase search terms.
134
+ * Minor fix: Relevanssi removes highlights better from inside multiline HTML tags.
135
+ * Minor fix: When image attachment indexing was disabled, saving image attachments would still index the images. Image attachment blocking is now a `relevanssi_indexing_restriction` filter function, which means it's always active.
136
+
137
  = 4.14.3 =
138
  * Security fix: User searches page had a XSS vulnerability.
139
 
255
  * Minor fix: In some cases, having less than or greater than symbols in PDF content would block that PDF content from being indexed.
256
 
257
  == Upgrade notice ==
258
+ = 4.14.4 =
259
+ * Small bug fixes.
260
+
261
+ = 4.14.3 =
262
  * Security fix: User searches page had a XSS vulnerability.
263
 
264
  = 4.14.2 =
relevanssi.php CHANGED
@@ -13,7 +13,7 @@
13
  * Plugin Name: Relevanssi
14
  * Plugin URI: https://www.relevanssi.com/
15
  * Description: This plugin replaces WordPress search with a relevance-sorting search.
16
- * Version: 4.14.3
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi
@@ -67,7 +67,7 @@ $relevanssi_variables['database_version'] = 6;
67
  $relevanssi_variables['file'] = __FILE__;
68
  $relevanssi_variables['plugin_dir'] = plugin_dir_path( __FILE__ );
69
  $relevanssi_variables['plugin_basename'] = plugin_basename( __FILE__ );
70
- $relevanssi_variables['plugin_version'] = '4.14.3';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';
13
  * Plugin Name: Relevanssi
14
  * Plugin URI: https://www.relevanssi.com/
15
  * Description: This plugin replaces WordPress search with a relevance-sorting search.
16
+ * Version: 4.14.4
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi
67
  $relevanssi_variables['file'] = __FILE__;
68
  $relevanssi_variables['plugin_dir'] = plugin_dir_path( __FILE__ );
69
  $relevanssi_variables['plugin_basename'] = plugin_basename( __FILE__ );
70
+ $relevanssi_variables['plugin_version'] = '4.14.4';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';