WP 404 Auto Redirect to Similar Post - Version 1.0.3

Version Description

  • Improvement: Enhanced search algorithm & matching
Download this release

Release Info

Developer hwk-fr
Plugin Icon 128x128 WP 404 Auto Redirect to Similar Post
Version 1.0.3
Comparing to
See all releases

Code changes from version 1.0.2 to 1.0.3

class/class-search.php CHANGED
@@ -41,17 +41,36 @@ class WP_404_Auto_Redirect_Search {
41
 
42
  $sql = "SELECT p.ID, ";
43
 
44
- if(is_array($args['keywords'])){
 
 
 
 
 
45
 
46
- foreach($args['keywords'] as $k){
 
 
47
  $sql .= "
48
- if(INSTR(LCASE(p.post_name), '" . $k . "'), 1, 0) + ";
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
 
51
- }else{
52
-
53
  $sql .= "
54
- if(INSTR(LCASE(p.post_name), '" . $args['keywords'] . "'), 1, 0) + ";
55
 
56
  }
57
 
@@ -127,17 +146,36 @@ class WP_404_Auto_Redirect_Search {
127
 
128
  $sql = "SELECT t.term_id, ";
129
 
130
- if(is_array($args['keywords'])){
 
 
 
 
 
131
 
132
- foreach($args['keywords'] as $k){
 
 
133
  $sql .= "
134
- if(INSTR(LCASE(t.slug), '" . $k . "'), 1, 0) + ";
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  }
136
 
137
- }else{
138
-
139
  $sql .= "
140
- if(INSTR(LCASE(t.slug), '" . $args['keywords'] . "'), 1, 0) + ";
141
 
142
  }
143
 
41
 
42
  $sql = "SELECT p.ID, ";
43
 
44
+ if(!is_array($args['keywords']))
45
+ $args['keywords'] = array($args['keywords']);
46
+
47
+ foreach($args['keywords'] as $k){
48
+
49
+ $strlen = strlen($k);
50
 
51
+ if($strlen > 1){
52
+
53
+ // Left
54
  $sql .= "
55
+ IF(LEFT(LCASE(p.post_name), " . ($strlen + 1) . ") = '" . $k . "-', 2, 0) + ";
56
+
57
+ // Right
58
+ $sql .= "
59
+ IF(RIGHT(LCASE(p.post_name), " . ($strlen + 1) . ") = '-" . $k . "', 2, 0) + ";
60
+
61
+ // Inside
62
+ $sql .= "
63
+ if(INSTR(LCASE(p.post_name), '-" . $k . "-'), 2, 0) + ";
64
+
65
+ // Direct
66
+ $sql .= "
67
+ if(LCASE(p.post_name) = '" . $k . "', 2, 0) + ";
68
+
69
  }
70
 
71
+ // Wildcard
 
72
  $sql .= "
73
+ if(INSTR(LCASE(p.post_name), '" . $k . "'), 1, 0) + ";
74
 
75
  }
76
 
146
 
147
  $sql = "SELECT t.term_id, ";
148
 
149
+ if(!is_array($args['keywords']))
150
+ $args['keywords'] = array($args['keywords']);
151
+
152
+ foreach($args['keywords'] as $k){
153
+
154
+ $strlen = strlen($k);
155
 
156
+ if($strlen > 1){
157
+
158
+ // Left
159
  $sql .= "
160
+ IF(LEFT(LCASE(t.slug), " . ($strlen + 1) . ") = '" . $k . "-', 2, 0) + ";
161
+
162
+ // Right
163
+ $sql .= "
164
+ IF(RIGHT(LCASE(t.slug), " . ($strlen + 1) . ") = '-" . $k . "', 2, 0) + ";
165
+
166
+ // Inside
167
+ $sql .= "
168
+ if(INSTR(LCASE(t.slug), '-" . $k . "-'), 2, 0) + ";
169
+
170
+ // Direct
171
+ $sql .= "
172
+ if(LCASE(t.slug) = '" . $k . "', 2, 0) + ";
173
+
174
  }
175
 
176
+ // Wildcard
 
177
  $sql .= "
178
+ if(INSTR(LCASE(t.slug), '" . $k . "'), 1, 0) + ";
179
 
180
  }
181
 
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: hwk-fr
3
  Donate link: https://hwk.fr/
4
  Tags: SEO, 404, Redirect, 301, Similar, Related, Search, Broken Link, Webmaster Tools, Google
5
  Requires at least: 4.0
6
- Tested up to: 4.9.8
7
- Requires PHP: 5.4
8
- Stable tag: 1.0.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -376,6 +376,9 @@ function my_404_after_redirect($query){
376
 
377
  == Changelog ==
378
 
 
 
 
379
  = 1.0.2 =
380
  * Fix: Request sanitization compatibility for nginx servers
381
 
3
  Donate link: https://hwk.fr/
4
  Tags: SEO, 404, Redirect, 301, Similar, Related, Search, Broken Link, Webmaster Tools, Google
5
  Requires at least: 4.0
6
+ Tested up to: 5.4
7
+ Requires PHP: 5.6
8
+ Stable tag: 1.0.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
376
 
377
  == Changelog ==
378
 
379
+ = 1.0.3 =
380
+ * Improvement: Enhanced search algorithm & matching
381
+
382
  = 1.0.2 =
383
  * Fix: Request sanitization compatibility for nginx servers
384
 
wp-404-auto-redirect-similar-post.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: WP 404 Auto Redirect to Similar Post
4
  * Description: Automatically Redirect any 404 page to a Similar Post based on the Title, Post Type & Taxonomy using 301 Redirects!
5
- * Version: 1.0.2
6
  * Author: hwk-fr
7
  * Author URI: https://hwk.fr
8
  * Text Domain: wp-404-auto-redirect
2
  /**
3
  * Plugin Name: WP 404 Auto Redirect to Similar Post
4
  * Description: Automatically Redirect any 404 page to a Similar Post based on the Title, Post Type & Taxonomy using 301 Redirects!
5
+ * Version: 1.0.3
6
  * Author: hwk-fr
7
  * Author URI: https://hwk.fr
8
  * Text Domain: wp-404-auto-redirect