Relevanssi – A Better Search - Version 4.0.6

Version Description

  • Indexing bugs squashed.
  • Missing tag and category weight settings returned.
  • Fusion builder shortcodes are removed from excerpts.
  • MemberPress post control was backwards.
  • User searches page reset buttons fixed.
  • WPML language filter fix.
Download this release

Release Info

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

Code changes from version 4.0.5 to 4.0.6

lib/admin_scripts_free.js CHANGED
@@ -2,7 +2,8 @@ jQuery(document).ready(function($) {
2
  $("#build_index").click(function() {
3
  $("#relevanssi-progress").show();
4
  $("#results").show();
5
- $("#relevanssi-timer").show();
 
6
  $("#stateoftheindex").html(relevanssi.reload_state);
7
  $("#indexing_button_instructions").hide();
8
  var results = document.getElementById("results");
2
  $("#build_index").click(function() {
3
  $("#relevanssi-progress").show();
4
  $("#results").show();
5
+ $("#relevanssi-timer").show();
6
+ $("#relevanssi-indexing-instructions").show();
7
  $("#stateoftheindex").html(relevanssi.reload_state);
8
  $("#indexing_button_instructions").hide();
9
  var results = document.getElementById("results");
lib/common.php CHANGED
@@ -50,7 +50,7 @@ function relevanssi_wpml_filter( $data ) {
50
  if ( $sitepress->is_translated_post_type( $hit->post_type ) ) {
51
  $id = apply_filters( 'wpml_object_id', $hit->ID, $hit->post_type, false );
52
  // This is a post in a translated post type.
53
- if ( $id === $hit->ID ) {
54
  // The post exists in the current language, and can be included.
55
  $filtered_hits[] = $hit;
56
  }
@@ -703,7 +703,7 @@ function relevanssi_default_post_ok( $post_ok, $post_id ) {
703
  if ( class_exists( 'MeprUpdateCtrl' ) && MeprUpdateCtrl::is_activated() ) {
704
  // Memberpress.
705
  $post = get_post( $post_id );
706
- $post_ok = MeprRule::is_locked( $post );
707
  }
708
  if ( defined( 'SIMPLE_WP_MEMBERSHIP_VER' ) ) {
709
  // Simple Membership.
@@ -2001,3 +2001,25 @@ function relevanssi_flatten_array( array $array ) {
2001
  }
2002
  return $return_value;
2003
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  if ( $sitepress->is_translated_post_type( $hit->post_type ) ) {
51
  $id = apply_filters( 'wpml_object_id', $hit->ID, $hit->post_type, false );
52
  // This is a post in a translated post type.
53
+ if ( intval( $hit->ID ) === $id ) {
54
  // The post exists in the current language, and can be included.
55
  $filtered_hits[] = $hit;
56
  }
703
  if ( class_exists( 'MeprUpdateCtrl' ) && MeprUpdateCtrl::is_activated() ) {
704
  // Memberpress.
705
  $post = get_post( $post_id );
706
+ $post_ok = ! MeprRule::is_locked( $post );
707
  }
708
  if ( defined( 'SIMPLE_WP_MEMBERSHIP_VER' ) ) {
709
  // Simple Membership.
2001
  }
2002
  return $return_value;
2003
  }
2004
+
2005
+ /**
2006
+ * Sanitizes hex color strings.
2007
+ *
2008
+ * A copy of sanitize_hex_color(), because that isn't always available.
2009
+ *
2010
+ * @param string $color A hex color string to sanitize.
2011
+ *
2012
+ * @return string Sanitized hex string, or an empty string.
2013
+ */
2014
+ function relevanssi_sanitize_hex_color( $color ) {
2015
+ if ( '' === $color ) {
2016
+ return '';
2017
+ }
2018
+
2019
+ // 3 or 6 hex digits, or the empty string.
2020
+ if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
2021
+ return $color;
2022
+ }
2023
+
2024
+ return '';
2025
+ }
lib/indexing.php CHANGED
@@ -1034,7 +1034,7 @@ function relevanssi_index_taxonomy_terms( $post = null, $taxonomy = '', $insert_
1034
  $insert_data[ $token ]['taxonomy'] += $count;
1035
  }
1036
  if ( isset( $insert_data[ $token ]['taxonomy_detail'] ) ) {
1037
- $tax_detail = json_decode( $insert_data[ $token ]['taxonomy_detail'] );
1038
  } else {
1039
  $tax_detail = array();
1040
  }
1034
  $insert_data[ $token ]['taxonomy'] += $count;
1035
  }
1036
  if ( isset( $insert_data[ $token ]['taxonomy_detail'] ) ) {
1037
+ $tax_detail = json_decode( $insert_data[ $token ]['taxonomy_detail'], true );
1038
  } else {
1039
  $tax_detail = array();
1040
  }
lib/interface.php CHANGED
@@ -69,68 +69,6 @@ function relevanssi_options() {
69
  echo "<div style='clear:both'></div></div>";
70
  }
71
 
72
- /**
73
- * Prints out the 'User searches' page.
74
- */
75
- function relevanssi_search_stats() {
76
- $relevanssi_hide_branding = get_option( 'relevanssi_hide_branding' );
77
-
78
- if ( 'on' === $relevanssi_hide_branding ) {
79
- $options_txt = __( 'User searches', 'relevanssi' );
80
- } else {
81
- $options_txt = __( 'Relevanssi User Searches', 'relevanssi' );
82
- }
83
-
84
- if ( isset( $_REQUEST['relevanssi_reset'] ) && current_user_can( 'manage_options' ) ) {
85
- check_admin_referer( 'relevanssi_reset_logs', '_relresnonce' );
86
- if ( isset( $_REQUEST['relevanssi_reset_code'] ) ) {
87
- if ( 'reset' === $_REQUEST['relevanssi_reset_code'] ) {
88
- $verbose = true;
89
- relevanssi_truncate_logs( $verbose );
90
- }
91
- }
92
- }
93
-
94
- wp_enqueue_style( 'dashboard' );
95
- wp_print_styles( 'dashboard' );
96
- wp_enqueue_script( 'dashboard' );
97
- wp_print_scripts( 'dashboard' );
98
-
99
- printf( "<div class='wrap'><h2>%s</h2>", esc_html( $options_txt ) );
100
-
101
- if ( 'on' === get_option( 'relevanssi_log_queries' ) ) {
102
- relevanssi_query_log();
103
- } else {
104
- printf( '<p>%s</p>', esc_html__( 'Enable query logging to see stats here.', 'relevanssi' ) );
105
- }
106
- }
107
-
108
- /**
109
- * Truncates the Relevanssi logs.
110
- *
111
- * @global object $wpdb The WP database interface.
112
- * @global array $relevanssi_variables The global Relevanssi variables array.
113
- *
114
- * @param boolean $verbose If true, prints out a notice. Default true.
115
- *
116
- * @return boolean True if success, false if failure.
117
- */
118
- function relevanssi_truncate_logs( $verbose = true ) {
119
- global $wpdb, $relevanssi_variables;
120
-
121
- $result = $wpdb->query( 'TRUNCATE ' . $relevanssi_variables['log_table'] ); // WPCS: unprepared SQL ok.
122
-
123
- if ( $verbose ) {
124
- if ( false !== $result ) {
125
- printf( "<div id='relevanssi-warning' class='updated fade'>%s</div>", esc_html__( 'Logs clear!', 'relevanssi' ) );
126
- } else {
127
- printf( "<div id='relevanssi-warning' class='updated fade'>%s</div>", esc_html__( 'Clearing the logs failed.', 'relevanssi' ) );
128
- }
129
- }
130
-
131
- return $result;
132
- }
133
-
134
  /**
135
  * Updates Relevanssi options.
136
  *
@@ -475,6 +413,68 @@ function update_relevanssi_options() {
475
  // phpcs:enable
476
  }
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  /**
479
  * Adds a stopword to the list of stopwords.
480
  *
@@ -734,7 +734,7 @@ function relevanssi_query_log() {
734
  print( "<form method='post'>" );
735
  wp_nonce_field( 'relevanssi_reset_logs', '_relresnonce', true, true );
736
  // Translators: %1$s is the input field, %2$s is the submit button.
737
- printf( '<p>%s</p></form>', esc_html( sprintf( __( 'To reset the logs, type "reset" into the box here %1$s and click %2$s', 'relevanssi' ), ' <input type="text" name="relevanssi_reset_code" />', ' <input type="submit" name="relevanssi_reset" value="Reset" class="button" />' ) ) );
738
 
739
  }
740
 
@@ -1508,8 +1508,7 @@ if ( function_exists( 'relevanssi_form_hide_post_controls' ) ) {
1508
  }
1509
  if ( function_exists( 'relevanssi_form_taxonomy_weights' ) ) {
1510
  relevanssi_form_taxonomy_weights( $post_type_weights );
1511
- }
1512
- if ( function_exists( 'relevanssi_form_tag_weight' ) ) {
1513
  relevanssi_form_tag_weight( $post_type_weights );
1514
  }
1515
  if ( function_exists( 'relevanssi_form_recency_weight' ) ) {
@@ -2131,6 +2130,7 @@ if ( function_exists( 'relevanssi_form_hide_post_controls' ) ) {
2131
  <div id='relevanssi-progress' class='rpi-progress'><div class="rpi-indicator"></div></div>
2132
  <div id='relevanssi-timer'><?php esc_html_e( 'Time elapsed', 'relevanssi' ); ?>: <span id="relevanssi_elapsed">0:00:00</span> | <?php esc_html_e( 'Time remaining', 'relevanssi' ); ?>: <span id="relevanssi_estimated"><?php esc_html_e( 'some time', 'relevanssi' ); ?></span></div>
2133
  <textarea id='results' rows='10' cols='80'></textarea>
 
2134
  </td>
2135
  </tr>
2136
  <tr>
@@ -2404,7 +2404,7 @@ if ( function_exists( 'relevanssi_form_hide_post_controls' ) ) {
2404
  </td>
2405
  </tr>
2406
  <tr>
2407
- <th scope="row"><?php esc_html_e( 'Punctuation control' ); ?></th>
2408
  <td><p class="description"><?php esc_html_e( 'Here you can adjust how the punctuation is controlled. For more information, see help. Remember that any changes here require reindexing, otherwise searches will fail to find posts they should.', 'relevanssi' ); ?></p></td>
2409
  </tr>
2410
  <tr>
@@ -2493,7 +2493,7 @@ if ( function_exists( 'relevanssi_form_hide_post_controls' ) ) {
2493
 
2494
  <h2><?php esc_html_e( 'Indexing attachment content', 'relevanssi' ); ?></h2>
2495
 
2496
- <p><?php esc_html_e( 'With Relevanssi Premium, you can index the text contents of PDF attachments. The contents of the attachments are processed on an external service, which makes the feature reliable and light on your own server performance.', 'relevanssi' ); ?></p>
2497
  <?php // Translators: %1$s starts the link, %2$s closes it. ?>
2498
  <p><?php printf( esc_html__( 'In order to access this and many other delightful Premium features, %1$sbuy Relevanssi Premium here%2$s.', 'relevanssi' ), '<a href="https://www.relevanssi.com/buy-premium/">', '</a>' ); ?></p>
2499
 
@@ -2871,23 +2871,35 @@ function relevanssi_add_admin_scripts( $hook ) {
2871
  }
2872
 
2873
  /**
2874
- * Sanitizes hex color strings.
2875
- *
2876
- * A copy of sanitize_hex_color(), because that isn't always available.
2877
- *
2878
- * @param string $color A hex color string to sanitize.
2879
  *
2880
- * @return string Sanitized hex string, or an empty string.
2881
  */
2882
- function relevanssi_sanitize_hex_color( $color ) {
2883
- if ( '' === $color ) {
2884
- return '';
 
2885
  }
2886
-
2887
- // 3 or 6 hex digits, or the empty string.
2888
- if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
2889
- return $color;
2890
  }
2891
-
2892
- return '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2893
  }
69
  echo "<div style='clear:both'></div></div>";
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * Updates Relevanssi options.
74
  *
413
  // phpcs:enable
414
  }
415
 
416
+ /**
417
+ * Prints out the 'User searches' page.
418
+ */
419
+ function relevanssi_search_stats() {
420
+ $relevanssi_hide_branding = get_option( 'relevanssi_hide_branding' );
421
+
422
+ if ( 'on' === $relevanssi_hide_branding ) {
423
+ $options_txt = __( 'User searches', 'relevanssi' );
424
+ } else {
425
+ $options_txt = __( 'Relevanssi User Searches', 'relevanssi' );
426
+ }
427
+
428
+ if ( isset( $_REQUEST['relevanssi_reset'] ) && current_user_can( 'manage_options' ) ) {
429
+ check_admin_referer( 'relevanssi_reset_logs', '_relresnonce' );
430
+ if ( isset( $_REQUEST['relevanssi_reset_code'] ) ) {
431
+ if ( 'reset' === $_REQUEST['relevanssi_reset_code'] ) {
432
+ $verbose = true;
433
+ relevanssi_truncate_logs( $verbose );
434
+ }
435
+ }
436
+ }
437
+
438
+ wp_enqueue_style( 'dashboard' );
439
+ wp_print_styles( 'dashboard' );
440
+ wp_enqueue_script( 'dashboard' );
441
+ wp_print_scripts( 'dashboard' );
442
+
443
+ printf( "<div class='wrap'><h2>%s</h2>", esc_html( $options_txt ) );
444
+
445
+ if ( 'on' === get_option( 'relevanssi_log_queries' ) ) {
446
+ relevanssi_query_log();
447
+ } else {
448
+ printf( '<p>%s</p>', esc_html__( 'Enable query logging to see stats here.', 'relevanssi' ) );
449
+ }
450
+ }
451
+
452
+ /**
453
+ * Truncates the Relevanssi logs.
454
+ *
455
+ * @global object $wpdb The WP database interface.
456
+ * @global array $relevanssi_variables The global Relevanssi variables array.
457
+ *
458
+ * @param boolean $verbose If true, prints out a notice. Default true.
459
+ *
460
+ * @return boolean True if success, false if failure.
461
+ */
462
+ function relevanssi_truncate_logs( $verbose = true ) {
463
+ global $wpdb, $relevanssi_variables;
464
+
465
+ $result = $wpdb->query( 'TRUNCATE ' . $relevanssi_variables['log_table'] ); // WPCS: unprepared SQL ok.
466
+
467
+ if ( $verbose ) {
468
+ if ( false !== $result ) {
469
+ printf( "<div id='relevanssi-warning' class='updated fade'>%s</div>", esc_html__( 'Logs clear!', 'relevanssi' ) );
470
+ } else {
471
+ printf( "<div id='relevanssi-warning' class='updated fade'>%s</div>", esc_html__( 'Clearing the logs failed.', 'relevanssi' ) );
472
+ }
473
+ }
474
+
475
+ return $result;
476
+ }
477
+
478
  /**
479
  * Adds a stopword to the list of stopwords.
480
  *
734
  print( "<form method='post'>" );
735
  wp_nonce_field( 'relevanssi_reset_logs', '_relresnonce', true, true );
736
  // Translators: %1$s is the input field, %2$s is the submit button.
737
+ printf( '<p>%s</p></form>', sprintf( __( 'To reset the logs, type "reset" into the box here %1$s and click %2$s', 'relevanssi' ), ' <input type="text" name="relevanssi_reset_code" />', ' <input type="submit" name="relevanssi_reset" value="Reset" class="button" />' ) ); // WPCS: XSS ok.
738
 
739
  }
740
 
1508
  }
1509
  if ( function_exists( 'relevanssi_form_taxonomy_weights' ) ) {
1510
  relevanssi_form_taxonomy_weights( $post_type_weights );
1511
+ } elseif ( function_exists( 'relevanssi_form_tag_weight' ) ) {
 
1512
  relevanssi_form_tag_weight( $post_type_weights );
1513
  }
1514
  if ( function_exists( 'relevanssi_form_recency_weight' ) ) {
2130
  <div id='relevanssi-progress' class='rpi-progress'><div class="rpi-indicator"></div></div>
2131
  <div id='relevanssi-timer'><?php esc_html_e( 'Time elapsed', 'relevanssi' ); ?>: <span id="relevanssi_elapsed">0:00:00</span> | <?php esc_html_e( 'Time remaining', 'relevanssi' ); ?>: <span id="relevanssi_estimated"><?php esc_html_e( 'some time', 'relevanssi' ); ?></span></div>
2132
  <textarea id='results' rows='10' cols='80'></textarea>
2133
+ <div id='relevanssi-indexing-instructions' style='display: none'><?php esc_html_e( "Indexing should respond quickly. If nothing happens in couple of minutes, it's probably stuck. The most common reasons for indexing issues are incompatible shortcodes, so try disabling the shortcode expansion setting and try again. Also, if you've just updated Relevanssi, doing a hard refresh in your browser will make sure your browser is not trying to use an outdated version of the Relevanssi scripts.", 'relevanssi' ); ?></div>
2134
  </td>
2135
  </tr>
2136
  <tr>
2404
  </td>
2405
  </tr>
2406
  <tr>
2407
+ <th scope="row"><?php esc_html_e( 'Punctuation control', 'relevanssi' ); ?></th>
2408
  <td><p class="description"><?php esc_html_e( 'Here you can adjust how the punctuation is controlled. For more information, see help. Remember that any changes here require reindexing, otherwise searches will fail to find posts they should.', 'relevanssi' ); ?></p></td>
2409
  </tr>
2410
  <tr>
2493
 
2494
  <h2><?php esc_html_e( 'Indexing attachment content', 'relevanssi' ); ?></h2>
2495
 
2496
+ <p><?php esc_html_e( 'With Relevanssi Premium, you can index the text contents of attachments (PDFs, Word documents, Open Office documents and many other types). The contents of the attachments are processed on an external service, which makes the feature reliable and light on your own server performance.', 'relevanssi' ); ?></p>
2497
  <?php // Translators: %1$s starts the link, %2$s closes it. ?>
2498
  <p><?php printf( esc_html__( 'In order to access this and many other delightful Premium features, %1$sbuy Relevanssi Premium here%2$s.', 'relevanssi' ), '<a href="https://www.relevanssi.com/buy-premium/">', '</a>' ); ?></p>
2499
 
2871
  }
2872
 
2873
  /**
2874
+ * Prints out the form fields for tag and category weights.
 
 
 
 
2875
  *
2876
+ * @param array $taxonomy_weights The taxonomy weights.
2877
  */
2878
+ function relevanssi_form_tag_weight( $taxonomy_weights ) {
2879
+ $tag_value = 1;
2880
+ if ( isset( $taxonomy_weights['post_tag'] ) ) {
2881
+ $tag_value = $taxonomy_weights['post_tag'];
2882
  }
2883
+ $category_value = 1;
2884
+ if ( isset( $taxonomy_weights['category'] ) ) {
2885
+ $category_value = $taxonomy_weights['category'];
 
2886
  }
2887
+ ?>
2888
+ <tr>
2889
+ <td>
2890
+ <?php esc_html_e( 'Tag weight', 'relevanssi' ); ?>
2891
+ </td>
2892
+ <td class="col-2">
2893
+ <input type='text' id='relevanssi_weight_post_tag' name='relevanssi_weight_post_tag' size='4' value='<?php echo esc_attr( $tag_value ); ?>' />
2894
+ </td>
2895
+ </tr>
2896
+ <tr>
2897
+ <td>
2898
+ <?php esc_html_e( 'Category weight', 'relevanssi' ); ?>
2899
+ </td>
2900
+ <td class="col-2">
2901
+ <input type='text' id='relevanssi_weight_category' name='relevanssi_weight_category' size='4' value='<?php echo esc_attr( $category_value ); ?>' />
2902
+ </td>
2903
+ </tr>
2904
+ <?php
2905
  }
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.0.5
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi
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.0.6
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi