Redirect 404 To Homepage - Version 1.0.0

Version Description

Download this release

Release Info

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

Code changes from version 1.0.5 to 1.0.0

Files changed (3) hide show
  1. 404-to-homepage.php +21 -18
  2. admin-notices.php +0 -273
  3. readme.txt +22 -37
404-to-homepage.php CHANGED
@@ -1,13 +1,28 @@
1
  <?php
2
  /*
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.5
7
  Author: LittleBizzy
8
  Author URI: https://www.littlebizzy.com
9
- License: GPL3
10
- License URI: http://www.gnu.org/licenses/gpl-3.0.html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  */
12
 
13
 
@@ -20,7 +35,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.3');
24
 
25
 
26
  /* 404 hooks */
@@ -48,16 +63,4 @@ function ntfthp_wp() {
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()) {
58
- $timestamp = (int) get_option('ntfhp_dismissed_on');
59
- if (empty($timestamp) || (time() - $timestamp) > (180 * 86400)) {
60
- require_once(NTFTHP_PATH.'/admin-notices.php');
61
- NTFTHP_Admin_Suggestions::instance();
62
- }
63
  }
1
  <?php
2
  /*
3
  Plugin Name: 404 To Homepage
4
+ Plugin URI: https://www.littlebizzy.com/
5
+ Description: 404 To Homepage
6
+ Version: 1.0
7
  Author: LittleBizzy
8
  Author URI: https://www.littlebizzy.com
9
+
10
+ This program is free software; you can redistribute it and/or modify
11
+ it under the terms of the GNU General Public License as published by
12
+ the Free Software Foundation; either version 2 of the License, or
13
+ (at your option) any later version.
14
+
15
+ This program is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU General Public License for more details.
19
+
20
+ You should have received a copy of the GNU General Public License
21
+ along with this program; if not, write to the Free Software
22
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
+
24
+ Copyright 2016 by LittleBizzy
25
+
26
  */
27
 
28
 
35
  // This plugin constants
36
  define('NTFTHP_FILE', __FILE__);
37
  define('NTFTHP_PATH', dirname(NTFTHP_FILE));
38
+ define('NTFTHP_VERSION', '1.0');
39
 
40
 
41
  /* 404 hooks */
63
  require_once(NTFTHP_PATH.'/404-redirect.php');
64
  NTFTHP_Redirect::go();
65
  }
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
admin-notices.php DELETED
@@ -1,273 +0,0 @@
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
- 'duplicate-post-littlebizzy' => array(
36
- 'name' => 'Duplicate Post',
37
- 'desc' => 'Easily duplicate (clone) any blog post, custom post, or page in WordPress which are then saved in Draft mode, saving you tons of time and headache.',
38
- 'filename' => 'duplicate-post.php',
39
- ),
40
- 'remove-query-strings-littlebizzy' => array(
41
- 'name' => 'Remove Query Strings',
42
- 'desc' => 'Removes all query strings from static resources meaning that proxy servers and beyond can better cache your site content (plus, better SEO scores).',
43
- 'filename' => 'remove-query-strings.php',
44
- ),
45
- );
46
-
47
-
48
-
49
- // Initialization
50
- // ---------------------------------------------------------------------------------------------------
51
-
52
-
53
-
54
- /**
55
- * Create or retrieve instance
56
- */
57
- public static function instance() {
58
-
59
- // Check instance
60
- if (!isset(self::$instance))
61
- self::$instance = new NTFTHP_Admin_Suggestions;
62
-
63
- // Done
64
- return self::$instance;
65
- }
66
-
67
-
68
-
69
- /**
70
- * Constructor
71
- */
72
- private function __construct() {
73
-
74
- // Check AJAX submit
75
- if (defined('DOING_AJAX') && DOING_AJAX) {
76
- add_action( 'wp_ajax_ntfhp_dismiss', array(&$this, 'dismiss'));
77
-
78
- // Admin area (except install or activate plugins page)
79
- } elseif (!in_array(basename($_SERVER['PHP_SELF']), array('plugins.php', 'plugin-install.php', 'update.php'))) {
80
-
81
- // Admin hooks
82
- add_action('admin_footer', array(&$this, 'admin_footer'));
83
- add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
84
- }
85
- }
86
-
87
-
88
-
89
- /**
90
- * Footer script
91
- */
92
- public function admin_footer() { ?>
93
- <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>
94
- <?php }
95
-
96
-
97
-
98
- /**
99
- * Dismissi timestamp
100
- */
101
- public function dismiss() {
102
- if (!empty($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], NTFTHP_FILE.'-dismiss'))
103
- update_option('ntfhp_dismissed_on', time(), true);
104
- }
105
-
106
-
107
-
108
- // Plugins check
109
- // ---------------------------------------------------------------------------------------------------
110
-
111
-
112
-
113
- /**
114
- * Admin notices
115
- */
116
- public function admin_notices() {
117
-
118
- ?><div class="ntfhp-dismiss notice notice-success is-dismissible" data-nonce="<?php echo wp_create_nonce(NTFTHP_FILE.'-dismiss'); ?>">
119
-
120
- <p>404 To Homepage recommends the following free plugins:</p>
121
-
122
- <ul><?php foreach ($this->missing as $plugin) : ?>
123
-
124
- <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>
125
-
126
- <?php endforeach; ?></ul>
127
-
128
- </div><?php
129
- }
130
-
131
-
132
-
133
- /**
134
- * Check current active plugins
135
- */
136
- public function plugins_loaded() {
137
-
138
- // Check missing plugins
139
- $this->missing = $this->get_missing_plugins();
140
- if (empty($this->missing) || !is_array($this->missing))
141
- return;
142
-
143
- // Notice action
144
- add_action('admin_notices', array(&$this, 'admin_notices'));
145
- }
146
-
147
-
148
-
149
- /**
150
- * Retrieve uninstalled plugins
151
- */
152
- private function get_missing_plugins() {
153
-
154
- // Initialize
155
- $inactive = array();
156
-
157
- // Check plugins directory
158
- $directories = array_merge(self::get_mu_plugins_directories(), self::get_plugins_directories());
159
- if (!empty($directories)) {
160
- $required = array_keys($this->required);
161
- foreach ($required as $plugin) {
162
- if (!in_array($plugin, $directories))
163
- $inactive[] = $plugin;
164
- }
165
- }
166
-
167
- // Check inactives
168
- if (empty($inactive))
169
- return false;
170
-
171
- // Done
172
- return $inactive;
173
- }
174
-
175
-
176
-
177
- /**
178
- * Collects all active plugins
179
- */
180
- private function get_plugins_directories() {
181
-
182
- // Initialize
183
- $directories = array();
184
-
185
- // Plugins split directory
186
- $split = '/'.basename(WP_CONTENT_DIR).'/'.basename(WP_PLUGIN_DIR).'/';
187
-
188
- // Multisite plugins
189
- if (is_multisite()) {
190
- $ms_plugins = wp_get_active_network_plugins();
191
- if (!empty($ms_plugins) && is_array($ms_plugins)) {
192
- foreach ($ms_plugins as $file) {
193
- $directory = explode($split, $file);
194
- $directory = explode('/', ltrim($directory[1], '/'));
195
- $directory = $directory[0];
196
- if (!in_array($directory, $directories))
197
- $directories[] = $directory;
198
- }
199
- }
200
- }
201
-
202
- // Active plugins
203
- $plugins = wp_get_active_and_valid_plugins();
204
- if (!empty($plugins) && is_array($plugins)) {
205
- foreach ($plugins as $file) {
206
- $directory = explode($split, $file);
207
- $directory = explode('/', ltrim($directory[1], '/'));
208
- $directory = $directory[0];
209
- if (!in_array($directory, $directories))
210
- $directories[] = $directory;
211
- }
212
- }
213
-
214
- // Done
215
- return $directories;
216
- }
217
-
218
-
219
-
220
- /**
221
- * Retrieve mu-plugins directories
222
- */
223
- private function get_mu_plugins_directories() {
224
-
225
- // Initialize
226
- $directories = array();
227
-
228
- // Dependencies
229
- if (!function_exists('get_plugins'))
230
- require_once(ABSPATH.'wp-admin/includes/plugin.php');
231
-
232
- // Retrieve mu-plugins
233
- $plugins = get_plugins('/../mu-plugins');
234
- if (!empty($plugins) && is_array($plugins)) {
235
- foreach ($plugins as $path => $info) {
236
- $directory = dirname($path);
237
- if (!in_array($directory, array('.', '..')))
238
- $directories[] = $directory;
239
- }
240
- }
241
-
242
- // Done
243
- return $directories;
244
- }
245
-
246
-
247
-
248
- /**
249
- * Plugin install/activate URL
250
- */
251
- private function get_install_url($plugin) {
252
-
253
- // Check existing plugin
254
- $exists = @file_exists(WP_PLUGIN_DIR.'/'.$plugin);
255
-
256
- // Activate
257
- if ($exists) {
258
-
259
- // Existing plugin
260
- $path = $plugin.'/'.$this->required[$plugin]['filename'];
261
- return admin_url('plugins.php?action=activate&plugin='.$path.'&_wpnonce='.wp_create_nonce('activate-plugin_'.$path));
262
-
263
- // Install
264
- } else {
265
-
266
- // New plugin
267
- return admin_url('update.php?action=install-plugin&plugin='.$plugin.'&_wpnonce='.wp_create_nonce('install-plugin_'.$plugin));
268
- }
269
- }
270
-
271
-
272
-
273
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,34 +1,31 @@
1
- === Redirect 404 To Homepage ===
2
-
3
  Contributors: littlebizzy
4
- Tags: 404, homepage, home, not found, errors, page, missing, 301, redirect, htaccess
5
- Requires at least: 4.4
6
- Tested up to: 4.8
7
- Requires PHP: 7.0
8
- Stable tag: 1.0.5
9
- License: GPL3
10
- License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
12
  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.
13
 
14
  == Description ==
15
 
16
- > 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.
17
-
18
  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.
19
 
20
  It should be noted, however, that this method is not recommended for all websites. For example, large blogs or magazines that rely heavily on search engine traffic (such as a newspaper) should probably not use this plugin. This is because in many cases, 404 errors should be analyzed on a regular basis and then 301 redirected to the appropriate page. Rather, this plugin is best suited for small businesses or websites with a limited amount of content, and limited staff, who are not publishing massive amounts of content. In such cases, we suggest monitoring 404 errors for perhaps a few months, redirecting the ones that are legitimate, and then consider activating this plugin after that point.
21
 
22
  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.)
23
 
24
- ## Compatibility
25
 
26
  * __OS:__ Linux
27
  * __SERVER:__ Apache, Nginx
28
  * __PHP:__ 5.5+
29
  * __DATABASE:__ MySQL
30
 
31
- ### Plugin Features
32
 
33
  * __SETTINGS:__ None
34
  * __MUST-USE:__ Supported
@@ -38,26 +35,20 @@ Unlike other 404 redirect plugins, 404 To Homepage "removes" any pre-existing HT
38
  * __LOCALIZATION:__ None
39
  * __UNINSTALL:__ Removes plugin files only (no stored data exists)
40
 
41
- #### Future Goals
42
 
43
  * Localization (translation support)
44
  * HTTP header experimentation
45
  * More features (based on user suggestions)
46
  * Code maintenance/improvements
47
 
48
- #### Code Inspiration
49
 
50
  * [All 404 Redirect to Homepage](https://wordpress.org/plugins/all-404-redirect-to-homepage/)
51
  * [404 Redirection](https://wordpress.org/plugins/404-redirection/)
52
  * [Redirect 404 Error Page to Homepage](https://wordpress.org/plugins/redirect-404-error-page-to-homepage/)
53
 
54
- #### Extra Notes
55
-
56
- 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.
57
-
58
- 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.
59
-
60
- *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!*
61
 
62
  == Installation ==
63
 
@@ -65,7 +56,7 @@ Before to do the redirection to the homepage, there is a procedure that removes
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
- == FAQ ==
69
 
70
  = Does this plugin alter my 404.php template? =
71
 
@@ -79,23 +70,17 @@ This plugin does not have a settings page and is designed for speed and simplici
79
 
80
  Please avoid leaving negative reviews in order to get a feature implemented. Instead, we kindly ask that you post your feedback on the wordpress.org support forums by tagging this plugin in your post. If needed, you may also contact our homepage.
81
 
82
- == Changelog ==
83
 
84
- = 1.0.5 =
85
- * updated recommended plugins
86
 
87
- = 1.0.4 =
88
- * minor code tweaks
89
 
90
- = 1.0.3 =
91
- * recommended plugins
92
 
93
- = 1.0.2 =
94
- * updated plugin meta
95
- * tested with WordPress 4.8
96
 
97
- = 1.0.1 =
98
- * updated plugin meta
99
 
100
- = 1.0.0 =
101
- * initial release
1
+ === 404 To Homepage ===
 
2
  Contributors: littlebizzy
3
+ Donate link:
4
+ Tags: 404, not found, error, errors, 301, redirect, redirection, page, homepage, SEO
5
+ Requires at least: 4.7
6
+ Tested up to: 4.7
7
+ Stable tag: 1.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.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
  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.
16
 
17
  It should be noted, however, that this method is not recommended for all websites. For example, large blogs or magazines that rely heavily on search engine traffic (such as a newspaper) should probably not use this plugin. This is because in many cases, 404 errors should be analyzed on a regular basis and then 301 redirected to the appropriate page. Rather, this plugin is best suited for small businesses or websites with a limited amount of content, and limited staff, who are not publishing massive amounts of content. In such cases, we suggest monitoring 404 errors for perhaps a few months, redirecting the ones that are legitimate, and then consider activating this plugin after that point.
18
 
19
  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.)
20
 
21
+ __Compatibility:__
22
 
23
  * __OS:__ Linux
24
  * __SERVER:__ Apache, Nginx
25
  * __PHP:__ 5.5+
26
  * __DATABASE:__ MySQL
27
 
28
+ __Plugin Features:__
29
 
30
  * __SETTINGS:__ None
31
  * __MUST-USE:__ Supported
35
  * __LOCALIZATION:__ None
36
  * __UNINSTALL:__ Removes plugin files only (no stored data exists)
37
 
38
+ __Future plugin goals:__
39
 
40
  * Localization (translation support)
41
  * HTTP header experimentation
42
  * More features (based on user suggestions)
43
  * Code maintenance/improvements
44
 
45
+ __Code inspired by:__
46
 
47
  * [All 404 Redirect to Homepage](https://wordpress.org/plugins/all-404-redirect-to-homepage/)
48
  * [404 Redirection](https://wordpress.org/plugins/404-redirection/)
49
  * [Redirect 404 Error Page to Homepage](https://wordpress.org/plugins/redirect-404-error-page-to-homepage/)
50
 
51
+ 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!
 
 
 
 
 
 
52
 
53
  == Installation ==
54
 
56
  2. Activate the plugin through the 'Plugins' screen in WordPress
57
  3. Test the plugin is working correctly by loading a non-existent URL of your website
58
 
59
+ == Frequently Asked Questions ==
60
 
61
  = Does this plugin alter my 404.php template? =
62
 
70
 
71
  Please avoid leaving negative reviews in order to get a feature implemented. Instead, we kindly ask that you post your feedback on the wordpress.org support forums by tagging this plugin in your post. If needed, you may also contact our homepage.
72
 
73
+ == Screenshots ==
74
 
75
+ == Changelog ==
 
76
 
77
+ = 1.0 =
78
+ * Initial release based on research of other plugins but using better code
79
 
80
+ == Other Notes ==
 
81
 
82
+ Some details about the plugin implementation:
 
 
83
 
84
+ 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.
 
85
 
86
+ 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.