Relevanssi – A Better Search - Version 4.18.2

Version Description

  • New feature: Relevanssi now has a debug mode that will help troubleshooting and support.
  • Minor fix: Using the_permalink() caused problems with search result links. That is now fixed. Relevanssi no longer hooks onto the_permalink hook and instead uses post_link and other similar hooks.
Download this release

Release Info

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

Code changes from version 4.18.1 to 4.18.2

lib/common.php CHANGED
@@ -1043,6 +1043,12 @@ function relevanssi_permalink( $link, $link_post = null ) {
1043
  } elseif ( is_int( $link_post ) ) {
1044
  $link_post = relevanssi_get_post( $link_post );
1045
  }
 
 
 
 
 
 
1046
  // Using property_exists() to avoid troubles from magic variables.
1047
  if ( is_object( $link_post ) && property_exists( $link_post, 'relevanssi_link' ) ) {
1048
  // $link_post->relevanssi_link can still be false.
1043
  } elseif ( is_int( $link_post ) ) {
1044
  $link_post = relevanssi_get_post( $link_post );
1045
  }
1046
+ if ( is_object( $link_post ) && ! property_exists( $link_post, 'relevance_score' ) ) {
1047
+ // get_permalink( $post_id ) uses get_post() which eliminates Relevanssi
1048
+ // data from the post, thus we use relevanssi_get_post() to get it.
1049
+ $link_post = relevanssi_get_post( $link_post->ID );
1050
+ }
1051
+
1052
  // Using property_exists() to avoid troubles from magic variables.
1053
  if ( is_object( $link_post ) && property_exists( $link_post, 'relevanssi_link' ) ) {
1054
  // $link_post->relevanssi_link can still be false.
lib/debug.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * /lib/debug.php
4
+ *
5
+ * @package Relevanssi
6
+ * @author Mikko Saari
7
+ * @license https://wordpress.org/about/gpl/ GNU General Public License
8
+ * @see https://www.relevanssi.com/
9
+ */
10
+
11
+ /**
12
+ * Checks if Relevanssi debug mode is enabled.
13
+ *
14
+ * Debug mode is enabled by setting RELEVANSSI_DEBUG to true or with the
15
+ * 'relevanssi_debug' query parameter if the debug mode is allowed from the
16
+ * settings.
17
+ *
18
+ * @return boolean True if debug mode is enabled, false if not.
19
+ */
20
+ function relevanssi_is_debug() : bool {
21
+ $debug = false;
22
+ if ( defined( 'RELEVANSSI_DEBUG' ) && RELEVANSSI_DEBUG ) {
23
+ $debug = true;
24
+ }
25
+ if ( isset( $_REQUEST['relevanssi_debug'] ) && 'on' === get_option( 'relevanssi_debugging_mode' ) ) {
26
+ $debug = true;
27
+ }
28
+ return $debug;
29
+ }
30
+
31
+ function relevanssi_debug_posts( $posts ) {
32
+ echo '<h2>Posts</h2>';
33
+ foreach ( $posts as $post ) {
34
+ if ( ! is_object( $post ) ) {
35
+ echo "$post\n";
36
+ } else {
37
+ echo "<p>$post->ID: $post->post_title<br />";
38
+ echo "$post->post_type – $post->post_status – $post->relevance_score<br />";
39
+ echo "relevanssi_link: $post->relevanssi_link<br />";
40
+ echo 'the_permalink(): ';
41
+ the_permalink( $post->ID );
42
+ echo '<br />get_permalink(): ' . get_permalink( $post );
43
+ echo "</p>";
44
+ }
45
+ }
46
+ }
47
+
48
+ function relevanssi_debug_array( $array, $title ) {
49
+ echo '<h2>' . $title . '</h2>';
50
+ echo '<pre>';
51
+ print_r( $array );
52
+ echo '</pre>';
53
+ }
54
+
55
+ function relevanssi_debug_string( $string, $title ) {
56
+ echo '<h2>' . $title . '</h2>';
57
+ echo '<pre>' . $string . '</pre>';
58
+ }
59
+
60
+ add_action( 'wp', 'relevanssi_debug_post' );
61
+ function relevanssi_debug_post() {
62
+ if ( ! is_singular() || ! relevanssi_is_debug() ) {
63
+ return;
64
+ }
65
+ global $post;
66
+ echo '<h1>' . $post->post_title . ' (' . $post->ID . ')</h1>';
67
+
68
+ echo '<h2>Index</h2>';
69
+ echo relevanssi_generate_how_relevanssi_sees( $post->ID, true, 'post' );
70
+
71
+ echo '<h2>Database</h2>';
72
+ echo '<pre>' . relevanssi_generate_db_post_view( $post->ID ) . '</pre>';
73
+
74
+ relevanssi_debug_array( get_post_meta( $post->ID ), 'Post meta' );
75
+
76
+ exit();
77
+ }
78
+
79
+ /**
80
+ * Generates the debugging view for a post.
81
+ *
82
+ * @param int $post_id ID of the post.
83
+ *
84
+ * @return string The debugging view in a div container.
85
+ */
86
+ function relevanssi_generate_db_post_view( int $post_id ) {
87
+ global $wpdb;
88
+
89
+ $element = '<div id="relevanssi_db_view_container">';
90
+
91
+ $post_object = get_post( $post_id );
92
+
93
+ if ( ! $post_object ) {
94
+ $element .= '<p>' . esc_html__( 'Post not found', 'relevanssi' ) . '</p>';
95
+ $element .= '</div>';
96
+ return $element;
97
+ }
98
+
99
+ $element .= '<p>' . esc_html( $post_object->post_content ) . '</p>';
100
+
101
+ $element .= '</div>';
102
+ return $element;
103
+ }
lib/init.php CHANGED
@@ -69,8 +69,9 @@ add_filter( 'relevanssi_pre_excerpt_content', 'relevanssi_remove_page_builder_sh
69
  add_filter( 'relevanssi_post_content', 'relevanssi_remove_page_builder_shortcodes', 9 );
70
 
71
  // Permalink handling.
72
- add_filter( 'the_permalink', 'relevanssi_permalink', 10, 2 );
73
  add_filter( 'post_link', 'relevanssi_permalink', 10, 2 );
 
 
74
  add_filter( 'page_link', 'relevanssi_permalink', 10, 2 );
75
  add_filter( 'relevanssi_permalink', 'relevanssi_permalink' );
76
 
69
  add_filter( 'relevanssi_post_content', 'relevanssi_remove_page_builder_shortcodes', 9 );
70
 
71
  // Permalink handling.
 
72
  add_filter( 'post_link', 'relevanssi_permalink', 10, 2 );
73
+ add_filter( 'post_type_link', 'relevanssi_permalink', 10, 2 );
74
+ add_filter( 'attachment_link', 'relevanssi_permalink', 10, 2 );
75
  add_filter( 'page_link', 'relevanssi_permalink', 10, 2 );
76
  add_filter( 'relevanssi_permalink', 'relevanssi_permalink' );
77
 
lib/install.php CHANGED
@@ -78,6 +78,7 @@ function _relevanssi_install() {
78
  add_option( 'relevanssi_content_boost', $relevanssi_variables['content_boost_default'] );
79
  add_option( 'relevanssi_css', 'text-decoration: underline; color: #ff0000' );
80
  add_option( 'relevanssi_db_version', '0' );
 
81
  add_option( 'relevanssi_default_orderby', 'relevance' );
82
  add_option( 'relevanssi_disable_or_fallback', 'off' );
83
  add_option( 'relevanssi_exact_match_bonus', 'on' );
78
  add_option( 'relevanssi_content_boost', $relevanssi_variables['content_boost_default'] );
79
  add_option( 'relevanssi_css', 'text-decoration: underline; color: #ff0000' );
80
  add_option( 'relevanssi_db_version', '0' );
81
+ add_option( 'relevanssi_debugging_mode', 'off' );
82
  add_option( 'relevanssi_default_orderby', 'relevance' );
83
  add_option( 'relevanssi_disable_or_fallback', 'off' );
84
  add_option( 'relevanssi_exact_match_bonus', 'on' );
lib/interface.php CHANGED
@@ -240,7 +240,7 @@ function relevanssi_options_form() {
240
  'name' => __( 'Debugging', 'relevanssi' ),
241
  'require' => 'tabs/debugging-tab.php',
242
  'callback' => 'relevanssi_debugging_tab',
243
- 'save' => false,
244
  ),
245
  );
246
 
240
  'name' => __( 'Debugging', 'relevanssi' ),
241
  'require' => 'tabs/debugging-tab.php',
242
  'callback' => 'relevanssi_debugging_tab',
243
+ 'save' => true,
244
  ),
245
  );
246
 
lib/options.php CHANGED
@@ -89,6 +89,10 @@ function update_relevanssi_options( array $request ) {
89
  }
90
  }
91
 
 
 
 
 
92
  relevanssi_process_weights_and_indexing( $request );
93
  relevanssi_process_synonym_options( $request );
94
  relevanssi_process_punctuation_options( $request );
@@ -103,6 +107,7 @@ function update_relevanssi_options( array $request ) {
103
  'relevanssi_bg_col' => true,
104
  'relevanssi_class' => true,
105
  'relevanssi_css' => true,
 
106
  'relevanssi_default_orderby' => true,
107
  'relevanssi_disable_or_fallback' => true,
108
  'relevanssi_exact_match_bonus' => true,
89
  }
90
  }
91
 
92
+ if ( 'debugging' === $request['tab'] ) {
93
+ relevanssi_turn_off_options( $request, array( 'relevanssi_debugging_mode' ) );
94
+ }
95
+
96
  relevanssi_process_weights_and_indexing( $request );
97
  relevanssi_process_synonym_options( $request );
98
  relevanssi_process_punctuation_options( $request );
107
  'relevanssi_bg_col' => true,
108
  'relevanssi_class' => true,
109
  'relevanssi_css' => true,
110
+ 'relevanssi_debugging_mode' => true,
111
  'relevanssi_default_orderby' => true,
112
  'relevanssi_disable_or_fallback' => true,
113
  'relevanssi_exact_match_bonus' => true,
lib/search.php CHANGED
@@ -82,6 +82,12 @@ function relevanssi_query( $posts, $query = false ) {
82
  */
83
  $query = apply_filters( 'relevanssi_modify_wp_query', $query );
84
  $posts = relevanssi_do_query( $query );
 
 
 
 
 
 
85
  }
86
 
87
  return $posts;
@@ -118,6 +124,8 @@ function relevanssi_search( $args ) {
118
  $order = $filtered_args['order'];
119
  $fields = $filtered_args['fields'];
120
 
 
 
121
  $hits = array();
122
 
123
  $query_data = relevanssi_process_query_args( $filtered_args );
@@ -127,6 +135,8 @@ function relevanssi_search( $args ) {
127
  $q_no_synonyms = $query_data['query_no_synonyms'];
128
  $phrase_queries = $query_data['phrase_queries'];
129
 
 
 
130
  $min_length = get_option( 'relevanssi_min_word_length' );
131
 
132
  /**
@@ -161,6 +171,8 @@ function relevanssi_search( $args ) {
161
  $terms['terms'] = array( 'term' );
162
  }
163
 
 
 
164
  /**
165
  * Filters the query restrictions for the Relevanssi query.
166
  *
@@ -229,6 +241,8 @@ function relevanssi_search( $args ) {
229
  $query = relevanssi_generate_search_query( $term, $search_again, $no_terms, $query_join, $this_query_restrictions );
230
  $matches = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared
231
 
 
 
232
  if ( count( $matches ) < 1 ) {
233
  continue;
234
  }
@@ -668,7 +682,11 @@ function relevanssi_do_query( &$query ) {
668
  *
669
  * @return array An array of post objects.
670
  */
671
- foreach ( apply_filters( 'relevanssi_hits_to_show', $hits_to_show, $query ) as $post ) {
 
 
 
 
672
  if ( $highlight_title && $return_posts ) {
673
  relevanssi_highlight_post_title( $post, $q );
674
  }
82
  */
83
  $query = apply_filters( 'relevanssi_modify_wp_query', $query );
84
  $posts = relevanssi_do_query( $query );
85
+
86
+ if ( relevanssi_is_debug() ) {
87
+ relevanssi_debug_posts( $posts );
88
+ exit();
89
+ }
90
+
91
  }
92
 
93
  return $posts;
124
  $order = $filtered_args['order'];
125
  $fields = $filtered_args['fields'];
126
 
127
+ relevanssi_is_debug() && relevanssi_debug_array( $filtered_args, 'Filtered args' );
128
+
129
  $hits = array();
130
 
131
  $query_data = relevanssi_process_query_args( $filtered_args );
135
  $q_no_synonyms = $query_data['query_no_synonyms'];
136
  $phrase_queries = $query_data['phrase_queries'];
137
 
138
+ relevanssi_is_debug() && relevanssi_debug_array( $query_data, 'Processed query args' );
139
+
140
  $min_length = get_option( 'relevanssi_min_word_length' );
141
 
142
  /**
171
  $terms['terms'] = array( 'term' );
172
  }
173
 
174
+ relevanssi_is_debug() && relevanssi_debug_array( $terms, 'Terms' );
175
+
176
  /**
177
  * Filters the query restrictions for the Relevanssi query.
178
  *
241
  $query = relevanssi_generate_search_query( $term, $search_again, $no_terms, $query_join, $this_query_restrictions );
242
  $matches = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared
243
 
244
+ relevanssi_is_debug() && relevanssi_debug_string( $query, 'Query' );
245
+
246
  if ( count( $matches ) < 1 ) {
247
  continue;
248
  }
682
  *
683
  * @return array An array of post objects.
684
  */
685
+ $hits_to_show = apply_filters( 'relevanssi_hits_to_show', $hits_to_show, $query );
686
+ if ( ! is_array( $hits_to_show ) ) {
687
+ $hits_to_show = array();
688
+ }
689
+ foreach ( $hits_to_show as $post ) {
690
  if ( $highlight_title && $return_posts ) {
691
  relevanssi_highlight_post_title( $post, $q );
692
  }
lib/tabs/debugging-tab.php CHANGED
@@ -147,31 +147,20 @@ function relevanssi_debugging_tab() {
147
 
148
  <?php do_action( 'relevanssi_debugging_tab' ); ?>
149
 
150
- <?php
151
- }
152
-
153
- /**
154
- * Generates the debugging view for a post.
155
- *
156
- * @param int $post_id ID of the post.
157
- *
158
- * @return string The debugging view in a div container.
159
- */
160
- function relevanssi_generate_db_post_view( int $post_id ) {
161
- global $wpdb;
162
-
163
- $element = '<div id="relevanssi_db_view_container">';
164
 
165
- $post_object = get_post( $post_id );
166
-
167
- if ( ! $post_object ) {
168
- $element .= '<p>' . esc_html__( 'Post not found', 'relevanssi' ) . '</p>';
169
- $element .= '</div>';
170
- return $element;
171
- }
172
 
173
- $element .= '<p>' . esc_html( $post_object->post_content ) . '</p>';
 
 
 
 
 
 
 
174
 
175
- $element .= '</div>';
176
- return $element;
177
  }
147
 
148
  <?php do_action( 'relevanssi_debugging_tab' ); ?>
149
 
150
+ <h2><?php esc_html_e( 'Debugging mode', 'relevanssi' ); ?></h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
+ <?php
153
+ $enable_debugging_mode = relevanssi_check( get_option( 'relevanssi_debugging_mode' ) );
154
+ ?>
 
 
 
 
155
 
156
+ <fieldset>
157
+ <legend class="screen-reader-text"><?php esc_html_e( 'Enable the debugging mode.', 'relevanssi' ); ?></legend>
158
+ <label for='relevanssi_debugging_mode'>
159
+ <input type='checkbox' name='relevanssi_debugging_mode' id='relevanssi_debugging_mode' <?php echo esc_html( $enable_debugging_mode ); ?> />
160
+ <?php esc_html_e( 'Enable the debugging mode.', 'relevanssi' ); ?>
161
+ </label>
162
+ <p class="description"><?php esc_html_e( "Relevanssi support may ask you to enable the debugging mode. When you check this box, it's possible to see debugging information from the front-end.", 'relevanssi' ); ?></p>
163
+ </fieldset>
164
 
165
+ <?php
 
166
  }
lib/uninstall.php CHANGED
@@ -68,6 +68,7 @@ function relevanssi_uninstall_free() {
68
  delete_option( 'relevanssi_content_boost' );
69
  delete_option( 'relevanssi_css' );
70
  delete_option( 'relevanssi_db_version' );
 
71
  delete_option( 'relevanssi_default_orderby' );
72
  delete_option( 'relevanssi_disable_or_fallback' );
73
  delete_option( 'relevanssi_disable_shortcodes' );
68
  delete_option( 'relevanssi_content_boost' );
69
  delete_option( 'relevanssi_css' );
70
  delete_option( 'relevanssi_db_version' );
71
+ delete_option( 'relevanssi_debugging_mode' );
72
  delete_option( 'relevanssi_default_orderby' );
73
  delete_option( 'relevanssi_disable_or_fallback' );
74
  delete_option( 'relevanssi_disable_shortcodes' );
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: 6.1
7
  Requires PHP: 7.0
8
- Stable tag: 4.18.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -128,6 +128,10 @@ Each document database is full of useless words. All the little words that appea
128
  * John Calahan for extensive 4.0 beta testing.
129
 
130
  == Changelog ==
 
 
 
 
131
  = 4.18.1 =
132
  * New feature: New filter hook `relevanssi_add_highlight_and_tracking` can be used to force Relevanssi to add the `highlight` and tracking parameters to permalinks.
133
  * Changed behaviour: The 'relevanssi_wpml_filter' filter function now runs on priority 9 instead of 10 to avoid problems with custom filters on relevanssi_hits_filter.
@@ -180,6 +184,9 @@ Each document database is full of useless words. All the little words that appea
180
  * Minor fix: Prevents fatal errors from `relevanssi_strip_all_tags()`.
181
 
182
  == Upgrade notice ==
 
 
 
183
  = 4.18.1 =
184
  * Small bug fixes.
185
 
5
  Requires at least: 4.9
6
  Tested up to: 6.1
7
  Requires PHP: 7.0
8
+ Stable tag: 4.18.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
128
  * John Calahan for extensive 4.0 beta testing.
129
 
130
  == Changelog ==
131
+ = 4.18.2 =
132
+ * New feature: Relevanssi now has a debug mode that will help troubleshooting and support.
133
+ * Minor fix: Using the_permalink() caused problems with search result links. That is now fixed. Relevanssi no longer hooks onto `the_permalink` hook and instead uses `post_link` and other similar hooks.
134
+
135
  = 4.18.1 =
136
  * New feature: New filter hook `relevanssi_add_highlight_and_tracking` can be used to force Relevanssi to add the `highlight` and tracking parameters to permalinks.
137
  * Changed behaviour: The 'relevanssi_wpml_filter' filter function now runs on priority 9 instead of 10 to avoid problems with custom filters on relevanssi_hits_filter.
184
  * Minor fix: Prevents fatal errors from `relevanssi_strip_all_tags()`.
185
 
186
  == Upgrade notice ==
187
+ = 4.18.2 =
188
+ * Fixes problems with broken permalinks.
189
+
190
  = 4.18.1 =
191
  * Small bug fixes.
192
 
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.18.1
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi
@@ -67,10 +67,11 @@ $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.18.1';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';
 
74
  require_once 'lib/didyoumean.php';
75
  require_once 'lib/excerpts-highlights.php';
76
  require_once 'lib/indexing.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.18.2
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.18.2';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';
74
+ require_once 'lib/debug.php';
75
  require_once 'lib/didyoumean.php';
76
  require_once 'lib/excerpts-highlights.php';
77
  require_once 'lib/indexing.php';