WP 404 Auto Redirect to Similar Post - Version 0.7.7

Version Description

  • Fixed PHP header() error on upgrade
  • Fixed Exclude Post Type from Redirections UI & Logic
  • Added 999 priority on template_redirect action for compatibility
  • Fixed 'Compatibility' typo in description
  • Updated Plugin Screenshot
Download this release

Release Info

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

Code changes from version 0.7.6 to 0.7.7

assets/admin.css CHANGED
@@ -7,7 +7,40 @@
7
  }
8
 
9
  #wp404arsp_settings #wp404arsp_settings_rules_redirection_exclude_post_types{
10
- width:300px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }
12
 
13
  #wp404arsp_settings #wp404arsp_settings_redirection_preview .request{
7
  }
8
 
9
  #wp404arsp_settings #wp404arsp_settings_rules_redirection_exclude_post_types{
10
+ display:block;
11
+ border:1px solid #ddd;
12
+ max-width:300px;
13
+ max-height:148px;
14
+ overflow:auto;
15
+ }
16
+
17
+ #wp404arsp_settings #wp404arsp_settings_rules_redirection_exclude_post_types input{
18
+ display: none;
19
+ opacity: 0;
20
+ visibility: hidden;
21
+ }
22
+
23
+ #wp404arsp_settings #wp404arsp_settings_rules_redirection_exclude_post_types label{
24
+ display:block;
25
+ padding:5px;
26
+ margin:0 !important;
27
+ position:relative;
28
+ }
29
+
30
+ #wp404arsp_settings #wp404arsp_settings_rules_redirection_exclude_post_types label:hover{
31
+ background:#f1f1f1;
32
+ }
33
+
34
+ #wp404arsp_settings #wp404arsp_settings_rules_redirection_exclude_post_types input:checked + label{
35
+ background:#0073aa;
36
+ color:#c6d6dd;
37
+ }
38
+
39
+ #wp404arsp_settings #wp404arsp_settings_rules_redirection_exclude_post_types input:checked + label:after{
40
+ position: absolute;
41
+ content: "Excluded";
42
+ right: 5px;
43
+ font-size: 10px;
44
  }
45
 
46
  #wp404arsp_settings #wp404arsp_settings_redirection_preview .request{
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://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.1
7
- Stable tag: 0.7.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -32,7 +32,7 @@ This plugin automatically redirect all your 404 requests to similar posts based
32
  * No useless data saved in Database.
33
  * Blazing Fast Performance.
34
 
35
- = Comptibility: =
36
 
37
  If you missed a manual redirection and a 404 is about to be displayed, the plugin will take action. Yes, WP 404 Auto Redirect to Similar Post is 100% compatible with all popular redirection plugins:
38
 
@@ -65,6 +65,13 @@ They talk about it! :)
65
 
66
  == Changelog ==
67
 
 
 
 
 
 
 
 
68
  = 0.7.6 =
69
  * Added "Custom Redirect URL" as Fallback Behavior (Feature Request)
70
  * Added "Exclude Post Type" Multi-select to possible redirections (Feature Request)
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.1
7
+ Stable tag: 0.7.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
32
  * No useless data saved in Database.
33
  * Blazing Fast Performance.
34
 
35
+ = Compatibility: =
36
 
37
  If you missed a manual redirection and a 404 is about to be displayed, the plugin will take action. Yes, WP 404 Auto Redirect to Similar Post is 100% compatible with all popular redirection plugins:
38
 
65
 
66
  == Changelog ==
67
 
68
+ = 0.7.7 =
69
+ * Fixed PHP header() error on upgrade
70
+ * Fixed Exclude Post Type from Redirections UI & Logic
71
+ * Added 999 priority on template_redirect action for compatibility
72
+ * Fixed 'Compatibility' typo in description
73
+ * Updated Plugin Screenshot
74
+
75
  = 0.7.6 =
76
  * Added "Custom Redirect URL" as Fallback Behavior (Feature Request)
77
  * Added "Exclude Post Type" Multi-select to possible redirections (Feature Request)
wp-404-auto-redirect-similar-post.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WP 404 Auto Redirect to Similar Post
4
  * Description: Automatically Redirect any 404 to a Similar Post based on the Title, Post Type, Category & Taxonomy using 301 Redirects!
5
  * Author: hwk-fr
6
- * Version: 0.7.6
7
  * Author URI: http://hwk.fr
8
  */
9
 
@@ -132,23 +132,20 @@ function wp404arsp_admin_page_html(){
132
  <td>
133
  <fieldset>
134
  <legend class="screen-reader-text"><span>Exclude one or multiple post types from possible redirections.</span></legend>
135
- <label for="wp404arsp_settings_rules_redirection_exclude_post_types">
136
- <select multiple="multiple" name="wp404arsp_settings[rules][redirection][exclude][post_types][]" id="wp404arsp_settings_rules_redirection_exclude_post_types">
137
- <?php foreach(get_post_types(array('public' => true), 'objects') as $post_type) { ?>
138
- <?php
139
- $selected = '';
140
- if(
141
- isset($settings['rules']['redirection']['exclude']['post_types']) &&
142
- is_array($settings['rules']['redirection']['exclude']['post_types']) &&
143
- in_array($post_type->name, $settings['rules']['redirection']['exclude']['post_types'])
144
- )
145
- $selected = 'selected="selected"'; ?>
146
- <option value="<?php echo $post_type->name; ?>" <?php echo $selected; ?>>
147
- <?php echo $post_type->label; ?>
148
- </option>
149
- <?php } ?>
150
- </select>
151
- </label>
152
  </fieldset>
153
  <p class="description">Exclude one or multiple post types from possible redirections.</p>
154
  </td>
@@ -224,7 +221,7 @@ function wp404arsp_admin_page_html(){
224
  </div>
225
  <?php }
226
 
227
- add_action('template_redirect', 'wp404arsp_init');
228
  function wp404arsp_init(){
229
  if(
230
  !is_404() ||
@@ -386,7 +383,6 @@ function wp404arsp_search($query){
386
  }
387
 
388
  function wp404arsp_redirect($args){
389
-
390
  $settings = wp404arsp_get_settings();
391
  $method = $settings['method'];
392
  $fallback = $settings['fallback']['type'] != 'disabled' ? $settings['fallback']['url'] : false;
@@ -451,7 +447,6 @@ Details: <?php echo $args['why']; ?></pre>
451
  }
452
 
453
  function wp404arsp_search_sql($args = array()){
454
-
455
  global $wpdb;
456
  $settings = wp404arsp_get_settings();
457
  $args = wp_parse_args($args, array(
@@ -526,7 +521,8 @@ function wp404arsp_sanitize($input){
526
  }
527
 
528
  function wp404arsp_get_settings(){
529
- return wp_parse_args(get_option('wp404arsp_settings'),
 
530
  array(
531
  'debug' => null,
532
  'logs' => null,
@@ -545,26 +541,29 @@ function wp404arsp_get_settings(){
545
  'method' => 301
546
  )
547
  );
 
 
 
 
 
 
 
 
 
548
  }
549
 
550
- function wp404arsp_remove_stop_words($input){
551
-
552
- $words = array('a', 'about', 'above', 'after', 'again', 'against', 'all', 'am', 'an', 'and', 'any', 'are', 'arent', 'as', 'at', 'be', 'because', 'been', 'before', 'being', 'below', 'between', 'both', 'but', 'by', 'cant', 'cannot', 'could', 'couldnt', 'did', 'didnt', 'do', 'does', 'doesnt', 'doing', 'dont', 'down', 'during', 'each', 'few', 'for', 'from', 'further', 'had', 'hadnt', 'has', 'hasnt', 'have', 'havent', 'having', 'he', 'hed', 'hell', 'hes', 'her', 'here', 'heres', 'hers', 'herself', 'him', 'himself', 'his', 'how', 'hows', 'i', 'id', 'ill', 'im', 'ive', 'if', 'in', 'into', 'is', 'isnt', 'it', 'its', 'itself', 'lets', 'me', 'more', 'most', 'mustnt', 'my', 'myself', 'no', 'nor', 'not', 'of', 'off', 'on', 'once', 'only', 'or', 'other', 'ought', 'our', 'ours', 'ourselves', 'out', 'over', 'own', 'same', 'shant', 'she', 'shed', 'shell', 'shes', 'should', 'shouldnt', 'so', 'some', 'such', 'than', 'that', 'thats', 'the', 'their', 'theirs', 'them', 'themselves', 'then', 'there', 'theres', 'these', 'they', 'theyd', 'theyll', 'theyre', 'theyve', 'this', 'those', 'to', 'too', 'under', 'until', 'up', 'very', 'was', 'wasnt', 'we', 'wed', 'well', 'were', 'weve', 'werent', 'what', 'whats', 'when', 'whens', 'where', 'wheres', 'which', 'while', 'who', 'whos', 'whom', 'why', 'whys', 'with', 'wont', 'would', 'wouldnt', 'you', 'youd', 'youll', 'youre', 'youve', 'your', 'yours', 'category', 'page', 'paged');
553
-
554
- if(is_array($input)){
555
- $return = array_diff($input, $words);
556
-
557
- foreach($return as $key => $val){
558
- if(is_numeric($val))
559
- unset($return[$key]);
560
- }
561
-
562
- return array_values($return);
563
-
564
- }else{
565
- return preg_replace('/\b('.implode('|', $words).')\b/', '', $input);
566
-
567
- }
568
  }
569
 
570
  function wp404arsp_get_post_types($type = 'names'){
@@ -585,8 +584,27 @@ function wp404arsp_get_post_types($type = 'names'){
585
  if(in_array($search, $settings['rules']['redirection']['exclude']['post_types']))
586
  continue;
587
 
588
- $filtered_post_types[] = $post_type;
589
  }
590
 
591
  return $filtered_post_types;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  }
3
  * Plugin Name: WP 404 Auto Redirect to Similar Post
4
  * Description: Automatically Redirect any 404 to a Similar Post based on the Title, Post Type, Category & Taxonomy using 301 Redirects!
5
  * Author: hwk-fr
6
+ * Version: 0.7.7
7
  * Author URI: http://hwk.fr
8
  */
9
 
132
  <td>
133
  <fieldset>
134
  <legend class="screen-reader-text"><span>Exclude one or multiple post types from possible redirections.</span></legend>
135
+ <div id="wp404arsp_settings_rules_redirection_exclude_post_types">
136
+ <?php foreach(get_post_types(array('public' => true), 'objects') as $post_type) { ?>
137
+ <?php
138
+ $checked = '';
139
+ if(
140
+ isset($settings['rules']['redirection']['exclude']['post_types']) &&
141
+ is_array($settings['rules']['redirection']['exclude']['post_types']) &&
142
+ in_array($post_type->name, $settings['rules']['redirection']['exclude']['post_types'])
143
+ )
144
+ $checked = 'checked="checked"'; ?>
145
+ <div><input type="checkbox" name="wp404arsp_settings[rules][redirection][exclude][post_types][]" id="wp404arsp_settings_rules_redirection_exclude_post_types_<?php echo $post_type->name; ?>" value="<?php echo $post_type->name; ?>" <?php echo $checked; ?> />
146
+ <label for="wp404arsp_settings_rules_redirection_exclude_post_types_<?php echo $post_type->name; ?>"><?php echo $post_type->label; ?></label></div>
147
+ <?php } ?>
148
+ </div>
 
 
 
149
  </fieldset>
150
  <p class="description">Exclude one or multiple post types from possible redirections.</p>
151
  </td>
221
  </div>
222
  <?php }
223
 
224
+ add_action('template_redirect', 'wp404arsp_init', 999);
225
  function wp404arsp_init(){
226
  if(
227
  !is_404() ||
383
  }
384
 
385
  function wp404arsp_redirect($args){
 
386
  $settings = wp404arsp_get_settings();
387
  $method = $settings['method'];
388
  $fallback = $settings['fallback']['type'] != 'disabled' ? $settings['fallback']['url'] : false;
447
  }
448
 
449
  function wp404arsp_search_sql($args = array()){
 
450
  global $wpdb;
451
  $settings = wp404arsp_get_settings();
452
  $args = wp_parse_args($args, array(
521
  }
522
 
523
  function wp404arsp_get_settings(){
524
+ $option = get_option('wp404arsp_settings');
525
+ $return = wp404arsp_wp_parse_args_recursive($option,
526
  array(
527
  'debug' => null,
528
  'logs' => null,
541
  'method' => 301
542
  )
543
  );
544
+
545
+ if($return['fallback']['type'] == 'home')
546
+ $return['fallback']['url'] = home_url();
547
+
548
+ if(((int)$return['method'] !== 301) || ((int)$return['method'] !== 302))
549
+ $return['method'] = 301;
550
+
551
+ return $return;
552
+
553
  }
554
 
555
+ function wp404arsp_wp_parse_args_recursive(&$a, $b){
556
+ $a = (array) $a;
557
+ $b = (array) $b;
558
+ $result = $b;
559
+ foreach ( $a as $k => &$v ) {
560
+ if ( is_array( $v ) && isset( $result[ $k ] ) ) {
561
+ $result[ $k ] = wp404arsp_wp_parse_args_recursive( $v, $result[ $k ] );
562
+ } else {
563
+ $result[ $k ] = $v;
564
+ }
565
+ }
566
+ return $result;
 
 
 
 
 
 
567
  }
568
 
569
  function wp404arsp_get_post_types($type = 'names'){
584
  if(in_array($search, $settings['rules']['redirection']['exclude']['post_types']))
585
  continue;
586
 
587
+ $filtered_post_types[] = $search;
588
  }
589
 
590
  return $filtered_post_types;
591
+ }
592
+
593
+ function wp404arsp_remove_stop_words($input){
594
+ $words = array('a', 'about', 'above', 'after', 'again', 'against', 'all', 'am', 'an', 'and', 'any', 'are', 'arent', 'as', 'at', 'be', 'because', 'been', 'before', 'being', 'below', 'between', 'both', 'but', 'by', 'cant', 'cannot', 'could', 'couldnt', 'did', 'didnt', 'do', 'does', 'doesnt', 'doing', 'dont', 'down', 'during', 'each', 'few', 'for', 'from', 'further', 'had', 'hadnt', 'has', 'hasnt', 'have', 'havent', 'having', 'he', 'hed', 'hell', 'hes', 'her', 'here', 'heres', 'hers', 'herself', 'him', 'himself', 'his', 'how', 'hows', 'i', 'id', 'ill', 'im', 'ive', 'if', 'in', 'into', 'is', 'isnt', 'it', 'its', 'itself', 'lets', 'me', 'more', 'most', 'mustnt', 'my', 'myself', 'no', 'nor', 'not', 'of', 'off', 'on', 'once', 'only', 'or', 'other', 'ought', 'our', 'ours', 'ourselves', 'out', 'over', 'own', 'same', 'shant', 'she', 'shed', 'shell', 'shes', 'should', 'shouldnt', 'so', 'some', 'such', 'than', 'that', 'thats', 'the', 'their', 'theirs', 'them', 'themselves', 'then', 'there', 'theres', 'these', 'they', 'theyd', 'theyll', 'theyre', 'theyve', 'this', 'those', 'to', 'too', 'under', 'until', 'up', 'very', 'was', 'wasnt', 'we', 'wed', 'well', 'were', 'weve', 'werent', 'what', 'whats', 'when', 'whens', 'where', 'wheres', 'which', 'while', 'who', 'whos', 'whom', 'why', 'whys', 'with', 'wont', 'would', 'wouldnt', 'you', 'youd', 'youll', 'youre', 'youve', 'your', 'yours', 'category', 'page', 'paged');
595
+
596
+ if(is_array($input)){
597
+ $return = array_diff($input, $words);
598
+
599
+ foreach($return as $key => $val){
600
+ if(is_numeric($val))
601
+ unset($return[$key]);
602
+ }
603
+
604
+ return array_values($return);
605
+
606
+ }else{
607
+ return preg_replace('/\b('.implode('|', $words).')\b/', '', $input);
608
+
609
+ }
610
  }