Redirect 404 To Homepage - Version 1.0.3

Version Description

  • recommended plugins
Download this release

Release Info

Developer littlebizzy
Plugin Icon 128x128 Redirect 404 To Homepage
Version 1.0.3
Comparing to
See all releases

Code changes from version 1.0.2 to 1.0.3

Files changed (3) hide show
  1. 404-to-homepage.php +14 -2
  2. admin-suggestions.php +268 -0
  3. readme.txt +19 -16
404-to-homepage.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: 404 To Homepage
4
  Plugin URI: https://www.littlebizzy.com/plugins/404-to-homepage
5
  Description: Redirects all 404 (Not Found) errors to the homepage for a better user experience, less abuse from bots, and 100% elimination of Google GSC warnings.
6
- Version: 1.0.2
7
  Author: LittleBizzy
8
  Author URI: https://www.littlebizzy.com
9
  License: GPL3
@@ -20,7 +20,7 @@ if (!function_exists('add_action'))
20
  // This plugin constants
21
  define('NTFTHP_FILE', __FILE__);
22
  define('NTFTHP_PATH', dirname(NTFTHP_FILE));
23
- define('NTFTHP_VERSION', '1.0');
24
 
25
 
26
  /* 404 hooks */
@@ -48,4 +48,16 @@ function ntfthp_wp() {
48
  require_once(NTFTHP_PATH.'/404-redirect.php');
49
  NTFTHP_Redirect::go();
50
  }
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
3
  Plugin Name: 404 To Homepage
4
  Plugin URI: https://www.littlebizzy.com/plugins/404-to-homepage
5
  Description: Redirects all 404 (Not Found) errors to the homepage for a better user experience, less abuse from bots, and 100% elimination of Google GSC warnings.
6
+ Version: 1.0.3
7
  Author: LittleBizzy
8
  Author URI: https://www.littlebizzy.com
9
  License: GPL3
20
  // This plugin constants
21
  define('NTFTHP_FILE', __FILE__);
22
  define('NTFTHP_PATH', dirname(NTFTHP_FILE));
23
+ define('NTFTHP_VERSION', '1.0.3');
24
 
25
 
26
  /* 404 hooks */
48
  require_once(NTFTHP_PATH.'/404-redirect.php');
49
  NTFTHP_Redirect::go();
50
  }
51
+ }
52
+
53
+
54
+ /* Plugin suggestions */
55
+
56
+ // Admin loader
57
+ if (is_admin()) {//update_option('ntfhp_dismissed_on', '', true);
58
+ $timestamp = (int) get_option('ntfhp_dismissed_on');
59
+ if (empty($timestamp) || (time() - $timestamp) > (90 * 86400)) {
60
+ require_once(NTFTHP_PATH.'/admin-suggestions.php');
61
+ NTFTHP_Admin_Suggestions::instance();
62
+ }
63
  }
admin-suggestions.php ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * 404 To Homepage - Plugins Suggestions class
5
+ *
6
+ * @package 404 To Homepage
7
+ * @subpackage 404 To Homepage Admin
8
+ */
9
+ final class NTFTHP_Admin_Suggestions {
10
+
11
+
12
+
13
+ // Properties
14
+ // ---------------------------------------------------------------------------------------------------
15
+
16
+
17
+
18
+ /**
19
+ * Single class instance
20
+ */
21
+ private static $instance;
22
+
23
+
24
+
25
+ /**
26
+ * Plugins directories
27
+ */
28
+ private $missing;
29
+ private $required = array(
30
+ 'server-status-littlebizzy' => array(
31
+ 'name' => 'Server Status',
32
+ 'desc' => 'Useful statistics about the server OS, CPU, RAM, load average, memory usage, IP address, hostname, timezone, disk space, PHP, MySQL, caches, etc.',
33
+ 'filename' => 'server-status.php',
34
+ ),
35
+ 'remove-query-strings-littlebizzy' => array(
36
+ 'name' => 'Remove Query Strings',
37
+ 'desc' => 'Removes all query strings from static resources meaning that proxy servers and beyond can better cache your site content (plus, better SEO scores).',
38
+ 'filename' => 'remove-query-strings.php',
39
+ ),
40
+ );
41
+
42
+
43
+
44
+ // Initialization
45
+ // ---------------------------------------------------------------------------------------------------
46
+
47
+
48
+
49
+ /**
50
+ * Create or retrieve instance
51
+ */
52
+ public static function instance() {
53
+
54
+ // Check instance
55
+ if (!isset(self::$instance))
56
+ self::$instance = new NTFTHP_Admin_Suggestions;
57
+
58
+ // Done
59
+ return self::$instance;
60
+ }
61
+
62
+
63
+
64
+ /**
65
+ * Constructor
66
+ */
67
+ private function __construct() {
68
+
69
+ // Check AJAX submit
70
+ if (defined('DOING_AJAX') && DOING_AJAX) {
71
+ add_action( 'wp_ajax_ntfhp_dismiss', array(&$this, 'dismiss'));
72
+
73
+ // Admin area (except install or activate plugins page)
74
+ } elseif (!in_array(basename($_SERVER['PHP_SELF']), array('plugins.php', 'plugin-install.php', 'update.php'))) {
75
+
76
+ // Admin hooks
77
+ add_action('admin_footer', array(&$this, 'admin_footer'));
78
+ add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
79
+ }
80
+ }
81
+
82
+
83
+
84
+ /**
85
+ * Footer script
86
+ */
87
+ public function admin_footer() { ?>
88
+ <script type="text/javascript">jQuery(function($) { $(document).on('click', '.ntfhp-dismiss .notice-dismiss', function() { $.post(ajaxurl, {'action':'ntfhp_dismiss','nonce':$(this).parent().attr('data-nonce')}); }); });</script>
89
+ <?php }
90
+
91
+
92
+
93
+ /**
94
+ * Dismissi timestamp
95
+ */
96
+ public function dismiss() {
97
+ if (!empty($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], NTFTHP_FILE.'-dismiss'))
98
+ update_option('ntfhp_dismissed_on', time(), true);
99
+ }
100
+
101
+
102
+
103
+ // Plugins check
104
+ // ---------------------------------------------------------------------------------------------------
105
+
106
+
107
+
108
+ /**
109
+ * Admin notices
110
+ */
111
+ public function admin_notices() {
112
+
113
+ ?><div class="ntfhp-dismiss notice notice-success is-dismissible" data-nonce="<?php echo wp_create_nonce(NTFTHP_FILE.'-dismiss'); ?>">
114
+
115
+ <p>404 To Homepage recommends the following free plugins:</p>
116
+
117
+ <ul><?php foreach ($this->missing as $plugin) : ?>
118
+
119
+ <li><strong><?php echo $this->required[$plugin]['name']; ?></strong> <a href="<?php echo esc_url($this->get_install_url($plugin)); ?>">Install now!</a><br /><?php echo $this->required[$plugin]['desc']; ?></li>
120
+
121
+ <?php endforeach; ?></ul>
122
+
123
+ </div><?php
124
+ }
125
+
126
+
127
+
128
+ /**
129
+ * Check current active plugins
130
+ */
131
+ public function plugins_loaded() {
132
+
133
+ // Check missing plugins
134
+ $this->missing = $this->get_missing_plugins();
135
+ if (empty($this->missing) || !is_array($this->missing))
136
+ return;
137
+
138
+ // Notice action
139
+ add_action('admin_notices', array(&$this, 'admin_notices'));
140
+ }
141
+
142
+
143
+
144
+ /**
145
+ * Retrieve uninstalled plugins
146
+ */
147
+ private function get_missing_plugins() {
148
+
149
+ // Initialize
150
+ $inactive = array();
151
+
152
+ // Check plugins directory
153
+ $directories = array_merge(self::get_mu_plugins_directories(), self::get_plugins_directories());
154
+ if (!empty($directories)) {
155
+ $required = array_keys($this->required);
156
+ foreach ($required as $plugin) {
157
+ if (!in_array($plugin, $directories))
158
+ $inactive[] = $plugin;
159
+ }
160
+ }
161
+
162
+ // Check inactives
163
+ if (empty($inactive))
164
+ return false;
165
+
166
+ // Done
167
+ return $inactive;
168
+ }
169
+
170
+
171
+
172
+ /**
173
+ * Collects all active plugins
174
+ */
175
+ private function get_plugins_directories() {
176
+
177
+ // Initialize
178
+ $directories = array();
179
+
180
+ // Plugins split directory
181
+ $split = '/'.basename(WP_CONTENT_DIR).'/'.basename(WP_PLUGIN_DIR).'/';
182
+
183
+ // Multisite plugins
184
+ if (is_multisite()) {
185
+ $ms_plugins = wp_get_active_network_plugins();
186
+ if (!empty($ms_plugins) && is_array($ms_plugins)) {
187
+ foreach ($ms_plugins as $file) {
188
+ $directory = explode($split, $file);
189
+ $directory = explode('/', ltrim($directory[1], '/'));
190
+ $directory = $directory[0];
191
+ if (!in_array($directory, $directories))
192
+ $directories[] = $directory;
193
+ }
194
+ }
195
+ }
196
+
197
+ // Active plugins
198
+ $plugins = wp_get_active_and_valid_plugins();
199
+ if (!empty($plugins) && is_array($plugins)) {
200
+ foreach ($plugins as $file) {
201
+ $directory = explode($split, $file);
202
+ $directory = explode('/', ltrim($directory[1], '/'));
203
+ $directory = $directory[0];
204
+ if (!in_array($directory, $directories))
205
+ $directories[] = $directory;
206
+ }
207
+ }
208
+
209
+ // Done
210
+ return $directories;
211
+ }
212
+
213
+
214
+
215
+ /**
216
+ * Retrieve mu-plugins directories
217
+ */
218
+ private function get_mu_plugins_directories() {
219
+
220
+ // Initialize
221
+ $directories = array();
222
+
223
+ // Dependencies
224
+ if (!function_exists('get_plugins'))
225
+ require_once(ABSPATH.'wp-admin/includes/plugin.php');
226
+
227
+ // Retrieve mu-plugins
228
+ $plugins = get_plugins('/../mu-plugins');
229
+ if (!empty($plugins) && is_array($plugins)) {
230
+ foreach ($plugins as $path => $info) {
231
+ $directory = dirname($path);
232
+ if (!in_array($directory, array('.', '..')))
233
+ $directories[] = $directory;
234
+ }
235
+ }
236
+
237
+ // Done
238
+ return $directories;
239
+ }
240
+
241
+
242
+
243
+ /**
244
+ * Plugin install/activate URL
245
+ */
246
+ private function get_install_url($plugin) {
247
+
248
+ // Check existing plugin
249
+ $exists = @file_exists(WP_PLUGIN_DIR.'/'.$plugin);
250
+
251
+ // Activate
252
+ if ($exists) {
253
+
254
+ // Existing plugin
255
+ $path = $plugin.'/'.$this->required[$plugin]['filename'];
256
+ return admin_url('plugins.php?action=activate&plugin='.$path.'&_wpnonce='.wp_create_nonce('activate-plugin_'.$path));
257
+
258
+ // Install
259
+ } else {
260
+
261
+ // New plugin
262
+ return admin_url('update.php?action=install-plugin&plugin='.$plugin.'&_wpnonce='.wp_create_nonce('install-plugin_'.$plugin));
263
+ }
264
+ }
265
+
266
+
267
+
268
+ }
readme.txt CHANGED
@@ -1,20 +1,18 @@
1
  === Redirect 404 To Homepage ===
2
  Contributors: littlebizzy
3
- Donate link:
4
  Tags: 404, not found, error, errors, missing, 301, redirect, redirection, page, homepage, home, htaccess
5
  Requires at least: 4.4
6
  Tested up to: 4.8
7
- Stable tag: 1.0.2
8
  License: GPL3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
11
  Redirects all 404 (Not Found) errors to the homepage for a better user experience, less abuse from bots, and 100% elimination of Google GSC warnings.
12
 
13
- == Description ==
14
 
15
- *Redirects all 404 (Not Found) errors to the homepage for a better user experience, less abuse from bots, and 100% elimination of Google GSC warnings.*
16
 
17
- ---
18
 
19
  404 To Homepage is a simple WordPress plugin for redirecting all 404 "Not Found" errors to the homepage. The reason for doing this is to avoid user confusion (or lost leads), and to avoid abuse causes by bots that ping your site with non-existent URLs which can negatively effect search engine indexing. Additionally, it can totally eliminate the warnings created in Google GSC (Webmasters) in regard to 404 errors that begin piling up over time, which quite often are not even the fault of your website.
20
 
@@ -22,14 +20,14 @@ It should be noted, however, that this method is not recommended for all website
22
 
23
  Unlike other 404 redirect plugins, 404 To Homepage "removes" any pre-existing HTTP headers, and executes ONLY a 301 redirect header pointed at the site's homepage. In other words, it does not allow any "previous" headers to be sent in order to avoid confusing browsers or Google bots. (NOTE: while any previous headers sent by WordPress/PHP engine are ignored, it's possible for your server i.e. Apache or Nginx to override things with header rules of their own... please check to ensure no conflicts.)
24
 
25
- __Compatibility:__
26
 
27
  * __OS:__ Linux
28
  * __SERVER:__ Apache, Nginx
29
  * __PHP:__ 5.5+
30
  * __DATABASE:__ MySQL
31
 
32
- __Plugin Features:__
33
 
34
  * __SETTINGS:__ None
35
  * __MUST-USE:__ Supported
@@ -39,33 +37,35 @@ __Plugin Features:__
39
  * __LOCALIZATION:__ None
40
  * __UNINSTALL:__ Removes plugin files only (no stored data exists)
41
 
42
- __Future plugin goals:__
43
 
44
  * Localization (translation support)
45
  * HTTP header experimentation
46
  * More features (based on user suggestions)
47
  * Code maintenance/improvements
48
 
49
- __Code inspired by:__
50
 
51
  * [All 404 Redirect to Homepage](https://wordpress.org/plugins/all-404-redirect-to-homepage/)
52
  * [404 Redirection](https://wordpress.org/plugins/404-redirection/)
53
  * [Redirect 404 Error Page to Homepage](https://wordpress.org/plugins/redirect-404-error-page-to-homepage/)
54
 
55
- NOTE: We released this plugin in response to our managed hosting clients asking for better access to their server environment, and our primary goal will likely remain supporting that purpose. Although we are 100% open to fielding requests from the WordPress community, we kindly ask that you consider all of the above mentioned goals before leaving reviews of this plugin, thanks!
56
-
57
- Some details about the plugin implementation:
58
 
59
  This is a version that uses the early WP hook 'pre_handle_404' to avoid unnecessary code execution (posts types creation and taxonomies). But this hook is available only from WP 4.5.0, so the plugin declares also the 'wp' standard hook just in case for older versions.
60
 
61
  Before to do the redirection to the homepage, there is a procedure that removes any existing previous header, so only 301 header will be sent in response to the HTTP request. You can see the headers in chrome from Network tab and checking preserve log. For Firefox you can use the Live HTTP headers addon, for example.
62
 
 
 
 
63
  == Installation ==
64
 
65
  1. Upload the plugin files to `/wp-content/plugins/404-to-homepage-littlebizzy`
66
  2. Activate the plugin through the 'Plugins' screen in WordPress
67
  3. Test the plugin is working correctly by loading a non-existent URL of your website
68
 
 
69
  == Frequently Asked Questions ==
70
 
71
  = Does this plugin alter my 404.php template? =
@@ -83,12 +83,15 @@ Please avoid leaving negative reviews in order to get a feature implemented. Ins
83
 
84
  == Changelog ==
85
 
 
 
 
86
  = 1.0.2 =
87
- * tweaked plugin meta
88
- * tested with WP 4.8
89
 
90
  = 1.0.1 =
91
- * fixed plugin meta data (description, etc)
92
 
93
  = 1.0 =
94
- * Initial release based on research of other plugins but using better code
1
  === Redirect 404 To Homepage ===
2
  Contributors: littlebizzy
 
3
  Tags: 404, not found, error, errors, missing, 301, redirect, redirection, page, homepage, home, htaccess
4
  Requires at least: 4.4
5
  Tested up to: 4.8
6
+ Stable tag: 1.0.3
7
  License: GPL3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
10
  Redirects all 404 (Not Found) errors to the homepage for a better user experience, less abuse from bots, and 100% elimination of Google GSC warnings.
11
 
 
12
 
13
+ == Description ==
14
 
15
+ ### Redirects all 404 (Not Found) errors to the homepage for a better user experience, less abuse from bots, and 100% elimination of Google GSC warnings.
16
 
17
  404 To Homepage is a simple WordPress plugin for redirecting all 404 "Not Found" errors to the homepage. The reason for doing this is to avoid user confusion (or lost leads), and to avoid abuse causes by bots that ping your site with non-existent URLs which can negatively effect search engine indexing. Additionally, it can totally eliminate the warnings created in Google GSC (Webmasters) in regard to 404 errors that begin piling up over time, which quite often are not even the fault of your website.
18
 
20
 
21
  Unlike other 404 redirect plugins, 404 To Homepage "removes" any pre-existing HTTP headers, and executes ONLY a 301 redirect header pointed at the site's homepage. In other words, it does not allow any "previous" headers to be sent in order to avoid confusing browsers or Google bots. (NOTE: while any previous headers sent by WordPress/PHP engine are ignored, it's possible for your server i.e. Apache or Nginx to override things with header rules of their own... please check to ensure no conflicts.)
22
 
23
+ #### Compatibility
24
 
25
  * __OS:__ Linux
26
  * __SERVER:__ Apache, Nginx
27
  * __PHP:__ 5.5+
28
  * __DATABASE:__ MySQL
29
 
30
+ #### Plugin Features
31
 
32
  * __SETTINGS:__ None
33
  * __MUST-USE:__ Supported
37
  * __LOCALIZATION:__ None
38
  * __UNINSTALL:__ Removes plugin files only (no stored data exists)
39
 
40
+ #### Future Goals
41
 
42
  * Localization (translation support)
43
  * HTTP header experimentation
44
  * More features (based on user suggestions)
45
  * Code maintenance/improvements
46
 
47
+ #### Code Inspiration
48
 
49
  * [All 404 Redirect to Homepage](https://wordpress.org/plugins/all-404-redirect-to-homepage/)
50
  * [404 Redirection](https://wordpress.org/plugins/404-redirection/)
51
  * [Redirect 404 Error Page to Homepage](https://wordpress.org/plugins/redirect-404-error-page-to-homepage/)
52
 
53
+ #### Extra Notes
 
 
54
 
55
  This is a version that uses the early WP hook 'pre_handle_404' to avoid unnecessary code execution (posts types creation and taxonomies). But this hook is available only from WP 4.5.0, so the plugin declares also the 'wp' standard hook just in case for older versions.
56
 
57
  Before to do the redirection to the homepage, there is a procedure that removes any existing previous header, so only 301 header will be sent in response to the HTTP request. You can see the headers in chrome from Network tab and checking preserve log. For Firefox you can use the Live HTTP headers addon, for example.
58
 
59
+ *We released this plugin in response to our managed hosting clients asking for better access to their server environment, and our primary goal will likely remain supporting that purpose. Although we are 100% open to fielding requests from the WordPress community, we kindly ask that you consider all of the above mentioned goals before leaving reviews of this plugin, thanks!*
60
+
61
+
62
  == Installation ==
63
 
64
  1. Upload the plugin files to `/wp-content/plugins/404-to-homepage-littlebizzy`
65
  2. Activate the plugin through the 'Plugins' screen in WordPress
66
  3. Test the plugin is working correctly by loading a non-existent URL of your website
67
 
68
+
69
  == Frequently Asked Questions ==
70
 
71
  = Does this plugin alter my 404.php template? =
83
 
84
  == Changelog ==
85
 
86
+ = 1.0.3 =
87
+ * recommended plugins
88
+
89
  = 1.0.2 =
90
+ * updated plugin meta
91
+ * tested with WordPress 4.8
92
 
93
  = 1.0.1 =
94
+ * updated plugin meta
95
 
96
  = 1.0 =
97
+ * Initial release