404 to 301 - Version 2.1.5

Version Description

(22/03/2016) = Improvements

  • Fixed issues with deprecated functions - Thanks to Pedro Mendonas.
  • Translated missing strings.
  • Tested with WordPress 4.4.2.
Download this release

Release Info

Developer joelcj91
Plugin Icon 128x128 404 to 301
Version 2.1.5
Comparing to
See all releases

Code changes from version 2.1.4 to 2.1.5

404-to-301.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
  /**
3
- * Plugin Name: 404 to 301
4
- * Plugin URI: http://iscode.co/products/404-to-301/
5
- * Description: Automatically redirect all <strong>404 errors</strong> to any page using <strong>301 redirect for SEO</strong>. You can <strong>redirect and log</strong> every 404 errors. No more 404 errors in Webmaster tool.
6
- * Version: 2.1.4
7
- * Author: Joel James
8
- * Author URI: http://iscode.co/
9
- * Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
10
- * License: GPL-2.0+
11
- * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
- * Text Domain: 404-to-301
13
- * Domain Path: /languages
14
  *
15
  * 404 to 301 is free software: you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
@@ -28,35 +28,34 @@
28
  * @package I4T3
29
  * @category Core
30
  * @author Joel James
31
- * @version 2.1.4
32
  */
33
-
34
  // If this file is called directly, abort.
35
- if ( ! defined( 'WPINC' ) ) {
36
- die('Damn it.! Dude you are looking for what?');
37
  }
38
 
39
- if(!defined('I4T3_PATH')){
40
- define( 'I4T3_PATH', home_url( PLUGINDIR . '/404-to-301/' ) );
41
  }
42
- if(!defined('I4T3_PLUGIN_DIR')) {
43
- define( 'I4T3_PLUGIN_DIR', __FILE__ );
44
  }
45
- if(!defined('I4T3_SETTINGS_PAGE')) {
46
- define( 'I4T3_SETTINGS_PAGE', admin_url( 'admin.php?page=i4t3-settings' ) );
47
  }
48
- if(!defined('I4T3_LOGS_PAGE')) {
49
- define( 'I4T3_LOGS_PAGE', admin_url( 'admin.php?page=i4t3-logs' ) );
50
  }
51
- if(!defined('I4T3_DB_VERSION')) {
52
- define( 'I4T3_DB_VERSION', '3' );
53
  }
54
- if(!defined('I4T3_VERSION')) {
55
- define( 'I4T3_VERSION', '2.1.4' );
56
  }
57
  // Set who all can access 404 settings. You can change this if you want to give others access.
58
- if(!defined('I4T3_ADMIN_PERMISSION')) {
59
- define( 'I4T3_ADMIN_PERMISSION', 'manage_options' );
60
  }
61
 
62
  /**
@@ -64,16 +63,17 @@ if(!defined('I4T3_ADMIN_PERMISSION')) {
64
  * This action is documented in includes/class-dcl-activator.php
65
  */
66
  function activate_i4t3() {
67
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-404-to-301-activator.php';
68
- _404_To_301_Activator::activate();
69
  }
70
- register_activation_hook( __FILE__, 'activate_i4t3' );
 
71
 
72
  /**
73
  * The core plugin class that is used to define
74
  * dashboard-specific hooks, and public-facing site hooks.
75
  */
76
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-404-to-301.php';
77
 
78
  /**
79
  * Begins execution of the plugin.
@@ -86,10 +86,10 @@ require_once plugin_dir_path( __FILE__ ) . 'includes/class-404-to-301.php';
86
  */
87
  function run_i4t3() {
88
 
89
- $plugin = new _404_To_301();
90
- $plugin->run();
91
-
92
  }
 
93
  run_i4t3();
94
 
95
  //*** Thank you for your interest in 404 to 301 - Developed and managed by Joel James ***//
1
  <?php
2
  /**
3
+ * Plugin Name: 404 to 301
4
+ * Plugin URI: http://iscode.co/products/404-to-301/
5
+ * Description: Automatically redirect all <strong>404 errors</strong> to any page using <strong>301 redirect for SEO</strong>. You can <strong>redirect and log</strong> every 404 errors. No more 404 errors in Webmaster tool.
6
+ * Version: 2.1.5
7
+ * Author: Joel James
8
+ * Author URI: http://iscode.co/
9
+ * Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
10
+ * License: GPL-2.0+
11
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
+ * Text Domain: 404-to-301
13
+ * Domain Path: /languages
14
  *
15
  * 404 to 301 is free software: you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
28
  * @package I4T3
29
  * @category Core
30
  * @author Joel James
31
+ * @version 2.1.5
32
  */
 
33
  // If this file is called directly, abort.
34
+ if (!defined('WPINC')) {
35
+ die('Damn it.! Dude you are looking for what?');
36
  }
37
 
38
+ if (!defined('I4T3_PATH')) {
39
+ define('I4T3_PATH', plugins_url('/404-to-301/'));
40
  }
41
+ if (!defined('I4T3_PLUGIN_DIR')) {
42
+ define('I4T3_PLUGIN_DIR', __FILE__);
43
  }
44
+ if (!defined('I4T3_SETTINGS_PAGE')) {
45
+ define('I4T3_SETTINGS_PAGE', admin_url('admin.php?page=i4t3-settings'));
46
  }
47
+ if (!defined('I4T3_LOGS_PAGE')) {
48
+ define('I4T3_LOGS_PAGE', admin_url('admin.php?page=i4t3-logs'));
49
  }
50
+ if (!defined('I4T3_DB_VERSION')) {
51
+ define('I4T3_DB_VERSION', '3');
52
  }
53
+ if (!defined('I4T3_VERSION')) {
54
+ define('I4T3_VERSION', '2.1.5');
55
  }
56
  // Set who all can access 404 settings. You can change this if you want to give others access.
57
+ if (!defined('I4T3_ADMIN_PERMISSION')) {
58
+ define('I4T3_ADMIN_PERMISSION', 'manage_options');
59
  }
60
 
61
  /**
63
  * This action is documented in includes/class-dcl-activator.php
64
  */
65
  function activate_i4t3() {
66
+ require_once plugin_dir_path(__FILE__) . 'includes/class-404-to-301-activator.php';
67
+ _404_To_301_Activator::activate();
68
  }
69
+
70
+ register_activation_hook(__FILE__, 'activate_i4t3');
71
 
72
  /**
73
  * The core plugin class that is used to define
74
  * dashboard-specific hooks, and public-facing site hooks.
75
  */
76
+ require_once plugin_dir_path(__FILE__) . 'includes/class-404-to-301.php';
77
 
78
  /**
79
  * Begins execution of the plugin.
86
  */
87
  function run_i4t3() {
88
 
89
+ $plugin = new _404_To_301();
90
+ $plugin->run();
 
91
  }
92
+
93
  run_i4t3();
94
 
95
  //*** Thank you for your interest in 404 to 301 - Developed and managed by Joel James ***//
admin/class-404-to-301-admin.php CHANGED
@@ -1,8 +1,9 @@
1
  <?php
2
  // If this file is called directly, abort.
3
- if ( ! defined( 'WPINC' ) ) {
4
- die('Damn it.! Dude you are looking for what?');
5
  }
 
6
  /**
7
  * The dashboard-specific functionality of the plugin.
8
  *
@@ -17,416 +18,394 @@ if ( ! defined( 'WPINC' ) ) {
17
  */
18
  class _404_To_301_Admin {
19
 
20
- /**
21
- * The ID of this plugin.
22
- *
23
- * @since 2.0.0
24
- * @access private
25
- * @var string $plugin_name The ID of this plugin.
26
- */
27
- private $plugin_name;
28
-
29
- /**
30
- * The version of this plugin.
31
- *
32
- * @since 2.0.0
33
- * @access private
34
- * @var string $version The current version of this plugin.
35
- */
36
- private $version;
37
-
38
- /**
39
- * The table name of this plugin.
40
- *
41
- * @since 2.0.0
42
- * @access private
43
- * @var string $table The table name of this plugin in db.
44
- */
45
- private $table;
46
-
47
- /**
48
- * The options from db.
49
- *
50
- * @since 2.0.0
51
- * @access private
52
- * @var string $gnrl_options Get the options saved in db.
53
- */
54
- private $gnrl_options;
55
-
56
- /**
57
- * The options from db.
58
- *
59
- * @since 2.1.0
60
- * @access private
61
- * @var mixed $list_table Class object for listing table.
62
- */
63
- private $list_table;
64
-
65
- /**
66
- * Initialize the class and set its properties.
67
- *
68
- * @since 2.0.0
69
- * @var string $plugin_name The name of this plugin.
70
- * @var string $version The version of this plugin.
71
- * @var string $table The name of the database table of this plugin.
72
- */
73
- public function __construct( $plugin_name, $version, $table ) {
74
-
75
- $this->plugin_name = $plugin_name;
76
- $this->version = $version;
77
- $this->table = $table;
78
- $this->gnrl_options = get_option( 'i4t3_gnrl_options' );
79
- }
80
-
81
-
82
- /**
83
- * Register the stylesheet for the Dashboard.
84
- *
85
- * This function is used to register all the required stylesheets for
86
- * dashboard. Styles will be registered only for i4t3 pages for performance.
87
- *
88
- * @since 2.0.0
89
- * @uses wp_enqueue_style To register style
90
- */
91
- public function enqueue_styles() {
92
-
93
- global $pagenow;
94
-
95
- if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings','i4t3-logs')))) {
96
- wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/min/admin.css', array(), $this->version, 'all' );
97
- }
98
-
99
- }
100
-
101
-
102
- /**
103
- * Register the scripts for the Dashboard.
104
- *
105
- * This function is used to register all the required scripts for
106
- * dashboard. Scripts will be registered only for i4t3 pages for performance.
107
- *
108
- * @since 2.0.0
109
- * @uses wp_enqueue_script To register script
110
- */
111
- public function enqueue_scripts() {
112
-
113
- global $pagenow;
114
-
115
- if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings')))) {
116
- wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), $this->version, false );
117
- }
118
-
119
- }
120
-
121
-
122
- /**
123
- * Run upgrade functions
124
- *
125
- * If 404 to 301 is upgraded, we may need to perform few updations in db
126
- *
127
- * @since 2.0.0
128
- * @uses get_option() To get the activation redirect option from db.
129
- * @return void.
130
- */
131
- public function i4t3_upgrade_if_new() {
132
-
133
- if ( !get_option('i4t3_version_no') || ( get_option('i4t3_version_no') < I4T3_VERSION ) ) {
134
- if( class_exists( '_404_To_301_Activator' ) ) {
135
- _404_To_301_Activator::activate();
136
- }
137
- update_option('i4t3_version_no', I4T3_VERSION );
138
- }
139
- }
140
-
141
- /**
142
- * Changing email notification recipient
143
- *
144
- * Using filter to change email notification recipient address from
145
- * default admin email.
146
- *
147
- * @since 2.0.7
148
- * @uses get_option() To get the email address option from db.
149
- * @return $email Email address to be used for notification.
150
- */
151
- public function i4t3_change_notify_email( $email ) {
152
- if( !empty( $this->gnrl_options['email_notify_address'] ) ) {
153
- $email_option = $this->gnrl_options['email_notify_address'];
154
- if( is_email( $email_option ) ) {
155
- $email = $email_option;
156
- }
157
- }
158
- return $email;
159
- }
160
-
161
-
162
- /**
163
- * Creating admin menus for 404 to 301.
164
- *
165
- * @since 2.0.0
166
- * @author Joel James
167
- * @uses action hook add_submenu_page Action hook to add new admin menu sub page.
168
- */
169
- public function i4t3_create_404_to_301_menu(){
170
-
171
- // Error log menu
172
- $hook = add_menu_page(
173
- __( '404 Error Logs', '404-to-301' ),
174
- __( '404 Error Logs', '404-to-301' ),
175
- I4T3_ADMIN_PERMISSION,
176
- 'i4t3-logs',
177
- array( $this,'i4t3_render_list_page' ),
178
- 'dashicons-redo',
179
- 90
180
- );
181
-
182
- add_action( "load-$hook", array( $this, 'screen_option' ) );
183
-
184
- // 404 to 301 settings menu
185
- add_submenu_page(
186
- 'i4t3-logs',
187
- __( '404 to 301 Settings', '404-to-301' ),
188
- '404 Settings',
189
- I4T3_ADMIN_PERMISSION,
190
- 'i4t3-settings',
191
- array( $this, 'i4t3_admin_page' )
192
- );
193
- }
194
-
195
-
196
- /**
197
  * To set the screen of the error listing page.
198
  *
199
  * @since 2.1.0
200
  * @author Joel James.
201
  */
202
- public static function set_screen( $status, $option, $value ) {
203
- return $value;
204
- }
205
-
206
- /**
207
  * To make screen options for 404 to 301 listing.
208
  *
209
  * This function is used to show screen options like entries per page,
210
- * show/hide columns etc.
211
  *
212
  * @since 2.1.0
213
  * @author Joel James.
214
  */
215
- public function screen_option() {
216
-
217
- $option = 'per_page';
218
- $args = array(
219
- 'label' => __( 'Error Logs', '404-to-301' ),
220
- 'default' => 5,
221
- 'option' => 'logs_per_page'
222
- );
223
-
224
- add_screen_option( $option, $args );
225
-
226
- $this->list_table = new _404_To_301_Logs( $this->table );
227
- }
228
-
229
-
230
- /**
231
- * Output buffer function
232
- *
233
- * To avoid header already sent issue
234
- * @link https://tommcfarlin.com/wp_redirect-headers-already-sent/
235
- * @since 2.1.4
236
- */
237
- public function add_buffer() {
238
-
239
- ob_start();
240
- }
241
-
242
-
243
- /**
244
- * Creating log table page.
245
- *
246
- * @since 2.0.0
247
- * @author Joel James
248
- * @uses class _404_To_301_Logs To initialize and load the log listing table.
249
- */
250
- public function i4t3_render_list_page(){
251
-
252
- ?>
253
- <div class="wrap">
254
- <h2><?php _e( '404 Error Logs', '404-to-301' ); ?></h2>
255
-
256
- <div id="poststuff">
257
- <div id="post-body" class="metabox-holder">
258
- <div id="post-body-content">
259
- <div class="meta-box-sortables ui-sortable">
260
- <form method="post">
261
- <?php
262
- $this->list_table->prepare_items();
263
- $this->list_table->display(); ?>
264
- </form>
265
- </div>
266
- </div>
267
- </div>
268
- <br class="clear">
269
- </div>
270
- </div>
271
- <?php
272
- }
273
-
274
-
275
- /**
276
- * Rename admin menu text to : 404 to 301.
277
- *
278
- * @since 2.0.0
279
- * @author Joel James
280
- * @var global $menu menus registered in this site.
281
- */
282
- public function i4t3_rename_plugin_menu() {
283
- global $menu;
284
- $menu[90][0] = __( '404 to 301', '404-to-301' ); // Change menu text
285
- }
286
-
287
-
288
- /**
289
- * Admin options page display.
290
- *
291
- * Includes admin page contents to manage i4t3 settings.
292
- * All html parts will be included in this page.
293
- *
294
- * @since 2.0.0
295
- * @author Joel James
296
- */
297
- public function i4t3_admin_page() {
298
-
299
- require plugin_dir_path( __FILE__ ) . 'partials/404-to-301-admin-display.php';
300
- }
301
-
302
-
303
- /**
304
- * Registering i4t3 options.
305
- * This function is used to register all settings options to the db using
306
- * WordPress settings API.
307
- * If we want to register another setting, we can include that here.
308
- *
309
- * @since 2.0.0
310
- * @author Joel James
311
- * @action hooks register_setting Hook to register i4t3 options in db.
312
- */
313
- public function i4t3_options_register(){
314
-
315
- register_setting(
316
- 'i4t3_gnrl_options',
317
- 'i4t3_gnrl_options'
318
- );
319
-
320
- }
321
-
322
-
323
- /**
324
- * Custom footer text for i4t3 pages.
325
- *
326
- * Function to alter the default footer text to show i4t3 credits only on i4t3 pages.
327
- *
328
- * @since 2.0.0
329
- * @author Joel James
330
- */
331
- function i4t3_dashboard_footer () {
332
-
333
- global $pagenow;
334
- if (( $pagenow == 'admin.php' ) && ( in_array ( $_GET['page'], array('i4t3-settings', 'i4t3-logs')))) {
335
-
336
- _e( 'Thank you for choosing 404 to 301 to improve your website', '404-to-301' );
337
- echo ' | ';
338
- _e( 'Kindly give this plugin a','404-to-301');
339
- echo '<a href="https://wordpress.org/support/view/plugin-reviews/404-to-301?filter=5#postform">';
340
- _e( 'rating','404-to-301');
341
- echo ' &#9733; &#9733;</a>';
342
- } else {
343
- return;
344
- }
345
- }
346
-
347
-
348
- /**
349
- * Custom Plugin Action Link.
350
- *
351
- * Function to add a quick link to i4t3, when being listed on your
352
- * plugins list view.
353
- *
354
- * @since 2.0.0
355
- * @return $links Links to display.
356
- * @author Joel James
357
- */
358
- public function i4t3_plugin_action_links( $links, $file ) {
359
- $plugin_file = basename('404-to-301.php');
360
- if (basename($file) == $plugin_file) {
361
- $settings_link = '<a href="admin.php?page=i4t3-settings">'. __( 'Settings', '404-to-301' ) .'</a>';
362
- $settings_link .= ' | <a href="admin.php?page=i4t3-logs">'. __( 'Logs', '404-to-301' ) .'</a>';
363
- array_unshift($links, $settings_link);
364
- }
365
- return $links;
366
- }
367
-
368
-
369
- /**
370
- * Get debug data.
371
- *
372
- * Function to output the debug data for the plugin. This will be useful
373
- * when asking for support. Just copy and paste these data to the email.
374
- *
375
- * Please DO NOT translate this part, as this need to be provided for debugging only.
376
- *
377
- * @since 2.0.0
378
- * @var array $gnrl_options Array of plugin settings
379
- * @var array $active_plugins Array of active plugins path
380
- * @return $html Html content to diplay.
381
- * @author Joel James
382
- */
383
- public function i4t3_get_debug_data() {
384
-
385
- $html = '';
386
- $gnrl_options = get_option('i4t3_gnrl_options');
387
- $active_plugins = get_option ( 'active_plugins', array () );
388
- $active_theme = wp_get_theme();
389
-
390
- // Dump the plugin settings data
391
- if( !empty( $gnrl_options ) ) {
392
- $html .= '<h4>Settings Data</h4>
393
- <p><pre>';
394
- foreach ( $gnrl_options as $key => $option ) {
395
- $html .= $key.' : '.$option.'<br/>';
396
- }
397
- $html .= '</pre></p><hr/>';
398
- }
399
- // Output basic info about the site
400
- $html .= '<h4>Basic Details</h4>
401
- <p>
402
- WordPress Version : '. get_bloginfo('version') .'<br/>
403
- PHP Version : '. PHP_VERSION .'<br/>
404
- Plugin Version : '. $this->version .'<br/>
405
- Home Page : '. home_url() .'<br/>
406
- </p><hr/>';
407
-
408
- if ( $active_theme->exists() ) {
409
-
410
- $html .= '<h4>Active Theme Details</h4>
411
- <p>
412
- Name : '. $active_theme->get( 'Name' ) .'<br/>
413
- Version : '. $active_theme->get( 'Version' ) .'<br/>
414
- Theme URI : '. $active_theme->get( 'ThemeURI' ) .'<br/>
415
- </p><hr/>';
416
- }
417
-
418
- // Dump the active plugins data
419
- if( !empty( $active_plugins ) ) {
420
- $html .= '<h4>Active Plugins</h4>
421
- <p>';
422
- foreach ( $active_plugins as $plugin ) {
423
- $html .= $plugin.'<br/>';
424
- }
425
- $html .= '</p>';
426
- }
427
-
428
- return $html;
429
- }
430
-
431
-
432
- }
1
  <?php
2
  // If this file is called directly, abort.
3
+ if (!defined('WPINC')) {
4
+ die('Damn it.! Dude you are looking for what?');
5
  }
6
+
7
  /**
8
  * The dashboard-specific functionality of the plugin.
9
  *
18
  */
19
  class _404_To_301_Admin {
20
 
21
+ /**
22
+ * The ID of this plugin.
23
+ *
24
+ * @since 2.0.0
25
+ * @access private
26
+ * @var string $plugin_name The ID of this plugin.
27
+ */
28
+ private $plugin_name;
29
+
30
+ /**
31
+ * The version of this plugin.
32
+ *
33
+ * @since 2.0.0
34
+ * @access private
35
+ * @var string $version The current version of this plugin.
36
+ */
37
+ private $version;
38
+
39
+ /**
40
+ * The table name of this plugin.
41
+ *
42
+ * @since 2.0.0
43
+ * @access private
44
+ * @var string $table The table name of this plugin in db.
45
+ */
46
+ private $table;
47
+
48
+ /**
49
+ * The options from db.
50
+ *
51
+ * @since 2.0.0
52
+ * @access private
53
+ * @var string $gnrl_options Get the options saved in db.
54
+ */
55
+ private $gnrl_options;
56
+
57
+ /**
58
+ * The options from db.
59
+ *
60
+ * @since 2.1.0
61
+ * @access private
62
+ * @var mixed $list_table Class object for listing table.
63
+ */
64
+ private $list_table;
65
+
66
+ /**
67
+ * Initialize the class and set its properties.
68
+ *
69
+ * @since 2.0.0
70
+ * @var string $plugin_name The name of this plugin.
71
+ * @var string $version The version of this plugin.
72
+ * @var string $table The name of the database table of this plugin.
73
+ */
74
+ public function __construct($plugin_name, $version, $table) {
75
+
76
+ $this->plugin_name = $plugin_name;
77
+ $this->version = $version;
78
+ $this->table = $table;
79
+ $this->gnrl_options = get_option('i4t3_gnrl_options');
80
+ }
81
+
82
+ /**
83
+ * Register the stylesheet for the Dashboard.
84
+ *
85
+ * This function is used to register all the required stylesheets for
86
+ * dashboard. Styles will be registered only for i4t3 pages for performance.
87
+ *
88
+ * @since 2.0.0
89
+ * @uses wp_enqueue_style To register style
90
+ */
91
+ public function enqueue_styles() {
92
+
93
+ global $pagenow;
94
+
95
+ if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings', 'i4t3-logs')))) {
96
+ wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/min/admin.css', array(), $this->version, 'all');
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Register the scripts for the Dashboard.
102
+ *
103
+ * This function is used to register all the required scripts for
104
+ * dashboard. Scripts will be registered only for i4t3 pages for performance.
105
+ *
106
+ * @since 2.0.0
107
+ * @uses wp_enqueue_script To register script
108
+ */
109
+ public function enqueue_scripts() {
110
+
111
+ global $pagenow;
112
+
113
+ if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings')))) {
114
+ wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/admin.js', array('jquery'), $this->version, false);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Run upgrade functions
120
+ *
121
+ * If 404 to 301 is upgraded, we may need to perform few updations in db
122
+ *
123
+ * @since 2.0.0
124
+ * @uses get_option() To get the activation redirect option from db.
125
+ * @return void.
126
+ */
127
+ public function i4t3_upgrade_if_new() {
128
+
129
+ if (!get_option('i4t3_version_no') || ( get_option('i4t3_version_no') < I4T3_VERSION )) {
130
+ if (class_exists('_404_To_301_Activator')) {
131
+ _404_To_301_Activator::activate();
132
+ }
133
+ update_option('i4t3_version_no', I4T3_VERSION);
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Changing email notification recipient
139
+ *
140
+ * Using filter to change email notification recipient address from
141
+ * default admin email.
142
+ *
143
+ * @since 2.0.7
144
+ * @uses get_option() To get the email address option from db.
145
+ * @return $email Email address to be used for notification.
146
+ */
147
+ public function i4t3_change_notify_email($email) {
148
+ if (!empty($this->gnrl_options['email_notify_address'])) {
149
+ $email_option = $this->gnrl_options['email_notify_address'];
150
+ if (is_email($email_option)) {
151
+ $email = $email_option;
152
+ }
153
+ }
154
+ return $email;
155
+ }
156
+
157
+ /**
158
+ * Creating admin menus for 404 to 301.
159
+ *
160
+ * @since 2.0.0
161
+ * @author Joel James
162
+ * @uses action hook add_submenu_page Action hook to add new admin menu sub page.
163
+ */
164
+ public function i4t3_create_404_to_301_menu() {
165
+
166
+ // Error log menu
167
+ $hook = add_menu_page(
168
+ __('404 Error Logs', '404-to-301'),
169
+ __('404 Error Logs', '404-to-301'),
170
+ I4T3_ADMIN_PERMISSION,
171
+ 'i4t3-logs',
172
+ array($this, 'i4t3_render_list_page'),
173
+ 'dashicons-redo',
174
+ 90
175
+ );
176
+
177
+ add_action("load-$hook", array($this, 'screen_option'));
178
+
179
+ // 404 to 301 settings menu
180
+ add_submenu_page(
181
+ 'i4t3-logs',
182
+ __('404 to 301 Settings', '404-to-301'),
183
+ __('404 Settings', '404-to-301'),
184
+ I4T3_ADMIN_PERMISSION,
185
+ 'i4t3-settings',
186
+ array($this, 'i4t3_admin_page')
187
+ );
188
+
189
+ do_action('i4t3_admin_page');
190
+ }
191
+
192
+ /**
 
 
 
 
 
193
  * To set the screen of the error listing page.
194
  *
195
  * @since 2.1.0
196
  * @author Joel James.
197
  */
198
+ public static function set_screen($status, $option, $value) {
199
+ return $value;
200
+ }
201
+
202
+ /**
203
  * To make screen options for 404 to 301 listing.
204
  *
205
  * This function is used to show screen options like entries per page,
206
+ * show/hide columns etc.
207
  *
208
  * @since 2.1.0
209
  * @author Joel James.
210
  */
211
+ public function screen_option() {
212
+
213
+ $option = 'per_page';
214
+ $args = array(
215
+ 'label' => __('Error Logs', '404-to-301'),
216
+ 'default' => 5,
217
+ 'option' => 'logs_per_page'
218
+ );
219
+
220
+ add_screen_option($option, $args);
221
+
222
+ $this->list_table = new _404_To_301_Logs($this->table);
223
+ }
224
+
225
+ /**
226
+ * Output buffer function
227
+ *
228
+ * To avoid header already sent issue
229
+ * @link https://tommcfarlin.com/wp_redirect-headers-already-sent/
230
+ * @since 2.1.4
231
+ */
232
+ public function add_buffer() {
233
+
234
+ ob_start();
235
+ }
236
+
237
+ /**
238
+ * Creating log table page.
239
+ *
240
+ * @since 2.0.0
241
+ * @author Joel James
242
+ * @uses class _404_To_301_Logs To initialize and load the log listing table.
243
+ */
244
+ public function i4t3_render_list_page() {
245
+ ?>
246
+ <div class="wrap">
247
+ <h2><?php _e('404 Error Logs', '404-to-301'); ?></h2>
248
+
249
+ <div id="poststuff">
250
+ <div id="post-body" class="metabox-holder">
251
+ <div id="post-body-content">
252
+ <div class="meta-box-sortables ui-sortable">
253
+ <form method="post">
254
+ <?php
255
+ $this->list_table->prepare_items();
256
+ $this->list_table->display();
257
+ ?>
258
+ </form>
259
+ </div>
260
+ </div>
261
+ </div>
262
+ <br class="clear">
263
+ </div>
264
+ </div>
265
+ <?php
266
+ }
267
+
268
+ /**
269
+ * Rename admin menu text to : 404 to 301.
270
+ *
271
+ * @since 2.0.0
272
+ * @author Joel James
273
+ * @var global $menu menus registered in this site.
274
+ */
275
+ public function i4t3_rename_plugin_menu() {
276
+ global $menu;
277
+ $menu[90][0] = __('404 to 301', '404-to-301'); // Change menu text
278
+ }
279
+
280
+ /**
281
+ * Admin options page display.
282
+ *
283
+ * Includes admin page contents to manage i4t3 settings.
284
+ * All html parts will be included in this page.
285
+ *
286
+ * @since 2.0.0
287
+ * @author Joel James
288
+ */
289
+ public function i4t3_admin_page() {
290
+
291
+ require plugin_dir_path(__FILE__) . 'partials/404-to-301-admin-display.php';
292
+ }
293
+
294
+ /**
295
+ * Registering i4t3 options.
296
+ * This function is used to register all settings options to the db using
297
+ * WordPress settings API.
298
+ * If we want to register another setting, we can include that here.
299
+ *
300
+ * @since 2.0.0
301
+ * @author Joel James
302
+ * @action hooks register_setting Hook to register i4t3 options in db.
303
+ */
304
+ public function i4t3_options_register() {
305
+
306
+ register_setting(
307
+ 'i4t3_gnrl_options', 'i4t3_gnrl_options'
308
+ );
309
+ }
310
+
311
+ /**
312
+ * Custom footer text for i4t3 pages.
313
+ *
314
+ * Function to alter the default footer text to show i4t3 credits only on i4t3 pages.
315
+ *
316
+ * @since 2.0.0
317
+ * @author Joel James
318
+ */
319
+ function i4t3_dashboard_footer() {
320
+
321
+ global $pagenow;
322
+ if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings', 'i4t3-logs')))) {
323
+
324
+ _e('Thank you for choosing 404 to 301 to improve your website', '404-to-301');
325
+ echo ' | ';
326
+ _e('Kindly give this plugin a', '404-to-301');
327
+ echo '<a href="https://wordpress.org/support/view/plugin-reviews/404-to-301?filter=5#postform">';
328
+ _e('rating', '404-to-301');
329
+ echo ' &#9733; &#9733;</a>';
330
+ } else {
331
+ return;
332
+ }
333
+ }
334
+
335
+ /**
336
+ * Custom Plugin Action Link.
337
+ *
338
+ * Function to add a quick link to i4t3, when being listed on your
339
+ * plugins list view.
340
+ *
341
+ * @since 2.0.0
342
+ * @return $links Links to display.
343
+ * @author Joel James
344
+ */
345
+ public function i4t3_plugin_action_links($links, $file) {
346
+ $plugin_file = basename('404-to-301.php');
347
+ if (basename($file) == $plugin_file) {
348
+ $settings_link = '<a href="admin.php?page=i4t3-settings">' . __('Settings', '404-to-301') . '</a>';
349
+ $settings_link .= ' | <a href="admin.php?page=i4t3-logs">' . __('Logs', '404-to-301') . '</a>';
350
+ array_unshift($links, $settings_link);
351
+ }
352
+ return $links;
353
+ }
354
+
355
+ /**
356
+ * Get debug data.
357
+ *
358
+ * Function to output the debug data for the plugin. This will be useful
359
+ * when asking for support. Just copy and paste these data to the email.
360
+ *
361
+ * Please DO NOT translate this part, as this need to be provided for debugging only.
362
+ *
363
+ * @since 2.0.0
364
+ * @var array $gnrl_options Array of plugin settings
365
+ * @var array $active_plugins Array of active plugins path
366
+ * @return $html Html content to diplay.
367
+ * @author Joel James
368
+ */
369
+ public function i4t3_get_debug_data() {
370
+
371
+ $html = '';
372
+ $gnrl_options = get_option('i4t3_gnrl_options');
373
+ $active_plugins = get_option('active_plugins', array());
374
+ $active_theme = wp_get_theme();
375
+
376
+ // Dump the plugin settings data
377
+ if (!empty($gnrl_options)) {
378
+ $html .= '<h4>' . __('Settings Data', '404-to-301') . '</h4><p><pre>';
379
+ foreach ($gnrl_options as $key => $option) {
380
+ $html .= $key . ' : ' . $option . '<br/>';
381
+ }
382
+ $html .= '</pre></p><hr/>';
383
+ }
384
+ // Output basic info about the site
385
+ $html .= '<h4>' . __('Basic Details', '404-to-301') . '</h4><p>
386
+ ' . __('WordPress Version', '404-to-301') . ' : ' . get_bloginfo('version') . '<br/>
387
+ ' . __('PHP Version', '404-to-301') . ' : ' . PHP_VERSION . '<br/>
388
+ ' . __('Plugin Version', '404-to-301') . ' : ' . $this->version . '<br/>
389
+ ' . __('Home Page', '404-to-301') . ' : ' . home_url() . '<br/></p><hr/>';
390
+
391
+ if ($active_theme->exists()) {
392
+
393
+ $html .= '<h4>' . __('Active Theme Details', '404-to-301') . '</h4><p>
394
+ ' . __('Name', '404-to-301') . ' : ' . $active_theme->get('Name') . '<br/>
395
+ ' . __('Version', '404-to-301') . ' : ' . $active_theme->get('Version') . '<br/>
396
+ ' . __('Theme URI', '404-to-301') . ' : ' . $active_theme->get('ThemeURI') . '<br/></p><hr/>';
397
+ }
398
+
399
+ // Dump the active plugins data
400
+ if (!empty($active_plugins)) {
401
+ $html .= '<h4>' . __('Active Plugins', '404-to-301') . '</h4><p>';
402
+ foreach ($active_plugins as $plugin) {
403
+ $html .= $plugin . '<br/>';
404
+ }
405
+ $html .= '</p>';
406
+ }
407
+
408
+ return $html;
409
+ }
410
+
411
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/class-404-to-301-logs.php CHANGED
@@ -1,7 +1,8 @@
1
  <?php
 
2
  // If this file is called directly, abort.
3
- if ( ! defined( 'WPINC' ) ) {
4
- die('Damn it.! Dude you are looking for what?');
5
  }
6
 
7
  /**
@@ -9,14 +10,14 @@ if ( ! defined( 'WPINC' ) ) {
9
  * Details here - https://codex.wordpress.org/Class_Reference/WP_List_Table
10
  * So we have copied this class and using independently to avoid future issues.
11
  */
12
- if( ! class_exists( 'WP_List_Table_404' ) ) {
13
-
14
- global $wp_version;
15
- if ( $wp_version >= 4.4 ) {
16
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/core/class-wp-list-table-4.4.php';
17
- } else {
18
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/core/class-wp-list-table-old.php';
19
- }
20
  }
21
 
22
  /**
@@ -33,45 +34,43 @@ if( ! class_exists( 'WP_List_Table_404' ) ) {
33
  */
34
  class _404_To_301_Logs extends WP_List_Table_404 {
35
 
36
- /**
37
  * The table name of this plugin.
38
  *
39
  * @since 2.0.0
40
  * @access private
41
- * @author Joel James.
42
  * @var string $table The table name of this plugin in db.
43
  */
44
- private static $table;
45
-
46
- /**
47
  * Initialize the class and set its properties.
48
  *
49
  * @since 2.0.0
50
- * @author Joel James.
51
  * @var string $table The name of the table of plugin.
52
  */
53
- public function __construct( $table ) {
54
 
55
- self::$table = $table;
56
-
57
- parent::__construct( array(
58
- 'singular' => __( '404 Error Log', '404-to-301' ), //singular name of the listed records
59
- 'plural' => __( '404 Error Logs', '404-to-301' ), //plural name of the listed records
60
- 'ajax' => false //does this table support ajax?
61
- )
62
- );
63
-
64
- }
65
 
 
 
 
 
 
 
 
66
 
67
- /**
68
  * Error log data to be displayed.
69
  *
70
  * Getting the error log data from the database and converts it to
71
  * the required structure.
72
- *
73
- * @param int $per_page
74
- * @param int $page_number
75
  *
76
  * @since 2.0.0
77
  * @author Joel James.
@@ -79,30 +78,29 @@ class _404_To_301_Logs extends WP_List_Table_404 {
79
  * @uses apply_filters i4t3_log_list_per_page Custom filter to modify per page view.
80
  * @return mixed $error_data Array of error log data.
81
  */
82
- public static function i4t3_get_log_data( $per_page = 5, $page_number = 1 ) {
83
-
84
- global $wpdb;
85
-
86
- $offset = ( $page_number - 1 ) * $per_page;
87
-
88
- // If no sort, default to title
89
- $orderby = ( isset( $_REQUEST['orderby'] ) ) ? self::i4t3_get_sort_column_filtered( $_REQUEST['orderby'] ) : 'date';
90
-
91
- // If no order, default to asc
92
- $order = ( isset( $_REQUEST['order'] ) && 'desc' == $_REQUEST['order'] ) ? 'DESC' : 'ASC';
93
-
94
- $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ".self::$table." ORDER BY $orderby $order LIMIT %d OFFSET %d", array( $per_page, $offset) ), 'ARRAY_A' );
95
-
96
- return $result;
97
- }
98
-
99
-
100
- /**
101
  * Filter the sorting parameters.
102
  *
103
  * This is used to filter the sorting parameters in order
104
- * to prevent SQL injection atacks. We will accept only our
105
- * required values. Else we will assign a default value.
106
  *
107
  * @since 2.0.3
108
  * @author Joel James.
@@ -110,74 +108,69 @@ class _404_To_301_Logs extends WP_List_Table_404 {
110
  * @var $filtered_column Value aftet filtering.
111
  * @return string $filtered_column.
112
  */
113
- public static function i4t3_get_sort_column_filtered( $column ) {
114
 
115
- $allowed_columns = array( 'date','url','ref','ip' );
116
 
117
- if( in_array( $column, $allowed_columns ) ) {
118
- $filtered_column = esc_sql( $column );
119
  } else {
120
  $filtered_column = 'date';
121
  }
 
122
  return $filtered_column;
123
  }
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
- /**
127
- * Delete a single record from table.
128
- *
129
- * This function is used to clear the selected errors
130
- * from error logs table.
131
- *
132
- * @since 2.1.0
133
- * @author Joel James.
134
- * @param int $id ID
135
- */
136
- public static function delete_error_logs( $id ) {
137
- global $wpdb;
138
-
139
- $wpdb->delete(
140
- self::$table,
141
- array( 'id' => $id ),
142
- array( '%d' )
143
- );
144
- }
145
-
146
-
147
- /**
148
- * Delete all records at once from database.
149
- *
150
- * This function is used to clear the error logs table.
151
- *
152
- * @since 2.1.0
153
- * @author Joel James.
154
- */
155
- public static function delete_error_all_logs() {
156
-
157
- global $wpdb;
158
-
159
- $wpdb->query( "DELETE FROM ".self::$table."" );
160
- }
161
-
162
-
163
- /**
164
  * Get the count of total records in table.
165
  *
166
  * @since 2.1.0
167
- * @author Joel James.
168
  * @return null|string
169
  */
170
- public static function record_count() {
171
-
172
- global $wpdb;
173
-
174
- $sql = "SELECT COUNT(id) FROM ".self::$table;
175
-
176
- return $wpdb->get_var( $sql );
177
- }
178
 
 
179
 
180
- /**
 
 
 
181
  * Empty record text.
182
  *
183
  * Custom text to display where there is nothing to display in error
@@ -187,12 +180,11 @@ class _404_To_301_Logs extends WP_List_Table_404 {
187
  * @author Joel James.
188
  * @return void
189
  */
190
- public function no_items() {
191
- _e( 'Ulta pulta..! Seems like you had no errors to log.', '404-to-301' );
192
- }
193
-
194
 
195
- /**
196
  * Default columns in list table.
197
  *
198
  * To show columns in error log list table. If there is nothing
@@ -202,36 +194,35 @@ class _404_To_301_Logs extends WP_List_Table_404 {
202
  * @author Joel James.
203
  * @uses switch To switch between columns.
204
  */
205
- public function column_default( $item, $column_name ) {
206
- switch ( $column_name ) {
207
- case 'date':
208
  case 'url':
209
  case 'ref':
210
  case 'ip':
211
  case 'ua':
212
- return $item[ $column_name ];
213
- default:
214
- return print_r( $item, true ); //Show the whole array for troubleshooting purposes
215
- }
216
- }
217
 
218
- /**
219
  * To output checkbox for bulk actions.
220
  *
221
  * This function is used to add new checkbox for all entries in
222
- * the listing table. We use this checkbox to perform bulk actions.
223
  *
224
  * @since 2.1.0
225
  * @author Joel James.
226
  * @return string Checkbox.
227
  */
228
- function column_cb( $item ) {
229
-
230
- return sprintf( '<input type="checkbox" name="bulk-delete[]" value="%s"/>', $item['id'] );
231
- }
232
 
 
 
233
 
234
- /**
235
  * To modify the date column data
236
  *
237
  * This function is used to modify the column data for date in listing table.
@@ -241,21 +232,20 @@ class _404_To_301_Logs extends WP_List_Table_404 {
241
  * @author Joel James.
242
  * @return string $date_data Date column text data.
243
  */
244
- function column_date( $item ) {
245
-
246
- $delete_nonce = wp_create_nonce( 'i4t3_delete_log' );
247
-
248
- $title = apply_filters( 'i4t3_log_list_date_column', date("j M Y, g:i a", strtotime($item['date'])) );
249
- $confirm = __( 'Are you sure you want to delete this item?', '404-to-301' );
250
- $actions = array(
251
- 'delete' => sprintf( '<a href="?page=%s&action=%s&log=%s&_wpnonce=%s" onclick="return confirm(\'%s\');">'. __( 'Delete', '404-to-301' ) .'</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['id'] ), $delete_nonce, $confirm )
252
- );
253
-
254
- return $title . $this->row_actions( $actions );
255
- }
256
-
257
-
258
- /**
259
  * To modify the url column data
260
  *
261
  * This function is used to modify the column data for url in listing table.
@@ -265,16 +255,15 @@ class _404_To_301_Logs extends WP_List_Table_404 {
265
  * @author Joel James.
266
  * @return string $url_data Url column text data.
267
  */
268
- public function column_url( $item ) {
269
 
270
  // Apply filter - i4t3_log_list_url_column
271
- $url_data = apply_filters( 'i4t3_log_list_url_column', $this->get_empty_text( '<p class="i4t3-url-p">'.$item['url'].'</p>', $item['url'] ) );
272
 
273
  return $url_data;
274
  }
275
-
276
-
277
- /**
278
  * To modify the ref column data
279
  *
280
  * This function is used to modify the column data for ref in listing table.
@@ -284,16 +273,15 @@ class _404_To_301_Logs extends WP_List_Table_404 {
284
  * @author Joel James.
285
  * @return string $ref_data Ref column text data.
286
  */
287
- public function column_ref( $item ) {
288
 
289
  // Apply filter - i4t3_log_list_ref_column
290
- $ref_data = apply_filters( 'i4t3_log_list_ref_column', $this->get_empty_text( '<a href="'.$item['ref'].'">'.$item['ref'].'</a>', $item['ref'] ) );
291
 
292
  return $ref_data;
293
  }
294
-
295
-
296
- /**
297
  * To modify the user agent column data
298
  *
299
  * This function is used to modify the column data for user agent in listing table.
@@ -303,16 +291,15 @@ class _404_To_301_Logs extends WP_List_Table_404 {
303
  * @author Joel James.
304
  * @return string $ua_data Ref column text data.
305
  */
306
- public function column_ua( $item ) {
307
 
308
  // Apply filter - i4t3_log_list_ref_column
309
- $ua_data = apply_filters( 'i4t3_log_list_ua_column', $this->get_empty_text( $item['ua'], $item['ua'] ) );
310
 
311
  return $ua_data;
312
  }
313
-
314
-
315
- /**
316
  * To modify the ip column data
317
  *
318
  * This function is used to modify the column data for ip in listing table.
@@ -322,16 +309,15 @@ class _404_To_301_Logs extends WP_List_Table_404 {
322
  * @author Joel James.
323
  * @return string $ip Ref column text data.
324
  */
325
- public function column_ip( $item ) {
326
 
327
  // Apply filter - i4t3_log_list_ref_column
328
- $ip = apply_filters( 'i4t3_log_list_ip_column', $this->get_empty_text( $item['ip'], $item['ip'] ) );
329
 
330
  return $ip;
331
  }
332
 
333
-
334
- /**
335
  * Column titles
336
  *
337
  * Custom column titles to be displayed in listing table. You can change this to anything
@@ -340,22 +326,21 @@ class _404_To_301_Logs extends WP_List_Table_404 {
340
  * @author Joel James.
341
  * @return array $columns Array of cloumn titles.
342
  */
343
- function get_columns() {
344
-
345
- $columns = array(
346
- 'cb' => '<input type="checkbox" style="width: 5%;" />',
347
- 'date'=> __( 'Date and Time', '404-to-301' ),
348
- 'url' => __( '404 Path', '404-to-301' ),
349
- 'ref' => __( 'Came From', '404-to-301' ), // referer
350
- 'ip' => __( 'IP Address', '404-to-301' ),
351
- 'ua' => __( 'User Agent', '404-to-301' )
352
- );
353
-
354
- return $columns;
355
- }
356
-
357
-
358
- /**
359
  * Make columns sortable
360
  *
361
  * To make our custom columns in list table sortable. We have included
@@ -365,41 +350,40 @@ class _404_To_301_Logs extends WP_List_Table_404 {
365
  * @author Joel James.
366
  * @return array $sortable_columns Array of columns to enable sorting.
367
  */
368
- public function get_sortable_columns() {
369
-
370
- $sortable_columns = array(
371
- 'date' => array( 'date', true ),
372
- 'url' => array('url',false),
373
- 'ref' => array('ref',false),
374
- 'ip' => array('ip',false)
375
- );
376
-
377
- return $sortable_columns;
378
- }
379
-
380
- /**
381
  * Bulk actions drop down
382
  *
383
  * Options to be added to the bulk actions drop down for users
384
  * to select. We have added 'Delete' actions.
385
  *
386
  * @since 2.0.0
387
- * @modified 2.1.0
388
  * @author Joel James.
389
  * @return array $actions Options to be added to the action select box.
390
  */
391
- public function get_bulk_actions() {
392
-
393
- $actions = array(
394
- 'bulk-delete' => __('Delete Selected', '404-to-301' ),
395
- 'bulk-all-delete' => __( 'Delete All', '404-to-301' )
396
- );
397
-
398
- return $actions;
399
- }
400
-
401
-
402
- /**
403
  * Main function to output the listing table using WP_List_Table class
404
  *
405
  * As name says, this function is used to prepare the lsting table based
@@ -414,27 +398,26 @@ class _404_To_301_Logs extends WP_List_Table_404 {
414
  * @uses $wpdb The global variable for WordPress database operations.
415
  * @uses hide_errors() To hide if there are SQL query errors.
416
  */
417
- public function prepare_items() {
418
 
419
- $this->_column_headers = $this->get_column_info();
420
 
421
- /** Process bulk action */
422
- $this->process_bulk_action();
423
 
424
- $per_page = $this->get_items_per_page( 'logs_per_page', 5 );
425
- $current_page = $this->get_pagenum();
426
- $total_items = self::record_count();
427
 
428
- $this->set_pagination_args( array(
429
- 'total_items' => $total_items, //WE have to calculate the total number of items
430
- 'per_page' => $per_page //WE have to determine how many items to show on a page
431
- ) );
432
 
433
- $this->items = self::i4t3_get_log_data( $per_page, $current_page );
434
- }
435
-
436
-
437
- /**
438
  * To perform bulk actions.
439
  *
440
  * This function is used to check if bulk action is set in post.
@@ -444,101 +427,95 @@ class _404_To_301_Logs extends WP_List_Table_404 {
444
  * @author Joel James.
445
  * @uses wp_verify_nonce To verify if the request is from WordPress.
446
  */
447
- public function process_bulk_action() {
448
-
449
- //Detect when a bulk action is being triggered...
450
- if ( 'delete' === $this->current_action() ) {
451
-
452
- // In our file that handles the request, verify the nonce.
453
- $nonce = esc_attr( $_REQUEST['_wpnonce'] );
454
-
455
- if ( ! wp_verify_nonce( $nonce, 'i4t3_delete_log' ) ) {
456
- wp_die( 'Go get a life script kiddies' );
457
- } else {
458
-
459
- self::delete_error_logs( absint( $_GET['log'] ) );
460
- wp_redirect( esc_url( add_query_arg() ) );
461
- exit;
462
- }
463
-
464
- }
465
-
466
- $this->bulk_delete_actions();
467
- }
468
-
469
-
470
- /**
471
  * To perform bulk delete actions.
472
  *
473
  * This function is used to perform the bulk delete
474
- * actions. Selected data delete and whole data delete
475
- * is being performed here.
476
  *
477
  * @since 2.1.0
478
  * @author Joel James.
479
  * @uses wp_verify_nonce To verify if the request is from WordPress.
480
  */
481
- public function bulk_delete_actions() {
482
-
483
- if( isset($_POST['_wpnonce'])) {
484
 
485
- $nonce = '';
 
 
486
  $action = '';
487
  // security check!
488
- if ( ! empty( $_POST['_wpnonce'] ) ) {
489
 
490
- $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
491
  $action = 'bulk-' . $this->_args['plural'];
492
  }
493
 
494
- if ( ! wp_verify_nonce( $nonce, $action ) ) {
495
- wp_die( 'Go get a life script kiddies' );
496
- }
497
-
498
- // If the delete bulk action is triggered
499
- else if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
500
- || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' ) ) {
501
-
502
- $delete_ids = esc_sql( $_POST['bulk-delete'] );
503
-
504
- // loop over the array of record IDs and delete them
505
- foreach ( $delete_ids as $id ) {
506
- self::delete_error_logs( $id );
507
-
508
- }
509
-
510
- wp_redirect( esc_url( add_query_arg() ) );
511
- exit;
512
- }
513
-
514
- // If the delete all bulk action is triggered
515
- else if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-all-delete' )
516
- || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-all-delete' ) ) {
517
-
518
- self::delete_error_all_logs();
519
- wp_redirect( esc_url( add_query_arg() ) );
520
- exit;
521
- }
522
- }
523
- }
524
-
525
-
526
- /**
527
  * To make clear error text if value is N/A.
528
  *
529
  * This function is used to show the N/A text in red colour if the field value
530
- * is not available.
531
  *
532
  * @since 2.1.0
533
  * @author Joel James.
534
  */
535
- public function get_empty_text( $data, $na = 'N/A' ) {
536
-
537
- if( $na == 'N/A' ) {
538
- return '<p class="i4t3-url-p">'. __( 'N/A', '404-to-301' ) .'</p>';
539
- }
540
-
541
- return $data;
542
- }
543
-
544
- }
1
  <?php
2
+
3
  // If this file is called directly, abort.
4
+ if (!defined('WPINC')) {
5
+ die('Damn it.! Dude you are looking for what?');
6
  }
7
 
8
  /**
10
  * Details here - https://codex.wordpress.org/Class_Reference/WP_List_Table
11
  * So we have copied this class and using independently to avoid future issues.
12
  */
13
+ if (!class_exists('WP_List_Table_404')) {
14
+
15
+ global $wp_version;
16
+ if ($wp_version >= 4.4) {
17
+ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/core/class-wp-list-table-4.4.php';
18
+ } else {
19
+ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/core/class-wp-list-table-old.php';
20
+ }
21
  }
22
 
23
  /**
34
  */
35
  class _404_To_301_Logs extends WP_List_Table_404 {
36
 
37
+ /**
38
  * The table name of this plugin.
39
  *
40
  * @since 2.0.0
41
  * @access private
42
+ * @author Joel James.
43
  * @var string $table The table name of this plugin in db.
44
  */
45
+ private static $table;
46
+
47
+ /**
48
  * Initialize the class and set its properties.
49
  *
50
  * @since 2.0.0
51
+ * @author Joel James.
52
  * @var string $table The name of the table of plugin.
53
  */
54
+ public function __construct($table) {
55
 
56
+ self::$table = $table;
 
 
 
 
 
 
 
 
 
57
 
58
+ parent::__construct(array(
59
+ 'singular' => __('404 Error Log', '404-to-301'), //singular name of the listed records
60
+ 'plural' => __('404 Error Logs', '404-to-301'), //plural name of the listed records
61
+ 'ajax' => false //does this table support ajax?
62
+ )
63
+ );
64
+ }
65
 
66
+ /**
67
  * Error log data to be displayed.
68
  *
69
  * Getting the error log data from the database and converts it to
70
  * the required structure.
71
+ *
72
+ * @param int $per_page
73
+ * @param int $page_number
74
  *
75
  * @since 2.0.0
76
  * @author Joel James.
78
  * @uses apply_filters i4t3_log_list_per_page Custom filter to modify per page view.
79
  * @return mixed $error_data Array of error log data.
80
  */
81
+ public static function i4t3_get_log_data($per_page = 5, $page_number = 1) {
82
+
83
+ global $wpdb;
84
+
85
+ $offset = ( $page_number - 1 ) * $per_page;
86
+
87
+ // If no sort, default to title
88
+ $orderby = ( isset($_REQUEST['orderby']) ) ? self::i4t3_get_sort_column_filtered($_REQUEST['orderby']) : 'date';
89
+
90
+ // If no order, default to asc
91
+ $order = ( isset($_REQUEST['order']) && 'desc' == $_REQUEST['order'] ) ? 'DESC' : 'ASC';
92
+
93
+ $result = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . self::$table . " ORDER BY $orderby $order LIMIT %d OFFSET %d", array($per_page, $offset)), 'ARRAY_A');
94
+
95
+ return $result;
96
+ }
97
+
98
+ /**
 
99
  * Filter the sorting parameters.
100
  *
101
  * This is used to filter the sorting parameters in order
102
+ * to prevent SQL injection atacks. We will accept only our
103
+ * required values. Else we will assign a default value.
104
  *
105
  * @since 2.0.3
106
  * @author Joel James.
108
  * @var $filtered_column Value aftet filtering.
109
  * @return string $filtered_column.
110
  */
111
+ public static function i4t3_get_sort_column_filtered($column) {
112
 
113
+ $allowed_columns = array('date', 'url', 'ref', 'ip');
114
 
115
+ if (in_array($column, $allowed_columns)) {
116
+ $filtered_column = esc_sql($column);
117
  } else {
118
  $filtered_column = 'date';
119
  }
120
+
121
  return $filtered_column;
122
  }
123
 
124
+ /**
125
+ * Delete a single record from table.
126
+ *
127
+ * This function is used to clear the selected errors
128
+ * from error logs table.
129
+ *
130
+ * @since 2.1.0
131
+ * @author Joel James.
132
+ * @param int $id ID
133
+ */
134
+ public static function delete_error_logs($id) {
135
+ global $wpdb;
136
+
137
+ $wpdb->delete(
138
+ self::$table, array('id' => $id), array('%d')
139
+ );
140
+ }
141
+
142
+ /**
143
+ * Delete all records at once from database.
144
+ *
145
+ * This function is used to clear the error logs table.
146
+ *
147
+ * @since 2.1.0
148
+ * @author Joel James.
149
+ */
150
+ public static function delete_error_all_logs() {
151
+
152
+ global $wpdb;
153
+
154
+ $wpdb->query("DELETE FROM " . self::$table . "");
155
+ }
156
 
157
+ /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  * Get the count of total records in table.
159
  *
160
  * @since 2.1.0
161
+ * @author Joel James.
162
  * @return null|string
163
  */
164
+ public static function record_count() {
165
+
166
+ global $wpdb;
 
 
 
 
 
167
 
168
+ $sql = "SELECT COUNT(id) FROM " . self::$table;
169
 
170
+ return $wpdb->get_var($sql);
171
+ }
172
+
173
+ /**
174
  * Empty record text.
175
  *
176
  * Custom text to display where there is nothing to display in error
180
  * @author Joel James.
181
  * @return void
182
  */
183
+ public function no_items() {
184
+ _e('Ulta pulta..! Seems like you had no errors to log.', '404-to-301');
185
+ }
 
186
 
187
+ /**
188
  * Default columns in list table.
189
  *
190
  * To show columns in error log list table. If there is nothing
194
  * @author Joel James.
195
  * @uses switch To switch between columns.
196
  */
197
+ public function column_default($item, $column_name) {
198
+ switch ($column_name) {
199
+ case 'date':
200
  case 'url':
201
  case 'ref':
202
  case 'ip':
203
  case 'ua':
204
+ return $item[$column_name];
205
+ default:
206
+ return print_r($item, true); //Show the whole array for troubleshooting purposes
207
+ }
208
+ }
209
 
210
+ /**
211
  * To output checkbox for bulk actions.
212
  *
213
  * This function is used to add new checkbox for all entries in
214
+ * the listing table. We use this checkbox to perform bulk actions.
215
  *
216
  * @since 2.1.0
217
  * @author Joel James.
218
  * @return string Checkbox.
219
  */
220
+ function column_cb($item) {
 
 
 
221
 
222
+ return sprintf('<input type="checkbox" name="bulk-delete[]" value="%s"/>', $item['id']);
223
+ }
224
 
225
+ /**
226
  * To modify the date column data
227
  *
228
  * This function is used to modify the column data for date in listing table.
232
  * @author Joel James.
233
  * @return string $date_data Date column text data.
234
  */
235
+ function column_date($item) {
236
+
237
+ $delete_nonce = wp_create_nonce('i4t3_delete_log');
238
+
239
+ $title = apply_filters('i4t3_log_list_date_column', date("j M Y, g:i a", strtotime($item['date'])));
240
+ $confirm = __('Are you sure you want to delete this item?', '404-to-301');
241
+ $actions = array(
242
+ 'delete' => sprintf('<a href="?page=%s&action=%s&log=%s&_wpnonce=%s" onclick="return confirm(\'%s\');">' . __('Delete', '404-to-301') . '</a>', esc_attr($_REQUEST['page']), 'delete', absint($item['id']), $delete_nonce, $confirm)
243
+ );
244
+
245
+ return $title . $this->row_actions($actions);
246
+ }
247
+
248
+ /**
 
249
  * To modify the url column data
250
  *
251
  * This function is used to modify the column data for url in listing table.
255
  * @author Joel James.
256
  * @return string $url_data Url column text data.
257
  */
258
+ public function column_url($item) {
259
 
260
  // Apply filter - i4t3_log_list_url_column
261
+ $url_data = apply_filters('i4t3_log_list_url_column', $this->get_empty_text('<p class="i4t3-url-p">' . $item['url'] . '</p>', $item['url']));
262
 
263
  return $url_data;
264
  }
265
+
266
+ /**
 
267
  * To modify the ref column data
268
  *
269
  * This function is used to modify the column data for ref in listing table.
273
  * @author Joel James.
274
  * @return string $ref_data Ref column text data.
275
  */
276
+ public function column_ref($item) {
277
 
278
  // Apply filter - i4t3_log_list_ref_column
279
+ $ref_data = apply_filters('i4t3_log_list_ref_column', $this->get_empty_text('<a href="' . $item['ref'] . '">' . $item['ref'] . '</a>', $item['ref']));
280
 
281
  return $ref_data;
282
  }
283
+
284
+ /**
 
285
  * To modify the user agent column data
286
  *
287
  * This function is used to modify the column data for user agent in listing table.
291
  * @author Joel James.
292
  * @return string $ua_data Ref column text data.
293
  */
294
+ public function column_ua($item) {
295
 
296
  // Apply filter - i4t3_log_list_ref_column
297
+ $ua_data = apply_filters('i4t3_log_list_ua_column', $this->get_empty_text($item['ua'], $item['ua']));
298
 
299
  return $ua_data;
300
  }
301
+
302
+ /**
 
303
  * To modify the ip column data
304
  *
305
  * This function is used to modify the column data for ip in listing table.
309
  * @author Joel James.
310
  * @return string $ip Ref column text data.
311
  */
312
+ public function column_ip($item) {
313
 
314
  // Apply filter - i4t3_log_list_ref_column
315
+ $ip = apply_filters('i4t3_log_list_ip_column', $this->get_empty_text($item['ip'], $item['ip']));
316
 
317
  return $ip;
318
  }
319
 
320
+ /**
 
321
  * Column titles
322
  *
323
  * Custom column titles to be displayed in listing table. You can change this to anything
326
  * @author Joel James.
327
  * @return array $columns Array of cloumn titles.
328
  */
329
+ function get_columns() {
330
+
331
+ $columns = array(
332
+ 'cb' => '<input type="checkbox" style="width: 5%;" />',
333
+ 'date' => __('Date and Time', '404-to-301'),
334
+ 'url' => __('404 Path', '404-to-301'),
335
+ 'ref' => __('Came From', '404-to-301'), // referer
336
+ 'ip' => __('IP Address', '404-to-301'),
337
+ 'ua' => __('User Agent', '404-to-301')
338
+ );
339
+
340
+ return $columns;
341
+ }
342
+
343
+ /**
 
344
  * Make columns sortable
345
  *
346
  * To make our custom columns in list table sortable. We have included
350
  * @author Joel James.
351
  * @return array $sortable_columns Array of columns to enable sorting.
352
  */
353
+ public function get_sortable_columns() {
354
+
355
+ $sortable_columns = array(
356
+ 'date' => array('date', true),
357
+ 'url' => array('url', false),
358
+ 'ref' => array('ref', false),
359
+ 'ip' => array('ip', false)
360
+ );
361
+
362
+ return $sortable_columns;
363
+ }
364
+
365
+ /**
366
  * Bulk actions drop down
367
  *
368
  * Options to be added to the bulk actions drop down for users
369
  * to select. We have added 'Delete' actions.
370
  *
371
  * @since 2.0.0
372
+ * @modified 2.1.0
373
  * @author Joel James.
374
  * @return array $actions Options to be added to the action select box.
375
  */
376
+ public function get_bulk_actions() {
377
+
378
+ $actions = array(
379
+ 'bulk-delete' => __('Delete Selected', '404-to-301'),
380
+ 'bulk-all-delete' => __('Delete All', '404-to-301')
381
+ );
382
+
383
+ return $actions;
384
+ }
385
+
386
+ /**
 
387
  * Main function to output the listing table using WP_List_Table class
388
  *
389
  * As name says, this function is used to prepare the lsting table based
398
  * @uses $wpdb The global variable for WordPress database operations.
399
  * @uses hide_errors() To hide if there are SQL query errors.
400
  */
401
+ public function prepare_items() {
402
 
403
+ $this->_column_headers = $this->get_column_info();
404
 
405
+ /** Process bulk action */
406
+ $this->process_bulk_action();
407
 
408
+ $per_page = $this->get_items_per_page('logs_per_page', 5);
409
+ $current_page = $this->get_pagenum();
410
+ $total_items = self::record_count();
411
 
412
+ $this->set_pagination_args(array(
413
+ 'total_items' => $total_items, //WE have to calculate the total number of items
414
+ 'per_page' => $per_page //WE have to determine how many items to show on a page
415
+ ));
416
 
417
+ $this->items = self::i4t3_get_log_data($per_page, $current_page);
418
+ }
419
+
420
+ /**
 
421
  * To perform bulk actions.
422
  *
423
  * This function is used to check if bulk action is set in post.
427
  * @author Joel James.
428
  * @uses wp_verify_nonce To verify if the request is from WordPress.
429
  */
430
+ public function process_bulk_action() {
431
+
432
+ //Detect when a bulk action is being triggered...
433
+ if ('delete' === $this->current_action()) {
434
+
435
+ // In our file that handles the request, verify the nonce.
436
+ $nonce = esc_attr($_REQUEST['_wpnonce']);
437
+
438
+ if (!wp_verify_nonce($nonce, 'i4t3_delete_log')) {
439
+ wp_die('Go get a life script kiddies');
440
+ } else {
441
+
442
+ self::delete_error_logs(absint($_GET['log']));
443
+ wp_redirect(esc_url(add_query_arg()));
444
+ exit;
445
+ }
446
+ }
447
+
448
+ $this->bulk_delete_actions();
449
+ }
450
+
451
+ /**
 
 
452
  * To perform bulk delete actions.
453
  *
454
  * This function is used to perform the bulk delete
455
+ * actions. Selected data delete and whole data delete
456
+ * is being performed here.
457
  *
458
  * @since 2.1.0
459
  * @author Joel James.
460
  * @uses wp_verify_nonce To verify if the request is from WordPress.
461
  */
462
+ public function bulk_delete_actions() {
 
 
463
 
464
+ if (isset($_POST['_wpnonce'])) {
465
+
466
+ $nonce = '';
467
  $action = '';
468
  // security check!
469
+ if (!empty($_POST['_wpnonce'])) {
470
 
471
+ $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING);
472
  $action = 'bulk-' . $this->_args['plural'];
473
  }
474
 
475
+ if (!wp_verify_nonce($nonce, $action)) {
476
+ wp_die('Go get a life script kiddies');
477
+ }
478
+
479
+ // If the delete bulk action is triggered
480
+ else if (( isset($_POST['action']) && $_POST['action'] == 'bulk-delete' ) || ( isset($_POST['action2']) && $_POST['action2'] == 'bulk-delete' )) {
481
+
482
+ $delete_ids = esc_sql($_POST['bulk-delete']);
483
+
484
+ // loop over the array of record IDs and delete them
485
+ foreach ($delete_ids as $id) {
486
+ self::delete_error_logs($id);
487
+ }
488
+
489
+ wp_redirect(esc_url(add_query_arg()));
490
+ exit;
491
+ }
492
+
493
+ // If the delete all bulk action is triggered
494
+ else if (( isset($_POST['action']) && $_POST['action'] == 'bulk-all-delete' ) || ( isset($_POST['action2']) && $_POST['action2'] == 'bulk-all-delete' )) {
495
+
496
+ self::delete_error_all_logs();
497
+ wp_redirect(esc_url(add_query_arg()));
498
+ exit;
499
+ }
500
+ }
501
+ }
502
+
503
+ /**
 
 
 
 
504
  * To make clear error text if value is N/A.
505
  *
506
  * This function is used to show the N/A text in red colour if the field value
507
+ * is not available.
508
  *
509
  * @since 2.1.0
510
  * @author Joel James.
511
  */
512
+ public function get_empty_text($data, $na = 'N/A') {
513
+
514
+ if ($na == 'N/A') {
515
+ return '<p class="i4t3-url-p">' . __('N/A', '404-to-301') . '</p>';
516
+ }
517
+
518
+ return $data;
519
+ }
520
+
521
+ }
admin/partials/404-to-301-admin-credits-tab.php CHANGED
@@ -1,92 +1,92 @@
1
  <div class="wrap">
2
- <br>
3
- <div id="poststuff">
4
- <div id="post-body" class="metabox-holder columns-2">
5
- <div id="post-body-content">
6
- <div class="postbox">
7
- <h3 class="hndle"><span><?php _e( 'About the plugin & developer', '404-to-301' ); ?></span></h3>
8
- <div class="inside">
9
- <div class="c4p-clearfix">
10
- <div class="c4p-left">
11
- <img src="<?php echo I4T3_PATH . 'admin/images/coder.png'; ?>" class="c4p-author-image" />
12
- </div>
13
- <div class="c4p-left" style="width: 70%">
14
- <?php $uname = ( $current_user->user_firstname == '' ) ? $current_user->user_login : $current_user->user_firstname; ?>
15
- <p>Yo <strong><?php echo $uname; ?></strong>! <?php _e( 'Thank you for using 404 to 301', '404-to-301' ); ?></p>
16
- <p>
17
- <?php _e( 'This plugin is brought to you by', '404-to-301' ); ?> <a href="http://iscode.co/" class="i4t3-author-link" target="_blank" title="<?php _e( 'Visit author website', '404-to-301' ); ?>"><strong>is_code()</strong></a>, <?php _e( 'a web store developed and managed by Joel James.', '404-to-301' ); ?>
18
- </p>
19
- <p>
20
- <hr/>
21
- </p>
22
- <p>
23
- <?php _e( 'So you installed this plugin and how is it doing? Feel free to', '404-to-301' ); ?> <a href="http://iscode.co/support/" class="i4t3-author-link" target="_blank" title="<?php _e( 'Contact the developer', '404-to-301' ); ?>"><?php _e( 'get in touch with me', '404-to-301' ); ?></a> <?php _e( 'anytime for help. I am always happy to help.', '404-to-301' ); ?>
24
- </p>
25
- </div>
26
- </div>
27
- </div>
28
- </div>
29
- <div class="postbox">
30
- <h3 class="hndle"><span><?php _e( 'Debugging Data', '404-to-301' ); ?></span></h3>
31
- <div class="inside">
32
- <div class="c4p-clearfix">
33
- <div class="c4p-left" style="width: 70%">
34
- <?php echo _404_To_301_Admin::i4t3_get_debug_data(); ?>
35
- </div>
36
- </div>
37
- </div>
38
- </div>
39
- </div>
40
- <div id="postbox-container-1" class="postbox-container">
41
-
42
- <div class="postbox">
43
- <h3 class="hndle ui-sortable-handle"><span class="dashicons dashicons-info"></span> <?php _e( 'Plugin Information', '404-to-301' ); ?></h3>
44
- <div class="inside">
45
- <div class="misc-pub-section">
46
- <label><?php _e( 'Name', '404-to-301' ); ?> : </label>
47
- <span><strong><?php _e( '404 to 301', '404-to-301' ); ?></strong></span>
48
- </div>
49
- <div class="misc-pub-section">
50
- <label><?php _e( 'Version', '404-to-301' ); ?> : v<?php echo $this->version; ?></label>
51
- <span></span>
52
- </div>
53
- <div class="misc-pub-section">
54
- <label><?php _e( 'Author', '404-to-301' ); ?> : <a href="http://iscode.co/" class="i4t3-author-link" target="_blank" title="<?php _e( 'Visit author website', '404-to-301' ); ?>">is_code()</a></label>
55
- <span></span>
56
- </div>
57
- <div class="misc-pub-section">
58
- <label><a href="http://iscode.co/docs/category/404-to-301/" class="i4t3-author-link" target="_blank" title="<?php _e( 'Visit plugin website','404-to-301' ); ?>"><strong><?php _e( 'Plugin documentation','404-to-301' ); ?></strong></a></label>
59
- <span></span>
60
- </div>
61
- <div class="misc-pub-section">
62
- <label><a href="http://iscode.co/docs/category/404-to-301/" class="i4t3-author-link" target="_blank" title="<?php _e( 'Visit plugin website','404-to-301' ); ?>"><strong><?php _e( 'More plugin details','404-to-301' ); ?></strong></a></label>
63
- <span></span>
64
- </div>
65
- <div class="misc-pub-section">
66
- <label><?php _e( 'Need help?','404-to-301' ); ?></label>
67
- <span><strong><a href="http://iscode.co/support/"><?php _e( 'contact support','404-to-301' ); ?></a></strong></span>
68
- </div>
69
- </div>
70
- </div>
71
- <div class="postbox">
72
- <h3 class="hndle ui-sortable-handle"><span class="dashicons dashicons-smiley"></span> <?php _e( 'Like the plugin','404-to-301' ); ?>?</h3>
73
- <div class="inside">
74
- <div class="misc-pub-section">
75
- <span class="dashicons dashicons-star-filled"></span> <label><strong><a href="https://wordpress.org/support/view/plugin-reviews/404-to-301?filter=5#postform" target="_blank" title="<?php _e( 'Rate now','404-to-301' ); ?>"><?php _e( 'Rate this on WordPress','404-to-301' ); ?></a></strong></label>
76
- </div>
77
- <div class="misc-pub-section">
78
- <label><span class="dashicons dashicons-heart"></span> <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4" target="_blank" title="<?php _e( 'Donate now','404-to-301' ); ?>"><?php _e( 'Make a small donation','404-to-301' ); ?></a></strong></label>
79
- </div>
80
- <div class="misc-pub-section">
81
- <label><span class="dashicons dashicons-admin-plugins"></span> <strong><a href="https://github.com/joel-james/404-to-301/" target="_blank" title="<?php _e( 'Contribute now','404-to-301' ); ?>"><?php _e( 'Contribute to the Plugin','404-to-301' ); ?></a></strong></label>
82
- </div>
83
- <div class="misc-pub-section">
84
- <label><span class="dashicons dashicons-twitter"></span> <strong><a href="https://twitter.com/home?status=I%20am%20using%20404%20to%20301%20plugin%20by%20%40Joel_James%20to%20handle%20all%20404%20errors%20in%20my%20%40WordPress%20site%20-%20it%20is%20awesome!%20%3E%20https://wordpress.org/plugins/404-to-301/" target="_blank" title="<?php _e( 'Tweet now','404-to-301' ); ?>"><?php _e( 'Tweet about the Plugin','404-to-301' ); ?></a></strong></label>
85
- </div>
86
- </div>
87
- </div>
88
 
89
- </div>
90
- </div>
91
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  </div>
1
  <div class="wrap">
2
+ <br>
3
+ <div id="poststuff">
4
+ <div id="post-body" class="metabox-holder columns-2">
5
+ <div id="post-body-content">
6
+ <div class="postbox">
7
+ <h3 class="hndle"><span><?php _e('About the plugin & developer', '404-to-301'); ?></span></h3>
8
+ <div class="inside">
9
+ <div class="c4p-clearfix">
10
+ <div class="c4p-left">
11
+ <img src="<?php echo I4T3_PATH . 'admin/images/coder.png'; ?>" class="c4p-author-image" />
12
+ </div>
13
+ <div class="c4p-left" style="width: 70%">
14
+ <?php $uname = ( $current_user->user_firstname == '' ) ? $current_user->user_login : $current_user->user_firstname; ?>
15
+ <p><?php printf(__('Yo %s!', '404-to-301'), '<strong>' . $uname . '</strong>'); ?> <?php _e('Thank you for using 404 to 301', '404-to-301'); ?></p>
16
+ <p>
17
+ <?php _e('This plugin is brought to you by', '404-to-301'); ?> <a href="https://iscode.co/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit author website', '404-to-301'); ?>"><strong>is_code()</strong></a>, <?php _e('a web store developed and managed by Joel James.', '404-to-301'); ?>
18
+ </p>
19
+ <p>
20
+ <hr/>
21
+ </p>
22
+ <p>
23
+ <?php _e('So you installed this plugin and how is it doing? Feel free to', '404-to-301'); ?> <a href="https://iscode.co/contact/" class="i4t3-author-link" target="_blank" title="<?php _e('Contact the developer', '404-to-301'); ?>"><?php _e('get in touch with me', '404-to-301'); ?></a> <?php _e('anytime for help. I am always happy to help.', '404-to-301'); ?>
24
+ </p>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ <div class="postbox">
30
+ <h3 class="hndle"><span><?php _e('Debugging Data', '404-to-301'); ?></span></h3>
31
+ <div class="inside">
32
+ <div class="c4p-clearfix">
33
+ <div class="c4p-left" style="width: 70%">
34
+ <?php echo _404_To_301_Admin::i4t3_get_debug_data(); ?>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ <div id="postbox-container-1" class="postbox-container">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ <div class="postbox">
43
+ <h3 class="hndle ui-sortable-handle"><span class="dashicons dashicons-info"></span> <?php _e('Plugin Information', '404-to-301'); ?></h3>
44
+ <div class="inside">
45
+ <div class="misc-pub-section">
46
+ <label><?php _e('Name', '404-to-301'); ?> : </label>
47
+ <span><strong><?php _e('404 to 301', '404-to-301'); ?></strong></span>
48
+ </div>
49
+ <div class="misc-pub-section">
50
+ <label><?php _e('Version', '404-to-301'); ?> : v<?php echo $this->version; ?></label>
51
+ <span></span>
52
+ </div>
53
+ <div class="misc-pub-section">
54
+ <label><?php _e('Author', '404-to-301'); ?> : <a href="https://iscode.co/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit author website', '404-to-301'); ?>">is_code()</a></label>
55
+ <span></span>
56
+ </div>
57
+ <div class="misc-pub-section">
58
+ <label><a href="https://iscode.co/docs/category/404-to-301/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit plugin website', '404-to-301'); ?>"><strong><?php _e('Plugin documentation', '404-to-301'); ?></strong></a></label>
59
+ <span></span>
60
+ </div>
61
+ <div class="misc-pub-section">
62
+ <label><a href="https://iscode.co/products/404-to-301/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit plugin website', '404-to-301'); ?>"><strong><?php _e('More details about the plugin', '404-to-301'); ?></strong></a></label>
63
+ <span></span>
64
+ </div>
65
+ <div class="misc-pub-section">
66
+ <label><?php _e('Need help?', '404-to-301'); ?></label>
67
+ <span><strong><a href="https://iscode.co/contact/"><?php _e('contact support', '404-to-301'); ?></a></strong></span>
68
+ </div>
69
+ </div>
70
+ </div>
71
+ <div class="postbox">
72
+ <h3 class="hndle ui-sortable-handle"><span class="dashicons dashicons-smiley"></span> <?php _e('Like the plugin', '404-to-301'); ?>?</h3>
73
+ <div class="inside">
74
+ <div class="misc-pub-section">
75
+ <span class="dashicons dashicons-star-filled"></span> <label><strong><a href="https://wordpress.org/support/view/plugin-reviews/404-to-301?filter=5#postform" target="_blank" title="<?php _e('Rate now', '404-to-301'); ?>"><?php _e('Rate this on WordPress', '404-to-301'); ?></a></strong></label>
76
+ </div>
77
+ <div class="misc-pub-section">
78
+ <label><span class="dashicons dashicons-heart"></span> <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4" target="_blank" title="<?php _e('Donate now', '404-to-301'); ?>"><?php _e('Make a small donation', '404-to-301'); ?></a></strong></label>
79
+ </div>
80
+ <div class="misc-pub-section">
81
+ <label><span class="dashicons dashicons-admin-plugins"></span> <strong><a href="https://github.com/joel-james/404-to-301/" target="_blank" title="<?php _e('Contribute now', '404-to-301'); ?>"><?php _e('Contribute to the Plugin', '404-to-301'); ?></a></strong></label>
82
+ </div>
83
+ <div class="misc-pub-section">
84
+ <label><span class="dashicons dashicons-twitter"></span> <strong><a href="https://twitter.com/home?status=I%20am%20using%20404%20to%20301%20plugin%20by%20%40Joel_James%20to%20handle%20all%20404%20errors%20in%20my%20%40WordPress%20site%20-%20it%20is%20awesome!%20%3E%20https://wordpress.org/plugins/404-to-301/" target="_blank" title="<?php _e('Tweet now', '404-to-301'); ?>"><?php _e('Tweet about the Plugin', '404-to-301'); ?></a></strong></label>
85
+ </div>
86
+ </div>
87
+ </div>
88
+
89
+ </div>
90
+ </div>
91
+ </div>
92
  </div>
admin/partials/404-to-301-admin-display.php CHANGED
@@ -55,4 +55,4 @@ if ( ! defined( 'WPINC' ) ) {
55
  break;
56
  default:
57
  include_once('404-to-301-admin-general-tab.php');
58
- }
55
  break;
56
  default:
57
  include_once('404-to-301-admin-general-tab.php');
58
+ }
admin/partials/404-to-301-admin-general-tab.php CHANGED
@@ -1,106 +1,109 @@
1
- <div class="wrap">
2
- <form method="post" action="options.php">
3
- <p>
4
- <?php settings_fields( 'i4t3_gnrl_options' ); ?>
5
- <?php $options = get_option( 'i4t3_gnrl_options' ); ?>
6
- <?php
7
- // To show/hide options
8
- $cp_style = 'style="display: none;"';
9
- $cl_style = 'style="display: none;"';
10
- switch ( $options['redirect_to'] ) {
11
- case 'page':
12
- $cp_style = '';
13
- break;
14
-
15
- case 'link':
16
- $cl_style = '';
17
- break;
18
-
19
- default:
20
- break;
21
- }
22
- ?>
23
- <table class="form-table">
24
- <tbody>
25
-
26
- <tr>
27
- <th><?php _e( 'Redirect type', '404-to-301' ); ?></th>
28
- <td>
29
- <select name='i4t3_gnrl_options[redirect_type]'>
30
- <option value='301' <?php selected( $options['redirect_type'], '301' ); ?>>301 <?php _e( 'Redirect (SEO)', '404-to-301' ); ?></option>
31
- <option value='302' <?php selected( $options['redirect_type'], '302' ); ?>>302 <?php _e( 'Redirect', '404-to-301' ); ?></option>
32
- <option value='307' <?php selected( $options['redirect_type'], '307' ); ?>>307 <?php _e( 'Redirect', '404-to-301' ); ?></option>
33
- </select>
34
- <p class="description"><a target="_blank" href="https://moz.com/learn/seo/redirection"><strong><?php _e( 'Learn more', '404-to-301' ); ?></strong></a> <?php _e( 'about these redirect types', '404-to-301' ); ?></p>
35
- </td>
36
- </tr>
37
- <tr>
38
- <th><?php _e( 'Redirect to', '404-to-301' ); ?></th>
39
- <td>
40
- <select name='i4t3_gnrl_options[redirect_to]' id='i4t3_redirect_to'>
41
- <option value='page' <?php selected( $options['redirect_to'], 'page' ); ?>><?php _e( 'Existing Page', '404-to-301' ); ?></option>
42
- <option value='link' <?php selected( $options['redirect_to'], 'link' ); ?>><?php _e( 'Custom URL', '404-to-301' ); ?></option>
43
- <option value='none' <?php selected( $options['redirect_to'], 'none' ); ?>><?php _e( 'No Redirect', '404-to-301' ); ?></option>
44
- </select>
45
- <p class="description"><strong><?php _e( 'Existing Page', '404-to-301' ); ?>:</strong> <?php _e( 'Select any WordPress page as a 404 page', '404-to-301' ); ?>.</p>
46
- <p class="description"><strong><?php _e( 'Custom URL', '404-to-301' ); ?>:</strong> <?php _e( 'Redirect 404 requests to a specific URL', '404-to-301' ); ?>.</p>
47
- <p class="description"><strong><?php _e( 'No Redirect', '404-to-301' ); ?>:</strong> <?php _e( 'To disable redirect', '404-to-301' ); ?>.</p>
48
- </td>
49
- </tr>
50
- <tr id="custom_page" <?php echo $cp_style; ?>>
51
- <th><?php _e( 'Select the page', '404-to-301' ); ?></th>
52
- <td>
53
- <select name='i4t3_gnrl_options[redirect_page]'>
54
- <?php foreach( $pages as $page ) { ?>
55
- <option value='<?php echo $page->ID; ?>' <?php selected( $options['redirect_page'], $page->ID ); ?>><?php echo $page->post_title; ?></option>
56
- <?php } ?>
57
- </select>
58
- <p class="description"><?php _e( 'The default 404 page will be replaced by the page you choose in this list', '404-to-301' ); ?>.</p>
59
- </td>
60
- </tr>
61
- <tr id="custom_url"<?php echo $cl_style; ?>>
62
- <th><?php _e( 'Custom URL', '404-to-301' ); ?></th>
63
- <td>
64
- <input type="text" placeholder="<?php echo home_url(); ?>" name="i4t3_gnrl_options[redirect_link]" value="<?php echo $options['redirect_link']; ?>">
65
- <p class="description"><?php _e( 'Enter any url', '404-to-301' ); ?> (<?php _e( 'including', '404-to-301' ); ?> http://)</p>
66
- </td>
67
- </tr>
68
- <tr>
69
- <th><?php _e( 'Log 404 Errors', '404-to-301' ); ?></th>
70
- <td>
71
- <select name='i4t3_gnrl_options[redirect_log]'>
72
- <option value='1' <?php selected( $options['redirect_log'], 1 ); ?>><?php _e( 'Enable Error Logs', '404-to-301' ); ?></option>
73
- <option value='0' <?php selected( $options['redirect_log'], 0 ); ?>><?php _e( 'Disable Error Logs', '404-to-301' ); ?></option>
74
- </select>
75
- <p class="description"><?php _e( 'Enable/Disable Logging', '404-to-301' ); ?></p>
76
- </td>
77
- </tr>
78
- <tr>
79
- <th><?php _e( 'Email notifications', '404-to-301' ); ?></th>
80
- <td>
81
- <?php $email_notify = 0; if( isset( $options['email_notify'] ) ) { $email_notify = $options['email_notify']; } ?>
82
- <input type="checkbox" name="i4t3_gnrl_options[email_notify]" value="1" <?php checked( $email_notify, 1 ); ?> />
83
- <p class="description"><?php _e( 'If you check this, an email will be sent on every 404 log on the admin email account', '404-to-301' ); ?>.</p>
84
- </td>
85
- </tr>
86
- <tr>
87
- <th><?php _e( 'Email address', '404-to-301' ); ?></th>
88
- <td>
89
- <?php $notify_address = ( isset( $options['email_notify_address'] ) ) ? $options['email_notify_address'] : get_option( 'admin_email' ); ?>
90
- <input type="text" placeholder="<?php echo get_option( 'admin_email' ); ?>" name="i4t3_gnrl_options[email_notify_address]" value="<?php echo $notify_address; ?>">
91
- <p class="description"><?php _e( 'Change the recipient email address for error log notifications', '404-to-301' ); ?>.</p>
92
- </td>
93
- </tr>
94
- <tr>
95
- <th><?php _e( 'Exclude paths', '404-to-301' ); ?></th>
96
- <td>
97
- <textarea rows="5" cols="50" placeholder="http://example.com&#13;&#10;wp-content/plugins/abc-plugin/css/" name="i4t3_gnrl_options[exclude_paths]"><?php echo $options['exclude_paths']; ?></textarea>
98
- <p class="description"><?php _e( 'If you want to exclude few paths from error logs, enter here. One per line.', '404-to-301' ); ?>.</p>
99
- </td>
100
- </tr>
101
- </tbody>
102
- </table>
103
- <?php submit_button( __( 'Save All Changes', '404-to-301' ) ); ?>
104
- </p>
105
- </form>
 
 
 
106
  </div>
1
+ <div class="wrap">
2
+ <form method="post" action="options.php">
3
+ <p>
4
+ <?php settings_fields('i4t3_gnrl_options'); ?>
5
+ <?php $options = get_option('i4t3_gnrl_options'); ?>
6
+ <?php
7
+ // To show/hide options
8
+ $cp_style = 'style="display: none;"';
9
+ $cl_style = 'style="display: none;"';
10
+ switch ($options['redirect_to']) {
11
+ case 'page':
12
+ $cp_style = '';
13
+ break;
14
+
15
+ case 'link':
16
+ $cl_style = '';
17
+ break;
18
+
19
+ default:
20
+ break;
21
+ }
22
+ ?>
23
+ <table class="form-table">
24
+ <tbody>
25
+
26
+ <tr>
27
+ <th><?php _e('Redirect type', '404-to-301'); ?></th>
28
+ <td>
29
+ <select name='i4t3_gnrl_options[redirect_type]'>
30
+ <option value='301' <?php selected($options['redirect_type'], '301'); ?>>301 <?php _e('Redirect (SEO)', '404-to-301'); ?></option>
31
+ <option value='302' <?php selected($options['redirect_type'], '302'); ?>>302 <?php _e('Redirect', '404-to-301'); ?></option>
32
+ <option value='307' <?php selected($options['redirect_type'], '307'); ?>>307 <?php _e('Redirect', '404-to-301'); ?></option>
33
+ </select>
34
+ <p class="description"><a target="_blank" href="https://moz.com/learn/seo/redirection"><strong><?php _e('Learn more', '404-to-301'); ?></strong></a> <?php _e('about these redirect types', '404-to-301'); ?></p>
35
+ </td>
36
+ </tr>
37
+ <tr>
38
+ <th><?php _e('Redirect to', '404-to-301'); ?></th>
39
+ <td>
40
+ <select name='i4t3_gnrl_options[redirect_to]' id='i4t3_redirect_to'>
41
+ <option value='page' <?php selected($options['redirect_to'], 'page'); ?>><?php _e('Existing Page', '404-to-301'); ?></option>
42
+ <option value='link' <?php selected($options['redirect_to'], 'link'); ?>><?php _e('Custom URL', '404-to-301'); ?></option>
43
+ <option value='none' <?php selected($options['redirect_to'], 'none'); ?>><?php _e('No Redirect', '404-to-301'); ?></option>
44
+ </select>
45
+ <p class="description"><strong><?php _e('Existing Page', '404-to-301'); ?>:</strong> <?php _e('Select any WordPress page as a 404 page', '404-to-301'); ?>.</p>
46
+ <p class="description"><strong><?php _e('Custom URL', '404-to-301'); ?>:</strong> <?php _e('Redirect 404 requests to a specific URL', '404-to-301'); ?>.</p>
47
+ <p class="description"><strong><?php _e('No Redirect', '404-to-301'); ?>:</strong> <?php _e('To disable redirect', '404-to-301'); ?>.</p>
48
+ </td>
49
+ </tr>
50
+ <tr id="custom_page" <?php echo $cp_style; ?>>
51
+ <th><?php _e('Select the page', '404-to-301'); ?></th>
52
+ <td>
53
+ <select name='i4t3_gnrl_options[redirect_page]'>
54
+ <?php foreach ($pages as $page) { ?>
55
+ <option value='<?php echo $page->ID; ?>' <?php selected($options['redirect_page'], $page->ID); ?>><?php echo $page->post_title; ?></option>
56
+ <?php } ?>
57
+ </select>
58
+ <p class="description"><?php _e('The default 404 page will be replaced by the page you choose in this list', '404-to-301'); ?>.</p>
59
+ </td>
60
+ </tr>
61
+ <tr id="custom_url"<?php echo $cl_style; ?>>
62
+ <th><?php _e('Custom URL', '404-to-301'); ?></th>
63
+ <td>
64
+ <input type="text" placeholder="<?php echo home_url(); ?>" name="i4t3_gnrl_options[redirect_link]" value="<?php echo $options['redirect_link']; ?>">
65
+ <p class="description"><?php _e('Enter any url', '404-to-301'); ?> (<?php _e('including', '404-to-301'); ?> http://)</p>
66
+ </td>
67
+ </tr>
68
+ <tr>
69
+ <th><?php _e('Log 404 Errors', '404-to-301'); ?></th>
70
+ <td>
71
+ <select name='i4t3_gnrl_options[redirect_log]'>
72
+ <option value='1' <?php selected($options['redirect_log'], 1); ?>><?php _e('Enable Error Logs', '404-to-301'); ?></option>
73
+ <option value='0' <?php selected($options['redirect_log'], 0); ?>><?php _e('Disable Error Logs', '404-to-301'); ?></option>
74
+ </select>
75
+ <p class="description"><?php _e('Enable/Disable Logging', '404-to-301'); ?></p>
76
+ </td>
77
+ </tr>
78
+ <tr>
79
+ <th><?php _e('Email notifications', '404-to-301'); ?></th>
80
+ <td>
81
+ <?php $email_notify = 0;
82
+ if (isset($options['email_notify'])) {
83
+ $email_notify = $options['email_notify'];
84
+ } ?>
85
+ <input type="checkbox" name="i4t3_gnrl_options[email_notify]" value="1" <?php checked($email_notify, 1); ?> />
86
+ <p class="description"><?php _e('If you check this, an email will be sent on every 404 log on the admin email account', '404-to-301'); ?>.</p>
87
+ </td>
88
+ </tr>
89
+ <tr>
90
+ <th><?php _e('Email address', '404-to-301'); ?></th>
91
+ <td>
92
+ <?php $notify_address = ( isset($options['email_notify_address']) ) ? $options['email_notify_address'] : get_option('admin_email'); ?>
93
+ <input type="text" placeholder="<?php echo get_option('admin_email'); ?>" name="i4t3_gnrl_options[email_notify_address]" value="<?php echo $notify_address; ?>">
94
+ <p class="description"><?php _e('Change the recipient email address for error log notifications', '404-to-301'); ?>.</p>
95
+ </td>
96
+ </tr>
97
+ <tr>
98
+ <th><?php _e('Exclude paths', '404-to-301'); ?></th>
99
+ <td>
100
+ <textarea rows="5" cols="50" placeholder="wp-content/plugins/abc-plugin/css/" name="i4t3_gnrl_options[exclude_paths]"><?php echo $options['exclude_paths']; ?></textarea>
101
+ <p class="description"><?php _e('If you want to exclude few paths from error logs, enter here. One per line.', '404-to-301'); ?></p>
102
+ </td>
103
+ </tr>
104
+ </tbody>
105
+ </table>
106
+ <?php submit_button(__('Save All Changes', '404-to-301')); ?>
107
+ </p>
108
+ </form>
109
  </div>
includes/class-404-to-301-activator.php CHANGED
@@ -1,7 +1,9 @@
1
  <?php
2
- if ( ! defined( 'WPINC' ) ) {
3
- die('Damn it.! Dude you are looking for what?');
 
4
  }
 
5
  /**
6
  * Fired during plugin activation.
7
  *
@@ -15,115 +17,114 @@ if ( ! defined( 'WPINC' ) ) {
15
  */
16
  class _404_To_301_Activator {
17
 
18
- /**
19
- * Function to run during activation
20
- * Transfering old options to new - 404 to 301
21
- *
22
- * 404 to 301 Coding sturucture and options are changed to new sturcture.
23
- * So we need to transfer old values to new structure. This file will
24
- * be used once. After transferring, we will never use these functions.
25
- *
26
- * @since 2.0.0
27
- * @author Joel James
28
- */
29
- public static function activate() {
30
-
31
- // Set default values for the plugin
32
- $i4t3_type = self::transfer( 'type', 'redirect_type', '301' );
33
- $i4t3_link = self::transfer( 'link', 'redirect_link', site_url() );
34
- $i4t3_enable = self::transfer( '', 'redirect_log', 1 );
35
- $i4t3_to = self::transfer( '', 'redirect_to', 'link' );
36
- $i4t3_page = self::transfer( '', 'redirect_page', '' );
37
- $i4t3_notify = self::transfer( '', 'email_notify', 0 );
38
- $i4t3_notify_email = self::transfer( '', 'email_notify_address', get_option( 'admin_email' ) );
39
- $i4t3_exclude = self::transfer( '', 'exclude_paths', '' );
40
-
41
- // New general settings array to be added
42
- $i4t3GnrlOptions = array(
43
- 'redirect_type' => $i4t3_type,
44
- 'redirect_link' => $i4t3_link,
45
- 'redirect_log' => $i4t3_enable,
46
- 'redirect_to' => $i4t3_to,
47
- 'redirect_page' => $i4t3_page,
48
- 'email_notify' => $i4t3_notify,
49
- 'email_notify_address' => $i4t3_notify_email,
50
- 'exclude_paths' => $i4t3_exclude
51
- );
52
-
53
- /**
54
- * Array of all settings arrays.
55
- * We are adding this to an array as we need to register
56
- * multiple settings in future for addons
57
- */
58
- $i4t3_options = array(
59
- 'i4t3_gnrl_options' => $i4t3GnrlOptions
60
- );
61
-
62
- // If not already exist, adding values
63
- foreach ($i4t3_options as $key => $value) {
64
- update_option($key, $value );
65
- }
66
-
67
- // remember, two spaces after PRIMARY KEY otherwise WP borks
68
- $installed_version = get_option('i4t3_db_version');
69
-
70
- if( !$installed_version || ( I4T3_DB_VERSION != $installed_version ) ) {
71
-
72
- global $wpdb;
73
- $table = $wpdb->prefix . "404_to_301";
74
-
75
- $sql = "CREATE TABLE $table (
76
- id BIGINT NOT NULL AUTO_INCREMENT,
77
- date DATETIME NOT NULL,
78
- url VARCHAR(512) NOT NULL,
79
- ref VARCHAR(512) NOT NULL default '',
80
- ip VARCHAR(40) NOT NULL default '',
81
- ua VARCHAR(512) NOT NULL default '',
82
- PRIMARY KEY (id)
83
- );";
84
-
85
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
86
- dbDelta($sql); // To be safe on db upgrades
87
- update_option( 'i4t3_db_version', I4T3_DB_VERSION );
88
- }
89
- }
90
-
91
-
92
- /**
93
- * Function to get existing settings
94
- *
95
- * This function used to check if the new setting is already available
96
- * in datatabse, then consider that. Otherwise check for the old one
97
- * and if available, takes that.
98
- * If both the values are not available, then creates new default settings.
99
- *
100
- * @since 2.0.0
101
- * @author Joel James
102
- */
103
- public static function transfer( $old, $new, $fresh ){
104
-
105
- $option = 'i4t3_gnrl_options';
106
-
107
- // let us check if new options already exists
108
- if( get_option( $option ) ) {
109
- $i4t3_option = get_option( $option );
110
- // If exists, then take that option value
111
- $fresh = (!empty($i4t3_option[$new])) ? $i4t3_option[$new] : $fresh;
112
- // Check if old value is available for the same option
113
- if( in_array( $old, array( 'type', 'link' ) ) && get_option( $old )) {
114
- // If available delete it, as we are moving to new settings
115
- delete_option( $old );
116
- }
117
- }
118
- // Fine, new options doesn't exist, then let us search for old
119
- else if( get_option( $old ) ) {
120
- // Take old value and set it to new
121
- $fresh = get_option($old);
122
- // Delete it, as we are moving to new settings
123
- delete_option( $old );
124
- }
125
-
126
- return $fresh;
127
- }
128
-
129
- }
1
  <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ die('Damn it.! Dude you are looking for what?');
5
  }
6
+
7
  /**
8
  * Fired during plugin activation.
9
  *
17
  */
18
  class _404_To_301_Activator {
19
 
20
+ /**
21
+ * Function to run during activation
22
+ * Transfering old options to new - 404 to 301
23
+ *
24
+ * 404 to 301 Coding sturucture and options are changed to new sturcture.
25
+ * So we need to transfer old values to new structure. This file will
26
+ * be used once. After transferring, we will never use these functions.
27
+ *
28
+ * @since 2.0.0
29
+ * @author Joel James
30
+ */
31
+ public static function activate() {
32
+
33
+ // Set default values for the plugin
34
+ $i4t3_type = self::transfer('type', 'redirect_type', '301');
35
+ $i4t3_link = self::transfer('link', 'redirect_link', site_url());
36
+ $i4t3_enable = self::transfer('', 'redirect_log', 1);
37
+ $i4t3_to = self::transfer('', 'redirect_to', 'link');
38
+ $i4t3_page = self::transfer('', 'redirect_page', '');
39
+ $i4t3_notify = self::transfer('', 'email_notify', 0);
40
+ $i4t3_notify_email = self::transfer('', 'email_notify_address', get_option('admin_email'));
41
+ $i4t3_exclude = self::transfer('', 'exclude_paths', '');
42
+
43
+ // New general settings array to be added
44
+ $i4t3GnrlOptions = array(
45
+ 'redirect_type' => $i4t3_type,
46
+ 'redirect_link' => $i4t3_link,
47
+ 'redirect_log' => $i4t3_enable,
48
+ 'redirect_to' => $i4t3_to,
49
+ 'redirect_page' => $i4t3_page,
50
+ 'email_notify' => $i4t3_notify,
51
+ 'email_notify_address' => $i4t3_notify_email,
52
+ 'exclude_paths' => $i4t3_exclude
53
+ );
54
+
55
+ /**
56
+ * Array of all settings arrays.
57
+ * We are adding this to an array as we need to register
58
+ * multiple settings in future for addons
59
+ */
60
+ $i4t3_options = array(
61
+ 'i4t3_gnrl_options' => $i4t3GnrlOptions
62
+ );
63
+
64
+ // If not already exist, adding values
65
+ foreach ($i4t3_options as $key => $value) {
66
+ update_option($key, $value);
67
+ }
68
+
69
+ // remember, two spaces after PRIMARY KEY otherwise WP borks
70
+ $installed_version = get_option('i4t3_db_version');
71
+
72
+ if (!$installed_version || ( I4T3_DB_VERSION != $installed_version )) {
73
+
74
+ global $wpdb;
75
+ $table = $wpdb->prefix . "404_to_301";
76
+
77
+ $sql = "CREATE TABLE $table (
78
+ id BIGINT NOT NULL AUTO_INCREMENT,
79
+ date DATETIME NOT NULL,
80
+ url VARCHAR(512) NOT NULL,
81
+ ref VARCHAR(512) NOT NULL default '',
82
+ ip VARCHAR(40) NOT NULL default '',
83
+ ua VARCHAR(512) NOT NULL default '',
84
+ PRIMARY KEY (id)
85
+ );";
86
+
87
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
88
+ dbDelta($sql); // To be safe on db upgrades
89
+ update_option('i4t3_db_version', I4T3_DB_VERSION);
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Function to get existing settings
95
+ *
96
+ * This function used to check if the new setting is already available
97
+ * in datatabse, then consider that. Otherwise check for the old one
98
+ * and if available, takes that.
99
+ * If both the values are not available, then creates new default settings.
100
+ *
101
+ * @since 2.0.0
102
+ * @author Joel James
103
+ */
104
+ public static function transfer($old, $new, $fresh) {
105
+
106
+ $option = 'i4t3_gnrl_options';
107
+
108
+ // let us check if new options already exists
109
+ if (get_option($option)) {
110
+ $i4t3_option = get_option($option);
111
+ // If exists, then take that option value
112
+ $fresh = (!empty($i4t3_option[$new])) ? $i4t3_option[$new] : $fresh;
113
+ // Check if old value is available for the same option
114
+ if (in_array($old, array('type', 'link')) && get_option($old)) {
115
+ // If available delete it, as we are moving to new settings
116
+ delete_option($old);
117
+ }
118
+ }
119
+ // Fine, new options doesn't exist, then let us search for old
120
+ else if (get_option($old)) {
121
+ // Take old value and set it to new
122
+ $fresh = get_option($old);
123
+ // Delete it, as we are moving to new settings
124
+ delete_option($old);
125
+ }
126
+
127
+ return $fresh;
128
+ }
129
+
130
+ }
 
includes/class-404-to-301-i18n.php CHANGED
@@ -1,44 +1,47 @@
1
- <?php
2
- /**
3
- * Define the internationalization functionality
4
- *
5
- * Loads and defines the internationalization files for this plugin
6
- * so that it is ready for translation.
7
- *
8
- * @link http://iscode.co/products/404-to-301/
9
- * @since 2.0.7
10
- * @package I4T3
11
- * @subpackage I4T3/includes
12
- * @author Joel James <me@joelsays.com>
13
- */
14
- class _404_To_301_i18n {
15
- /**
16
- * The domain specified for this plugin.
17
- *
18
- * @since 2.0.7
19
- * @access private
20
- * @var string $domain The domain identifier for this plugin.
21
- */
22
- private $domain;
23
- /**
24
- * Load the plugin text domain for translation.
25
- *
26
- * @since 2.0.7
27
- */
28
- public function load_plugin_textdomain() {
29
- load_plugin_textdomain(
30
- $this->domain,
31
- false,
32
- dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
33
- );
34
- }
35
- /**
36
- * Set the domain equal to that of the specified domain.
37
- *
38
- * @since 2.0.7
39
- * @param string $domain The domain that represents the locale of this plugin.
40
- */
41
- public function set_domain( $domain ) {
42
- $this->domain = $domain;
43
- }
44
- }
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Define the internationalization functionality
5
+ *
6
+ * Loads and defines the internationalization files for this plugin
7
+ * so that it is ready for translation.
8
+ *
9
+ * @link http://iscode.co/products/404-to-301/
10
+ * @since 2.0.7
11
+ * @package I4T3
12
+ * @subpackage I4T3/includes
13
+ * @author Joel James <me@joelsays.com>
14
+ */
15
+ class _404_To_301_i18n {
16
+
17
+ /**
18
+ * The domain specified for this plugin.
19
+ *
20
+ * @since 2.0.7
21
+ * @access private
22
+ * @var string $domain The domain identifier for this plugin.
23
+ */
24
+ private $domain;
25
+
26
+ /**
27
+ * Load the plugin text domain for translation.
28
+ *
29
+ * @since 2.0.7
30
+ */
31
+ public function load_plugin_textdomain() {
32
+ load_plugin_textdomain(
33
+ $this->domain, false, dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Set the domain equal to that of the specified domain.
39
+ *
40
+ * @since 2.0.7
41
+ * @param string $domain The domain that represents the locale of this plugin.
42
+ */
43
+ public function set_domain($domain) {
44
+ $this->domain = $domain;
45
+ }
46
+
47
+ }
includes/class-404-to-301-loader.php CHANGED
@@ -1,7 +1,8 @@
1
  <?php
 
2
  // If this file is called directly, abort.
3
- if ( ! defined( 'WPINC' ) ) {
4
- die('Damn it.! Dude you are looking for what?');
5
  }
6
 
7
  /**
@@ -19,107 +20,104 @@ if ( ! defined( 'WPINC' ) ) {
19
  */
20
  class _404_To_301_Loader {
21
 
22
- /**
23
- * The array of actions registered with WordPress.
24
- *
25
- * @since 2.0.0
26
- * @access protected
27
- * @var array $actions The actions registered with WordPress to fire when the plugin loads.
28
- */
29
- protected $actions;
30
-
31
- /**
32
- * The array of filters registered with WordPress.
33
- *
34
- * @since 2.0.0
35
- * @access protected
36
- * @var array $filters The filters registered with WordPress to fire when the plugin loads.
37
- */
38
- protected $filters;
39
-
40
- /**
41
- * Initialize the collections used to maintain the actions and filters.
42
- *
43
- * @since 2.0.0
44
- */
45
- public function __construct() {
46
-
47
- $this->actions = array();
48
- $this->filters = array();
49
-
50
- }
51
-
52
- /**
53
- * Add a new action to the collection to be registered with WordPress.
54
- *
55
- * @since 2.0.0
56
- * @var string $hook The name of the WordPress action that is being registered.
57
- * @var object $component A reference to the instance of the object on which the action is defined.
58
- * @var string $callback The name of the function definition on the $component.
59
- * @var int Optional $priority The priority at which the function should be fired.
60
- * @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
61
- */
62
- public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
63
- $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
64
- }
65
-
66
- /**
67
- * Add a new filter to the collection to be registered with WordPress.
68
- *
69
- * @since 2.0.0
70
- * @var string $hook The name of the WordPress filter that is being registered.
71
- * @var object $component A reference to the instance of the object on which the filter is defined.
72
- * @var string $callback The name of the function definition on the $component.
73
- * @var int Optional $priority The priority at which the function should be fired.
74
- * @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
75
- */
76
- public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
77
- $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
78
- }
79
-
80
- /**
81
- * A utility function that is used to register the actions and hooks into a single
82
- * collection.
83
- *
84
- * @since 2.0.0
85
- * @access private
86
- * @var array $hooks The collection of hooks that is being registered (that is, actions or filters).
87
- * @var string $hook The name of the WordPress filter that is being registered.
88
- * @var object $component A reference to the instance of the object on which the filter is defined.
89
- * @var string $callback The name of the function definition on the $component.
90
- * @var int Optional $priority The priority at which the function should be fired.
91
- * @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
92
- * @return type The collection of actions and filters registered with WordPress.
93
- */
94
- private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
95
-
96
- $hooks[] = array(
97
- 'hook' => $hook,
98
- 'component' => $component,
99
- 'callback' => $callback,
100
- 'priority' => $priority,
101
- 'accepted_args' => $accepted_args
102
- );
103
-
104
- return $hooks;
105
-
106
- }
107
-
108
- /**
109
- * Register the filters and actions with WordPress.
110
- *
111
- * @since 2.0.0
112
- */
113
- public function run() {
114
-
115
- foreach ( $this->filters as $hook ) {
116
- add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
117
- }
118
-
119
- foreach ( $this->actions as $hook ) {
120
- add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
121
- }
122
-
123
- }
124
 
125
  }
1
  <?php
2
+
3
  // If this file is called directly, abort.
4
+ if (!defined('WPINC')) {
5
+ die('Damn it.! Dude you are looking for what?');
6
  }
7
 
8
  /**
20
  */
21
  class _404_To_301_Loader {
22
 
23
+ /**
24
+ * The array of actions registered with WordPress.
25
+ *
26
+ * @since 2.0.0
27
+ * @access protected
28
+ * @var array $actions The actions registered with WordPress to fire when the plugin loads.
29
+ */
30
+ protected $actions;
31
+
32
+ /**
33
+ * The array of filters registered with WordPress.
34
+ *
35
+ * @since 2.0.0
36
+ * @access protected
37
+ * @var array $filters The filters registered with WordPress to fire when the plugin loads.
38
+ */
39
+ protected $filters;
40
+
41
+ /**
42
+ * Initialize the collections used to maintain the actions and filters.
43
+ *
44
+ * @since 2.0.0
45
+ */
46
+ public function __construct() {
47
+
48
+ $this->actions = array();
49
+ $this->filters = array();
50
+ }
51
+
52
+ /**
53
+ * Add a new action to the collection to be registered with WordPress.
54
+ *
55
+ * @since 2.0.0
56
+ * @var string $hook The name of the WordPress action that is being registered.
57
+ * @var object $component A reference to the instance of the object on which the action is defined.
58
+ * @var string $callback The name of the function definition on the $component.
59
+ * @var int Optional $priority The priority at which the function should be fired.
60
+ * @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
61
+ */
62
+ public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) {
63
+ $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args);
64
+ }
65
+
66
+ /**
67
+ * Add a new filter to the collection to be registered with WordPress.
68
+ *
69
+ * @since 2.0.0
70
+ * @var string $hook The name of the WordPress filter that is being registered.
71
+ * @var object $component A reference to the instance of the object on which the filter is defined.
72
+ * @var string $callback The name of the function definition on the $component.
73
+ * @var int Optional $priority The priority at which the function should be fired.
74
+ * @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
75
+ */
76
+ public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) {
77
+ $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args);
78
+ }
79
+
80
+ /**
81
+ * A utility function that is used to register the actions and hooks into a single
82
+ * collection.
83
+ *
84
+ * @since 2.0.0
85
+ * @access private
86
+ * @var array $hooks The collection of hooks that is being registered (that is, actions or filters).
87
+ * @var string $hook The name of the WordPress filter that is being registered.
88
+ * @var object $component A reference to the instance of the object on which the filter is defined.
89
+ * @var string $callback The name of the function definition on the $component.
90
+ * @var int Optional $priority The priority at which the function should be fired.
91
+ * @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
92
+ * @return type The collection of actions and filters registered with WordPress.
93
+ */
94
+ private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) {
95
+
96
+ $hooks[] = array(
97
+ 'hook' => $hook,
98
+ 'component' => $component,
99
+ 'callback' => $callback,
100
+ 'priority' => $priority,
101
+ 'accepted_args' => $accepted_args
102
+ );
103
+
104
+ return $hooks;
105
+ }
106
+
107
+ /**
108
+ * Register the filters and actions with WordPress.
109
+ *
110
+ * @since 2.0.0
111
+ */
112
+ public function run() {
113
+
114
+ foreach ($this->filters as $hook) {
115
+ add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
116
+ }
117
+
118
+ foreach ($this->actions as $hook) {
119
+ add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
120
+ }
121
+ }
 
 
 
122
 
123
  }
includes/class-404-to-301.php CHANGED
@@ -1,8 +1,10 @@
1
  <?php
 
2
  // If this file is called directly, abort.
3
- if ( ! defined( 'WPINC' ) ) {
4
- die('Damn it.! Dude you are looking for what?');
5
  }
 
6
  /**
7
  * The file that defines the core plugin class
8
  *
@@ -19,194 +21,193 @@ if ( ! defined( 'WPINC' ) ) {
19
  */
20
  class _404_To_301 {
21
 
22
- /**
23
- * The loader that's responsible for maintaining and registering all hooks that power
24
- * the plugin.
25
- *
26
- * @since 2.0.0
27
- * @access protected
28
- * @var _404_To_301_Loader $loader Maintains and registers all hooks for the plugin.
29
- */
30
- protected $loader;
31
-
32
- /**
33
- * The unique identifier of this plugin.
34
- *
35
- * @since 2.0.0
36
- * @access protected
37
- * @var string $plugin_name The string used to uniquely identify this plugin.
38
- */
39
- protected $plugin_name;
40
-
41
- /**
42
- * The current version of the plugin.
43
- *
44
- * @since 2.0.0
45
- * @access protected
46
- * @var string $version The current version of the plugin.
47
- */
48
- protected $version;
49
-
50
- /**
51
- * The database table of plugin.
52
- *
53
- * @since 2.0.0
54
- * @access protected
55
- * @var string $table The plugin table name in db.
56
- */
57
- protected $table;
58
- /**
59
- * Define the core functionality of the plugin.
60
- *
61
- * Set the plugin name, plugin version and the plugin table name that can be used throughout the plugin.
62
- * Load the dependencies, define the locale, and set the hooks for the Dashboard and
63
- * the public-facing side of the site.
64
- *
65
- * @since 2.0.0
66
- */
67
- public function __construct() {
68
-
69
- $this->plugin_name = '404-to-301';
70
- $this->version = '2.1.4';
71
- $this->table = $GLOBALS['wpdb']->prefix . '404_to_301';
72
- $this->load_dependencies();
73
- $this->set_locale();
74
- $this->define_admin_hooks();
75
- $this->define_handler_hooks();
76
- }
77
-
78
- /**
79
- * Load the required dependencies for this plugin.
80
- *
81
- * Include the following files that make up the plugin:
82
- *
83
- * - _404_To_301_Loader. Orchestrates the hooks of the plugin.
84
- * - _404_To_301_Admin. Defines all hooks for the dashboard.
85
- * - _404_To_301_Public. Defines all hooks for the public functions.
86
- * - _404_To_301_Logs. Defines all hooks for listing logs.
87
- *
88
- * Create an instance of the loader which will be used to register the hooks
89
- * with WordPress.
90
- *
91
- * @since 2.0.0
92
- * @access private
93
- */
94
- private function load_dependencies() {
95
-
96
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-404-to-301-loader.php';
97
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-404-to-301-i18n.php';
98
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-404-to-301-admin.php';
99
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-404-to-301-logs.php';
100
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-404-to-301-public.php';
101
-
102
- $this->loader = new _404_To_301_Loader();
103
- }
104
-
105
-
106
- /**
107
- * Define the locale for this plugin for internationalization.
108
- *
109
- * Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
110
- * with WordPress.
111
- *
112
- * @since 1.0.0
113
- * @access private
114
- */
115
- private function set_locale() {
116
- $plugin_i18n = new _404_To_301_i18n();
117
- $plugin_i18n->set_domain( $this->get_plugin_name() );
118
- $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
119
- }
120
-
121
-
122
- /**
123
- * Register all of the hooks related to the dashboard functionality
124
- * of the plugin.
125
- * This function is used to register all styles and JavaScripts for admin side.
126
- *
127
- * @since 2.0.0
128
- * @access private
129
- * @uses add_action() and add_filter()
130
- */
131
- private function define_admin_hooks() {
132
-
133
- $plugin_admin = new _404_To_301_Admin( $this->get_plugin_name(), $this->get_version(), $this->get_table() );
134
-
135
- $this->loader->add_filter( 'admin_init', $plugin_admin, 'add_buffer' );
136
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
137
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
138
- $this->loader->add_action( 'admin_menu', $plugin_admin, 'i4t3_create_404_to_301_menu');
139
- $this->loader->add_action( 'admin_menu', $plugin_admin, 'i4t3_rename_plugin_menu' );
140
- $this->loader->add_action( 'admin_init', $plugin_admin, 'i4t3_options_register' );
141
- $this->loader->add_filter( 'admin_footer_text', $plugin_admin, 'i4t3_dashboard_footer');
142
- $this->loader->add_filter( 'plugin_action_links', $plugin_admin, 'i4t3_plugin_action_links', 10, 5 );
143
- $this->loader->add_action( 'plugins_loaded', $plugin_admin, 'i4t3_upgrade_if_new' );
144
- $this->loader->add_filter( 'i4t3_notify_admin_email_address', $plugin_admin, 'i4t3_change_notify_email' );
145
- $this->loader->add_filter( 'set-screen-option', $plugin_admin, 'set_screen', 10, 3 );
146
- }
147
-
148
-
149
- /**
150
- * Register all of the hooks related to handle 404 actions of the plugin.
151
- *
152
- * @since 2.0.0
153
- * @access private
154
- * @uses add_filter()
155
- */
156
- private function define_handler_hooks() {
157
-
158
- $plugin_public = new _404_To_301_Public( $this->get_plugin_name(), $this->get_version(), $this->get_table() );
159
- // Main Hook to perform redirections on 404s
160
- $this->loader->add_filter( 'template_redirect', $plugin_public, 'i4t3_redirect_404' );
161
- }
162
-
163
- /**
164
- * Run the loader to execute all of the hooks with WordPress.
165
- *
166
- * @since 2.0.0
167
- */
168
- public function run() {
169
- $this->loader->run();
170
- }
171
-
172
- /**
173
- * The name of the plugin used to uniquely identify it within the context of
174
- * WordPress and to define internationalization functionality.
175
- *
176
- * @since 2.0.0
177
- * @return string The name of the plugin.
178
- */
179
- public function get_plugin_name() {
180
- return $this->plugin_name;
181
- }
182
-
183
- /**
184
- * The reference to the class that orchestrates the hooks with the plugin.
185
- *
186
- * @since 2.0.0
187
- * @return i4t3_Loader Orchestrates the hooks of the plugin.
188
- */
189
- public function get_loader() {
190
- return $this->loader;
191
- }
192
-
193
- /**
194
- * Retrieve the version number of the plugin.
195
- *
196
- * @since 2.0.0
197
- * @return string The version number of the plugin.
198
- */
199
- public function get_version() {
200
- return $this->version;
201
- }
202
-
203
- /**
204
- * Retrieve the table name of the plugin.
205
- *
206
- * @since 2.0.0
207
- * @return string The table name of the plugin.
208
- */
209
- public function get_table() {
210
- return $this->table;
211
- }
212
- }
1
  <?php
2
+
3
  // If this file is called directly, abort.
4
+ if (!defined('WPINC')) {
5
+ die('Damn it.! Dude you are looking for what?');
6
  }
7
+
8
  /**
9
  * The file that defines the core plugin class
10
  *
21
  */
22
  class _404_To_301 {
23
 
24
+ /**
25
+ * The loader that's responsible for maintaining and registering all hooks that power
26
+ * the plugin.
27
+ *
28
+ * @since 2.0.0
29
+ * @access protected
30
+ * @var _404_To_301_Loader $loader Maintains and registers all hooks for the plugin.
31
+ */
32
+ protected $loader;
33
+
34
+ /**
35
+ * The unique identifier of this plugin.
36
+ *
37
+ * @since 2.0.0
38
+ * @access protected
39
+ * @var string $plugin_name The string used to uniquely identify this plugin.
40
+ */
41
+ protected $plugin_name;
42
+
43
+ /**
44
+ * The current version of the plugin.
45
+ *
46
+ * @since 2.0.0
47
+ * @access protected
48
+ * @var string $version The current version of the plugin.
49
+ */
50
+ protected $version;
51
+
52
+ /**
53
+ * The database table of plugin.
54
+ *
55
+ * @since 2.0.0
56
+ * @access protected
57
+ * @var string $table The plugin table name in db.
58
+ */
59
+ protected $table;
60
+
61
+ /**
62
+ * Define the core functionality of the plugin.
63
+ *
64
+ * Set the plugin name, plugin version and the plugin table name that can be used throughout the plugin.
65
+ * Load the dependencies, define the locale, and set the hooks for the Dashboard and
66
+ * the public-facing side of the site.
67
+ *
68
+ * @since 2.0.0
69
+ */
70
+ public function __construct() {
71
+
72
+ $this->plugin_name = '404-to-301';
73
+ $this->version = '2.1.5';
74
+ $this->table = $GLOBALS['wpdb']->prefix . '404_to_301';
75
+ $this->load_dependencies();
76
+ $this->set_locale();
77
+ $this->define_admin_hooks();
78
+ $this->define_handler_hooks();
79
+ }
80
+
81
+ /**
82
+ * Load the required dependencies for this plugin.
83
+ *
84
+ * Include the following files that make up the plugin:
85
+ *
86
+ * - _404_To_301_Loader. Orchestrates the hooks of the plugin.
87
+ * - _404_To_301_Admin. Defines all hooks for the dashboard.
88
+ * - _404_To_301_Public. Defines all hooks for the public functions.
89
+ * - _404_To_301_Logs. Defines all hooks for listing logs.
90
+ *
91
+ * Create an instance of the loader which will be used to register the hooks
92
+ * with WordPress.
93
+ *
94
+ * @since 2.0.0
95
+ * @access private
96
+ */
97
+ private function load_dependencies() {
98
+
99
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-404-to-301-loader.php';
100
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-404-to-301-i18n.php';
101
+ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-404-to-301-admin.php';
102
+ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-404-to-301-logs.php';
103
+ require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-404-to-301-public.php';
104
+
105
+ $this->loader = new _404_To_301_Loader();
106
+ }
107
+
108
+ /**
109
+ * Define the locale for this plugin for internationalization.
110
+ *
111
+ * Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
112
+ * with WordPress.
113
+ *
114
+ * @since 1.0.0
115
+ * @access private
116
+ */
117
+ private function set_locale() {
118
+ $plugin_i18n = new _404_To_301_i18n();
119
+ $plugin_i18n->set_domain($this->get_plugin_name());
120
+ $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
121
+ }
122
+
123
+ /**
124
+ * Register all of the hooks related to the dashboard functionality
125
+ * of the plugin.
126
+ * This function is used to register all styles and JavaScripts for admin side.
127
+ *
128
+ * @since 2.0.0
129
+ * @access private
130
+ * @uses add_action() and add_filter()
131
+ */
132
+ private function define_admin_hooks() {
133
+
134
+ $plugin_admin = new _404_To_301_Admin($this->get_plugin_name(), $this->get_version(), $this->get_table());
135
+
136
+ $this->loader->add_filter('admin_init', $plugin_admin, 'add_buffer');
137
+ $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
138
+ $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
139
+ $this->loader->add_action('admin_menu', $plugin_admin, 'i4t3_create_404_to_301_menu');
140
+ $this->loader->add_action('admin_menu', $plugin_admin, 'i4t3_rename_plugin_menu');
141
+ $this->loader->add_action('admin_init', $plugin_admin, 'i4t3_options_register');
142
+ $this->loader->add_filter('admin_footer_text', $plugin_admin, 'i4t3_dashboard_footer');
143
+ $this->loader->add_filter('plugin_action_links', $plugin_admin, 'i4t3_plugin_action_links', 10, 5);
144
+ $this->loader->add_action('plugins_loaded', $plugin_admin, 'i4t3_upgrade_if_new');
145
+ $this->loader->add_filter('i4t3_notify_admin_email_address', $plugin_admin, 'i4t3_change_notify_email');
146
+ $this->loader->add_filter('set-screen-option', $plugin_admin, 'set_screen', 10, 3);
147
+ }
148
+
149
+ /**
150
+ * Register all of the hooks related to handle 404 actions of the plugin.
151
+ *
152
+ * @since 2.0.0
153
+ * @access private
154
+ * @uses add_filter()
155
+ */
156
+ private function define_handler_hooks() {
157
+
158
+ $plugin_public = new _404_To_301_Public($this->get_plugin_name(), $this->get_version(), $this->get_table());
159
+ // Main Hook to perform redirections on 404s
160
+ $this->loader->add_filter('template_redirect', $plugin_public, 'i4t3_redirect_404');
161
+ }
162
+
163
+ /**
164
+ * Run the loader to execute all of the hooks with WordPress.
165
+ *
166
+ * @since 2.0.0
167
+ */
168
+ public function run() {
169
+ $this->loader->run();
170
+ }
171
+
172
+ /**
173
+ * The name of the plugin used to uniquely identify it within the context of
174
+ * WordPress and to define internationalization functionality.
175
+ *
176
+ * @since 2.0.0
177
+ * @return string The name of the plugin.
178
+ */
179
+ public function get_plugin_name() {
180
+ return $this->plugin_name;
181
+ }
182
+
183
+ /**
184
+ * The reference to the class that orchestrates the hooks with the plugin.
185
+ *
186
+ * @since 2.0.0
187
+ * @return i4t3_Loader Orchestrates the hooks of the plugin.
188
+ */
189
+ public function get_loader() {
190
+ return $this->loader;
191
+ }
192
+
193
+ /**
194
+ * Retrieve the version number of the plugin.
195
+ *
196
+ * @since 2.0.0
197
+ * @return string The version number of the plugin.
198
+ */
199
+ public function get_version() {
200
+ return $this->version;
201
+ }
202
+
203
+ /**
204
+ * Retrieve the table name of the plugin.
205
+ *
206
+ * @since 2.0.0
207
+ * @return string The table name of the plugin.
208
+ */
209
+ public function get_table() {
210
+ return $this->table;
211
+ }
212
+
213
+ }
 
public/class-404-to-301-public.php CHANGED
@@ -1,8 +1,10 @@
1
  <?php
 
2
  // If this file is called directly, abort.
3
- if ( ! defined( 'WPINC' ) ) {
4
- die('Damn it.! Dude you are looking for what?');
5
  }
 
6
  /**
7
  * The public-facing functionality of the plugin.
8
  *
@@ -15,257 +17,249 @@ if ( ! defined( 'WPINC' ) ) {
15
  */
16
  class _404_To_301_Public {
17
 
18
- /**
19
- * The ID of this plugin.
20
- *
21
- * @since 2.0.0
22
- * @access private
23
- * @var string $plugin_name The ID of this plugin.
24
- */
25
- private $plugin_name;
26
-
27
- /**
28
- * The version of this plugin.
29
- *
30
- * @since 2.0.0
31
- * @access private
32
- * @var string $version The current version of this plugin.
33
- */
34
- private $version;
35
-
36
- /**
37
- * The database table of plugin.
38
- *
39
- * @since 2.0.0
40
- * @access protected
41
- * @var string $table The name of the database table from db.
42
- */
43
- private $table;
44
-
45
- /**
46
- * Initialize the class and set its properties.
47
- *
48
- * @since 2.0.0
49
- * @var string $plugin_name The name of the plugin.
50
- * @var string $version The version of this plugin.
51
- */
52
- public function __construct( $plugin_name, $version, $table ) {
53
-
54
- $this->plugin_name = $plugin_name;
55
- $this->version = $version;
56
- $this->table = $table;
57
- $this->gnrl_options = get_option( 'i4t3_gnrl_options' );
58
- }
59
-
60
-
61
- /**
62
- * Create the 404 Log Email to be sent.
63
- *
64
- * @since 2.0.0
65
- * @uses get_option To get admin email from database.
66
- * @uses get_bloginfo To get site title.
67
- */
68
- public function i4t3_send_404_log_email( $log_data ) {
69
-
70
- // Filter to change the email address used for admin notifications
71
- $admin_email = apply_filters( 'i4t3_notify_admin_email_address', get_option( 'admin_email' ) );
72
-
73
- // Action hook that will be performed before sending 404 error mail
74
- do_action( 'i4t3_before_404_email_log', $log_data );
75
-
76
- // Get the site name
77
- $site_name = get_bloginfo( 'name' );
78
-
79
- $headers[] = 'From: ' . $site_name . ' <' . $admin_email . '>' . "\r\n";
80
- $headers[] = 'Content-Type: text/html; charset=UTF-8';
81
- $message = '<p>'. __( 'Bummer! You have one more 404', '404-to-301' ) .'</p>';
82
- $message .= '<table>';
83
- $message .= '<tr>';
84
- $message .= '<th>'. __( 'IP Address', '404-to-301' ) .'</th>';
85
- $message .= '<td>' . $log_data['ip'] . '</td>';
86
- $message .= '</tr>';
87
- $message .= '<tr>';
88
- $message .= '<th>'. __( '404 Path', '404-to-301' ) .'</th>';
89
- $message .= '<td>' . $log_data['url'] . '</td>';
90
- $message .= '</tr>';
91
- $message .= '<tr>';
92
- $message .= '<th>'. __( 'User Agent', '404-to-301' ) .'</th>';
93
- $message .= '<td>' . $log_data['ua'] . '</td>';
94
- $message .= '</tr>';
95
- $message .= '</table>';
96
- $is_sent = wp_mail(
97
- $admin_email,
98
- __( 'Snap! One more 404 on ', '404-to-301' ) . $site_name,
99
- $message,
100
- $headers
101
- );
102
- }
103
-
104
-
105
- /**
106
- * The main function to perform redirections and logs on 404s.
107
- * Creating log for 404 errors, sending admin notification email if enables,
108
- * redirecting visitors to the specific page etc. are done in this function.
109
- *
110
- * @since 2.0.0
111
- * @uses wp_redirect To redirect to a given link.
112
- * @uses do_action To add new action.
113
- */
114
- public function i4t3_redirect_404() {
115
-
116
- // Check if 404 page and not admin side
117
- if ( is_404() && !is_admin() && !$this->i4t3_excluded_paths() ) {
118
-
119
- // Get the settings options
120
- $logging_status = ( !empty( $this->gnrl_options['redirect_log'] ) ) ? $this->gnrl_options['redirect_log'] : 0;
121
-
122
- $redirect_type = ( $this->gnrl_options['redirect_type'] ) ? $this->gnrl_options['redirect_type'] : '301';
123
- // Get the email notification settings
124
- $is_email_send = ( !empty( $this->gnrl_options['email_notify'] ) && $this->gnrl_options['email_notify'] == 1 ) ? true : false;
125
-
126
- // Get error details if emailnotification or log is enabled
127
- if( $logging_status == 1 || $is_email_send ) {
128
-
129
- // Action hook that will be performed before logging 404 errors
130
- do_action( 'i4t3_before_404_logging' );
131
-
132
- global $wpdb;
133
- $data = array(
134
- 'date' => current_time('mysql'),
135
- 'url' => $this->get_clear_empty( $_SERVER['REQUEST_URI'] )
136
- );
137
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
138
- $data['ip'] = $this->get_clear_empty( $_SERVER['HTTP_CLIENT_IP'] );
139
- } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
140
- $data['ip'] = $this->get_clear_empty( $_SERVER['HTTP_X_FORWARDED_FOR'] );
141
- } else {
142
- $data['ip'] = $this->get_clear_empty( $_SERVER['REMOTE_ADDR'] );
143
- }
144
- $data['ref'] = $this->get_clear_empty( $_SERVER['HTTP_REFERER'] );
145
- $data['ua'] = $this->get_clear_empty( $_SERVER['HTTP_USER_AGENT'] );
146
- // trim stuff
147
- foreach( array( 'url', 'ref', 'ua' ) as $k )
148
- if( isset( $data[$k] ) )
149
- $data[$k] = substr( $data[$k], 0, 512 );
150
- }
151
-
152
- // Add log data to db if log is enabled by user
153
- if($logging_status == 1 && !$this->i4t3_is_bot()) {
154
-
155
- $wpdb->insert( $this->table, $data );
156
-
157
- // pop old entry if we exceeded the limit
158
- //$max = intval( $this->options['max_entries'] );
159
- $max = 500;
160
- $cutoff = $wpdb->get_var( "SELECT id FROM $this->table ORDER BY id DESC LIMIT $max,1" );
161
- if( $cutoff ) {
162
- $wpdb->delete( $this->table, array( 'id' => intval( $cutoff ) ), array( '%d' ) );
163
- }
164
- }
165
-
166
- // Send email notification if enabled
167
- if ($is_email_send && !$this->i4t3_is_bot()) {
168
- $this->i4t3_send_404_log_email($data);
169
- }
170
-
171
- // Get redirect settings
172
- $redirect_to = $this->gnrl_options['redirect_to'];
173
-
174
- switch( $redirect_to ) {
175
- // Do not redirect if none is set
176
- case 'none':
177
- break;
178
- // Redirect to an existing WordPress site inside our site
179
- case 'page':
180
- $url = get_permalink( $this->gnrl_options['redirect_page'] );
181
- break;
182
- // Redirect to a custom link given by user
183
- case 'link':
184
- $naked_url = $this->gnrl_options['redirect_link'];
185
- $url = (!preg_match("~^(?:f|ht)tps?://~i", $naked_url)) ? "http://" . $naked_url : $naked_url;
186
- break;
187
- // If nothing, be chill and do nothing!
188
- default:
189
- break;
190
- }
191
-
192
- // Perform the redirect if $url is set
193
- if (!empty($url)) {
194
- // Action hook that will be performed before 404 redirect starts
195
- //echo $url; exit();
196
- do_action( 'i4t3_before_404_redirect' );
197
- wp_redirect( $url, $redirect_type );
198
- exit(); // exit, because WordPress will not exit automatically
199
- }
200
- // Action hook that will be performed after 404 redirect
201
- do_action( 'i4t3_after_404_redirect' );
202
- }
203
- }
204
-
205
-
206
- /**
207
- * Check if Bot is visiting.
208
- *
209
- * This function is used to check if a bot is being viewed our site content.
210
- *
211
- * @reference http://stackoverflow.com/questions/677419/how-to-detect-search-engine-bots-with-php
212
- * @since 2.0.5
213
- * @author Joel James
214
- */
215
- public function i4t3_is_bot() {
216
-
217
- $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
218
- "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
219
- "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
220
- "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
221
- "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
222
- "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
223
- "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
224
- "Butterfly","Twitturls","Me.dium","Twiceler");
225
-
226
- foreach($botlist as $bot){
227
- if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
228
- return true; // Is a bot
229
- }
230
-
231
- return false; // Not a bot
232
- }
233
-
234
-
235
- /**
236
- * Exclude specific uri strings/paths from errors
237
- *
238
- * @retun True if requested uri matches specified one
239
- * @since 2.0.8
240
- * @author Joel James
241
- */
242
- public function i4t3_excluded_paths() {
243
-
244
- // Add links to be excluded in this array.
245
- $links_string = $this->gnrl_options['exclude_paths'];
246
- if( empty( $links_string ) ) {
247
- return false;
248
- }
249
- $links = explode( "\n", $links_string );
250
- if( !empty( $links ) ) {
251
- foreach( $links as $link ){
252
- if( strpos( $_SERVER['REQUEST_URI'], trim($link) )!== false )
253
- return true;
254
- }
255
- }
256
- return false;
257
- }
258
-
259
-
260
- /**
261
- * Check if value is empty before trying to insert.
262
- *
263
- * @since 2.0.9.1
264
- * @author Joel James
265
- */
266
- public function get_clear_empty( $data = null ) {
267
-
268
- return ( $data == null || empty($data) ) ? 'N/A' : $data;
269
- }
270
 
271
  }
1
  <?php
2
+
3
  // If this file is called directly, abort.
4
+ if (!defined('WPINC')) {
5
+ die('Damn it.! Dude you are looking for what?');
6
  }
7
+
8
  /**
9
  * The public-facing functionality of the plugin.
10
  *
17
  */
18
  class _404_To_301_Public {
19
 
20
+ /**
21
+ * The ID of this plugin.
22
+ *
23
+ * @since 2.0.0
24
+ * @access private
25
+ * @var string $plugin_name The ID of this plugin.
26
+ */
27
+ private $plugin_name;
28
+
29
+ /**
30
+ * The version of this plugin.
31
+ *
32
+ * @since 2.0.0
33
+ * @access private
34
+ * @var string $version The current version of this plugin.
35
+ */
36
+ private $version;
37
+
38
+ /**
39
+ * The database table of plugin.
40
+ *
41
+ * @since 2.0.0
42
+ * @access protected
43
+ * @var string $table The name of the database table from db.
44
+ */
45
+ private $table;
46
+
47
+ /**
48
+ * Initialize the class and set its properties.
49
+ *
50
+ * @since 2.0.0
51
+ * @var string $plugin_name The name of the plugin.
52
+ * @var string $version The version of this plugin.
53
+ */
54
+ public function __construct($plugin_name, $version, $table) {
55
+
56
+ $this->plugin_name = $plugin_name;
57
+ $this->version = $version;
58
+ $this->table = $table;
59
+ $this->gnrl_options = get_option('i4t3_gnrl_options');
60
+ }
61
+
62
+ /**
63
+ * Create the 404 Log Email to be sent.
64
+ *
65
+ * @since 2.0.0
66
+ * @uses get_option To get admin email from database.
67
+ * @uses get_bloginfo To get site title.
68
+ */
69
+ public function i4t3_send_404_log_email($log_data) {
70
+
71
+ // Filter to change the email address used for admin notifications
72
+ $admin_email = apply_filters('i4t3_notify_admin_email_address', get_option('admin_email'));
73
+
74
+ // Action hook that will be performed before sending 404 error mail
75
+ do_action('i4t3_before_404_email_log', $log_data);
76
+
77
+ // Get the site name
78
+ $site_name = get_bloginfo('name');
79
+
80
+ $headers[] = 'From: ' . $site_name . ' <' . $admin_email . '>' . "\r\n";
81
+ $headers[] = 'Content-Type: text/html; charset=UTF-8';
82
+ $message = '<p>' . __('Bummer! You have one more 404', '404-to-301') . '</p>';
83
+ $message .= '<table>';
84
+ $message .= '<tr>';
85
+ $message .= '<th>' . __('IP Address', '404-to-301') . '</th>';
86
+ $message .= '<td>' . $log_data['ip'] . '</td>';
87
+ $message .= '</tr>';
88
+ $message .= '<tr>';
89
+ $message .= '<th>' . __('404 Path', '404-to-301') . '</th>';
90
+ $message .= '<td>' . $log_data['url'] . '</td>';
91
+ $message .= '</tr>';
92
+ $message .= '<tr>';
93
+ $message .= '<th>' . __('User Agent', '404-to-301') . '</th>';
94
+ $message .= '<td>' . $log_data['ua'] . '</td>';
95
+ $message .= '</tr>';
96
+ $message .= '</table>';
97
+ $is_sent = wp_mail(
98
+ $admin_email, __('Snap! One more 404 on ', '404-to-301') . $site_name, $message, $headers
99
+ );
100
+ }
101
+
102
+ /**
103
+ * The main function to perform redirections and logs on 404s.
104
+ * Creating log for 404 errors, sending admin notification email if enables,
105
+ * redirecting visitors to the specific page etc. are done in this function.
106
+ *
107
+ * @since 2.0.0
108
+ * @uses wp_redirect To redirect to a given link.
109
+ * @uses do_action To add new action.
110
+ */
111
+ public function i4t3_redirect_404() {
112
+
113
+ // Check if 404 page and not admin side
114
+ if (is_404() && !is_admin() && !$this->i4t3_excluded_paths()) {
115
+
116
+ // Get the settings options
117
+ $logging_status = (!empty($this->gnrl_options['redirect_log']) ) ? $this->gnrl_options['redirect_log'] : 0;
118
+
119
+ $redirect_type = ( $this->gnrl_options['redirect_type'] ) ? $this->gnrl_options['redirect_type'] : '301';
120
+ // Get the email notification settings
121
+ $is_email_send = (!empty($this->gnrl_options['email_notify']) && $this->gnrl_options['email_notify'] == 1 ) ? true : false;
122
+
123
+ // Get error details if emailnotification or log is enabled
124
+ if ($logging_status == 1 || $is_email_send) {
125
+
126
+ // Action hook that will be performed before logging 404 errors
127
+ do_action('i4t3_before_404_logging');
128
+
129
+ global $wpdb;
130
+ $data = array(
131
+ 'date' => current_time('mysql'),
132
+ 'url' => $this->get_clear_empty($_SERVER['REQUEST_URI'])
133
+ );
134
+ if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
135
+ $data['ip'] = $this->get_clear_empty($_SERVER['HTTP_CLIENT_IP']);
136
+ } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
137
+ $data['ip'] = $this->get_clear_empty($_SERVER['HTTP_X_FORWARDED_FOR']);
138
+ } else {
139
+ $data['ip'] = $this->get_clear_empty($_SERVER['REMOTE_ADDR']);
140
+ }
141
+ $data['ref'] = $this->get_clear_empty($_SERVER['HTTP_REFERER']);
142
+ $data['ua'] = $this->get_clear_empty($_SERVER['HTTP_USER_AGENT']);
143
+ // trim stuff
144
+ foreach (array('url', 'ref', 'ua') as $k)
145
+ if (isset($data[$k]))
146
+ $data[$k] = substr($data[$k], 0, 512);
147
+ }
148
+
149
+ // Add log data to db if log is enabled by user
150
+ if ($logging_status == 1 && !$this->i4t3_is_bot()) {
151
+
152
+ $wpdb->insert($this->table, $data);
153
+
154
+ // pop old entry if we exceeded the limit
155
+ //$max = intval( $this->options['max_entries'] );
156
+ $max = 500;
157
+ $cutoff = $wpdb->get_var("SELECT id FROM $this->table ORDER BY id DESC LIMIT $max,1");
158
+ if ($cutoff) {
159
+ $wpdb->delete($this->table, array('id' => intval($cutoff)), array('%d'));
160
+ }
161
+ }
162
+
163
+ // Send email notification if enabled
164
+ if ($is_email_send && !$this->i4t3_is_bot()) {
165
+ $this->i4t3_send_404_log_email($data);
166
+ }
167
+
168
+ // Get redirect settings
169
+ $redirect_to = $this->gnrl_options['redirect_to'];
170
+
171
+ switch ($redirect_to) {
172
+ // Do not redirect if none is set
173
+ case 'none':
174
+ break;
175
+ // Redirect to an existing WordPress site inside our site
176
+ case 'page':
177
+ $url = get_permalink($this->gnrl_options['redirect_page']);
178
+ break;
179
+ // Redirect to a custom link given by user
180
+ case 'link':
181
+ $naked_url = $this->gnrl_options['redirect_link'];
182
+ $url = (!preg_match("~^(?:f|ht)tps?://~i", $naked_url)) ? "http://" . $naked_url : $naked_url;
183
+ break;
184
+ // If nothing, be chill and do nothing!
185
+ default:
186
+ break;
187
+ }
188
+
189
+ // Perform the redirect if $url is set
190
+ if (!empty($url)) {
191
+ // Action hook that will be performed before 404 redirect starts
192
+ //echo $url; exit();
193
+ do_action('i4t3_before_404_redirect');
194
+ wp_redirect($url, $redirect_type);
195
+ exit(); // exit, because WordPress will not exit automatically
196
+ }
197
+ // Action hook that will be performed after 404 redirect
198
+ do_action('i4t3_after_404_redirect');
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Check if Bot is visiting.
204
+ *
205
+ * This function is used to check if a bot is being viewed our site content.
206
+ *
207
+ * @reference http://stackoverflow.com/questions/677419/how-to-detect-search-engine-bots-with-php
208
+ * @since 2.0.5
209
+ * @author Joel James
210
+ */
211
+ public function i4t3_is_bot() {
212
+
213
+ $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
214
+ "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
215
+ "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
216
+ "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
217
+ "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
218
+ "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
219
+ "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler", "TweetmemeBot",
220
+ "Butterfly", "Twitturls", "Me.dium", "Twiceler");
221
+
222
+ foreach ($botlist as $bot) {
223
+ if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
224
+ return true; // Is a bot
225
+ }
226
+
227
+ return false; // Not a bot
228
+ }
229
+
230
+ /**
231
+ * Exclude specific uri strings/paths from errors
232
+ *
233
+ * @retun True if requested uri matches specified one
234
+ * @since 2.0.8
235
+ * @author Joel James
236
+ */
237
+ public function i4t3_excluded_paths() {
238
+
239
+ // Add links to be excluded in this array.
240
+ $links_string = $this->gnrl_options['exclude_paths'];
241
+ if (empty($links_string)) {
242
+ return false;
243
+ }
244
+ $links = explode("\n", $links_string);
245
+ if (!empty($links)) {
246
+ foreach ($links as $link) {
247
+ if (strpos($_SERVER['REQUEST_URI'], trim($link)) !== false)
248
+ return true;
249
+ }
250
+ }
251
+ return false;
252
+ }
253
+
254
+ /**
255
+ * Check if value is empty before trying to insert.
256
+ *
257
+ * @since 2.0.9.1
258
+ * @author Joel James
259
+ */
260
+ public function get_clear_empty($data = null) {
261
+
262
+ return ( $data == null || empty($data) ) ? 'N/A' : $data;
263
+ }
 
 
 
 
 
 
 
 
264
 
265
  }
readme.txt CHANGED
@@ -1,248 +1,254 @@
1
- === 404 to 301 ===
2
- Contributors: joelcj91,is_code
3
- Tags: 404, 301, 302, 307, not found, 404 redirect, 404 to 301, 301 redirect, seo redirect, error redirect, 404 seo, custom 404 page
4
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
5
- Requires at least: 3.0
6
- Tested up to: 4.4.1
7
- Stable tag: 2.1.4
8
- License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
-
11
- Automatically redirect, log and notify all 404 page errors to any page using 301 redirect for SEO. No more 404 Errors in WebMaster tool.
12
-
13
- == Description ==
14
-
15
- If you care about your website, you should take steps to avoid 404 errors as it affects your SEO badly. 404 ( Page not found ) errors are common and we all hate it, even Search engines do the same! Install this plugin then sit back and relax. It will take care of 404 errors!
16
-
17
- = What is 404 to 301? =
18
-
19
- *Handling 404 errors in your site should be easy. With this plugin, it finally is.*
20
-
21
- 404 to 301 is a simple but amazing plugin which handles all 404 errors for you. It will redirect all 404 errors to any page that you set, using 301 (or any other) status. That means no more 404 errors! Even in Google webmaster tool you are safe!
22
- You will not see any 404 error reports in your webmaster tool dashboard.
23
-
24
-
25
- > #### 404 to 301 - Features
26
- >
27
- > - You can redirect errors to any existing page or custom link.<br />
28
- > - No more 404 errors in your website. Seriously!<br />
29
- > - **Translation ready!**<br />
30
- > - You can optionally monitor/log all errors.<br />
31
- > - Exclude paths from errors.<br />
32
- > - You can optionally enable email notification on all 404 errors.<br />
33
- > - You can choose which redirect method to be used (301,302,307).<br />
34
- > - Will not irritate your visitors if they land on a non-existing page/url.<br />
35
- > - Super Light weight.<br />
36
- > - Increase your SEO by telling Google that all 404 pages are moved to some other page.<br />
37
- > - Completely free to use with lifetime updates.<br />
38
- > - Developer friendly.<br />
39
- > - Follows best WordPress coding standards.<br />
40
- > - Of course, available in [GitHub](https://github.com/joel-james/404-to-301)<br />
41
- >
42
- > [Installation](https://wordpress.org/plugins/404-to-301/installation/) | [Docs](http://iscode.co/docs/category/404-to-301/) | [Screenshots](https://wordpress.org/plugins/404-to-301/screenshots/)
43
-
44
-
45
- **Bug Reports**
46
-
47
- Bug reports for 404 to 301 are always welcome. [Report here](https://iscode.co/bug-report/).
48
-
49
- **More information**
50
-
51
- - [404 to 301 - Plugin Homepage](https://iscode.co/products/404-to-301/), containing more details and docs.
52
- - Follow the developer [@Twitter](https://twitter.com/Joel_James)
53
- - Other [WordPress plugins](https://profiles.wordpress.org/joelcj91/#content-plugins) by [Joel James for is_code()](https://iscode.co/)
54
-
55
- **404 Errors and Redirect - More Details**
56
-
57
- If you are confused with these terms 404,301, redirect etc, [refer this page](https://moz.com/learn/seo/redirection/) to know more about the redirect and SEO.
58
-
59
-
60
- == Installation ==
61
-
62
-
63
- = Installing the plugin - Simple =
64
- 1. In your WordPress admin panel, go to *Plugins > New Plugin*, search for **404 to 301** and click "*Install now*"
65
- 2. Alternatively, download the plugin and upload the contents of `404-to-301.zip` to your plugins directory, which usually is `/wp-content/plugins/`.
66
- 3. Activate the plugin
67
- 4. Go to 404 to 301 tab on your admin menus.
68
- 5. Configure the plugin options with available settings.
69
-
70
-
71
- = Need more help? =
72
- Please take a look at the [plugin documentation](http://iscode.co/docs/category/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
73
-
74
- = Missing something? =
75
- If you would like to have an additional feature for this plugin, [let me know](http://iscode.co/support/)
76
-
77
- == Frequently Asked Questions ==
78
-
79
- = What is the use of 404 to 301? =
80
-
81
- It will increase your SEO by redirecting all 404 errors using SEO redirects.
82
-
83
- = Can I monitor 404 errors? =
84
-
85
- Yes. You can. If you enable logs from settings, it will list all the errors.
86
-
87
- = How can I clear logs? =
88
-
89
- Select 'clear logs' from bulk actions and submit. It will delete all log data from your db.
90
-
91
- = Can I get email notifications? =
92
-
93
- Yes. You can enable email notifications on each 404 errors (optional).
94
-
95
- = I need more details =
96
-
97
- Please take a look at the [plugin documentation](http://iscode.co/docs/category/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
98
-
99
-
100
- == Other Notes ==
101
-
102
- = Bug Reports =
103
-
104
- Bug reports for 404 to 301 are always welcome. [Report here](http://iscode.co/bug-report/).
105
-
106
-
107
- == Screenshots ==
108
-
109
- 1. **Settings** - Settings page of 404 to 301.
110
- 2. **Error Logs** - Logged 404 Errors.
111
-
112
-
113
- == Changelog ==
114
-
115
- = 2.1.4 (22/01/2016) =
116
- **Bug Fixes**
117
-
118
- - Fixed issues when clearing logs (header already sent..).
119
- - Tested with WordPress 4.4.1.
120
-
121
- = 2.1.3 (20/12/2015) =
122
- **Bug Fixes**
123
-
124
- - Fixed issues with older version of WordPress.
125
- - Fixed issues with older version of PHP.
126
-
127
- = 2.1.0 (20/12/2015) =
128
- **New Feature**
129
-
130
- - New option to set items per page from error log listing page.
131
- - New option to show or hide items from listing table (Screen option).
132
-
133
- **Improvements**
134
-
135
- - Improved error listing page table structure.
136
-
137
- **Bug Fixes**
138
-
139
- - Fixed issue - Null value issue when no Referrer or User Agent found.
140
- - Fixed issue - Clearing errors and redirecting.
141
-
142
- = 2.0.9 (2/11/2015) =
143
- **Bug Fixes**
144
-
145
- - Fixed issue - Empty needle issue after 2.0.8 update.
146
-
147
- = 2.0.8 (28/10/2015) =
148
- **New Feature**
149
-
150
- - New option to exclude paths from error logs and redirect - [See details](https://iscode.co/docs/excluding-paths-from-error-logs-and-redirects/).
151
-
152
- **Bug Fixes**
153
-
154
- - Fixed issue - Email notifications are being sent even after disabling it.
155
- - Fixed issue - Settings reset after reactivation of plugin.
156
-
157
- = 2.0.7 (25/09/2015) =
158
- **New Feature**
159
-
160
- - New option to change error notification email address.
161
- - Now **100% Translation ready**.
162
-
163
- **Improvements**
164
-
165
- - Minor code improvements.
166
-
167
- = 2.0.6 (13/09/2015) =
168
- **Improvements**
169
-
170
- - Introduced new website for the plugin.
171
- - Fixed few dead link issues
172
-
173
- = 2.0.5 (03/09/2015) =
174
- **Improvements**
175
-
176
- - Added option to avoid search engine crawlers/bots from logging errors.
177
-
178
- **Bug Fixes**
179
-
180
- - Fixed error log per page issue.
181
-
182
- = 2.0.4 (26/08/2015) =
183
-
184
- **Bug Fixes**
185
-
186
- - Fixed an issue where error log table is not being created.
187
-
188
- = 2.0.3 (21/08/2015) =
189
-
190
- **Bug Fixes**
191
-
192
- - Fixed a serious issue which may cause SQL injection attack.
193
-
194
- = 2.0.2 (16/08/2015) =
195
- **Bug Fixes**
196
-
197
- - Fixed an issue with https redirect.
198
- - Fixed an issue with url preg_match.
199
-
200
- = 2.0.1 (29/07/2015) =
201
- **New Feature**
202
-
203
- - Now you can log/monitor all 404 errors (optional).
204
- - You can get email notifications on 404 errors (optional).
205
- - You can select existing pages from dropdown to set as redirect page.
206
- - New plugin home page.
207
-
208
- **Improvements**
209
-
210
- - Upgraded to WordPress plugin coding standard.
211
- - Documented all functions.
212
-
213
- = 1.0.8 =
214
- * Very minor bug fix
215
- * Tested for WP 4.2
216
-
217
- = 1.0.7 =
218
- * Fixed options saving issue in admin page.
219
- * Improved performance.
220
-
221
- = 1.0.6 =
222
- * Tested with latest version.
223
- * Improved structure.
224
-
225
- = 1.0.5 =
226
- * Bug fix.
227
- * Fixed permission issue on redirect link on plugin activation.
228
-
229
- = 1.0.4 =
230
- * Bug fix.
231
- * Fixed permission issue on activating along with some security plugins like WordFence.
232
-
233
- = 1.0.3 =
234
- * Added official support forum.
235
-
236
- = 1.0.1 =
237
- * Added official website details.
238
-
239
- = 1.0.0 =
240
- * Added first version with basic options.
241
-
242
- == Upgrade Notice ==
243
-
244
- = 2.1.4 (22/01/2016) =
245
- **Bug Fixes**
246
-
247
- - Fixed issues when clearing logs (header already sent..).
248
- - Tested with WordPress 4.4.1.
 
 
 
 
 
 
1
+ === 404 to 301 ===
2
+ Contributors: joelcj91,is_code
3
+ Tags: 404, 301, 302, 307, not found, 404 redirect, 404 to 301, 301 redirect, seo redirect, error redirect, 404 seo, custom 404 page
4
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
5
+ Requires at least: 3.0
6
+ Tested up to: 4.4.2
7
+ Stable tag: 2.1.5
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Automatically redirect, log and notify all 404 page errors to any page using 301 redirect for SEO. No more 404 Errors in WebMaster tool.
12
+
13
+ == Description ==
14
+
15
+ If you care about your website, you should take steps to avoid 404 errors as it affects your SEO badly. 404 ( Page not found ) errors are common and we all hate it, even Search engines do the same! Install this plugin then sit back and relax. It will take care of 404 errors!
16
+
17
+ = What is 404 to 301? =
18
+
19
+ *Handling 404 errors in your site should be easy. With this plugin, it finally is.*
20
+
21
+ 404 to 301 is a simple but amazing plugin which handles all 404 errors for you. It will redirect all 404 errors to any page that you set, using 301 (or any other) status. That means no more 404 errors! Even in Google webmaster tool you are safe!
22
+ You will not see any 404 error reports in your webmaster tool dashboard.
23
+
24
+
25
+ > #### 404 to 301 - Features
26
+ >
27
+ > - You can redirect errors to any existing page or custom link.<br />
28
+ > - No more 404 errors in your website. Seriously!<br />
29
+ > - **Translation ready!**<br />
30
+ > - You can optionally monitor/log all errors.<br />
31
+ > - Exclude paths from errors.<br />
32
+ > - You can optionally enable email notification on all 404 errors.<br />
33
+ > - You can choose which redirect method to be used (301,302,307).<br />
34
+ > - Will not irritate your visitors if they land on a non-existing page/url.<br />
35
+ > - Super Light weight.<br />
36
+ > - Increase your SEO by telling Google that all 404 pages are moved to some other page.<br />
37
+ > - Completely free to use with lifetime updates.<br />
38
+ > - Developer friendly.<br />
39
+ > - Follows best WordPress coding standards.<br />
40
+ > - Of course, available in [GitHub](https://github.com/joel-james/404-to-301)<br />
41
+ >
42
+ > [Installation](https://wordpress.org/plugins/404-to-301/installation/) | [Docs](http://iscode.co/docs/category/404-to-301/) | [Screenshots](https://wordpress.org/plugins/404-to-301/screenshots/)
43
+
44
+
45
+ **Bug Reports**
46
+
47
+ Bug reports for 404 to 301 are always welcome. [Report here](https://iscode.co/bug-report/).
48
+
49
+ **More information**
50
+
51
+ - [404 to 301 - Plugin Homepage](https://iscode.co/products/404-to-301/), containing more details and docs.
52
+ - Follow the developer [@Twitter](https://twitter.com/Joel_James)
53
+ - Other [WordPress plugins](https://profiles.wordpress.org/joelcj91/#content-plugins) by [Joel James for is_code()](https://iscode.co/)
54
+
55
+ **404 Errors and Redirect - More Details**
56
+
57
+ If you are confused with these terms 404,301, redirect etc, [refer this page](https://moz.com/learn/seo/redirection/) to know more about the redirect and SEO.
58
+
59
+
60
+ == Installation ==
61
+
62
+
63
+ = Installing the plugin - Simple =
64
+ 1. In your WordPress admin panel, go to *Plugins > New Plugin*, search for **404 to 301** and click "*Install now*"
65
+ 2. Alternatively, download the plugin and upload the contents of `404-to-301.zip` to your plugins directory, which usually is `/wp-content/plugins/`.
66
+ 3. Activate the plugin
67
+ 4. Go to 404 to 301 tab on your admin menus.
68
+ 5. Configure the plugin options with available settings.
69
+
70
+
71
+ = Need more help? =
72
+ Please take a look at the [plugin documentation](http://iscode.co/docs/category/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
73
+
74
+ = Missing something? =
75
+ If you would like to have an additional feature for this plugin, [let me know](http://iscode.co/support/)
76
+
77
+ == Frequently Asked Questions ==
78
+
79
+ = What is the use of 404 to 301? =
80
+
81
+ It will increase your SEO by redirecting all 404 errors using SEO redirects.
82
+
83
+ = Can I monitor 404 errors? =
84
+
85
+ Yes. You can. If you enable logs from settings, it will list all the errors.
86
+
87
+ = How can I clear logs? =
88
+
89
+ Select 'clear logs' from bulk actions and submit. It will delete all log data from your db.
90
+
91
+ = Can I get email notifications? =
92
+
93
+ Yes. You can enable email notifications on each 404 errors (optional).
94
+
95
+ = I need more details =
96
+
97
+ Please take a look at the [plugin documentation](http://iscode.co/docs/category/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
98
+
99
+
100
+ == Other Notes ==
101
+
102
+ = Bug Reports =
103
+
104
+ Bug reports for 404 to 301 are always welcome. [Report here](http://iscode.co/bug-report/).
105
+
106
+
107
+ == Screenshots ==
108
+
109
+ 1. **Settings** - Settings page of 404 to 301.
110
+ 2. **Error Logs** - Logged 404 Errors.
111
+
112
+
113
+ == Changelog ==
114
+
115
+ = 2.1.5 (22/03/2016) =
116
+ **Improvements**
117
+
118
+ - Fixed issues with deprecated functions - Thanks to [Pedro Mendonças](https://github.com/pedro-mendonca).
119
+ - Translated missing strings.
120
+ - Tested with WordPress 4.4.2.
121
+
122
+ = 2.1.4 (22/01/2016) =
123
+ **Bug Fixes**
124
+
125
+ - Fixed issues when clearing logs (header already sent..).
126
+ - Tested with WordPress 4.4.1.
127
+
128
+ = 2.1.3 (20/12/2015) =
129
+ **Bug Fixes**
130
+
131
+ - Fixed issues with older version of WordPress.
132
+ - Fixed issues with older version of PHP.
133
+
134
+ = 2.1.0 (20/12/2015) =
135
+ **New Feature**
136
+
137
+ - New option to set items per page from error log listing page.
138
+ - New option to show or hide items from listing table (Screen option).
139
+
140
+ **Improvements**
141
+
142
+ - Improved error listing page table structure.
143
+
144
+ **Bug Fixes**
145
+
146
+ - Fixed issue - Null value issue when no Referrer or User Agent found.
147
+ - Fixed issue - Clearing errors and redirecting.
148
+
149
+ = 2.0.9 (2/11/2015) =
150
+ **Bug Fixes**
151
+
152
+ - Fixed issue - Empty needle issue after 2.0.8 update.
153
+
154
+ = 2.0.8 (28/10/2015) =
155
+ **New Feature**
156
+
157
+ - New option to exclude paths from error logs and redirect - [See details](https://iscode.co/docs/excluding-paths-from-error-logs-and-redirects/).
158
+
159
+ **Bug Fixes**
160
+
161
+ - Fixed issue - Email notifications are being sent even after disabling it.
162
+ - Fixed issue - Settings reset after reactivation of plugin.
163
+
164
+ = 2.0.7 (25/09/2015) =
165
+ **New Feature**
166
+
167
+ - New option to change error notification email address.
168
+ - Now **100% Translation ready**.
169
+
170
+ **Improvements**
171
+
172
+ - Minor code improvements.
173
+
174
+ = 2.0.6 (13/09/2015) =
175
+ **Improvements**
176
+
177
+ - Introduced new website for the plugin.
178
+ - Fixed few dead link issues
179
+
180
+ = 2.0.5 (03/09/2015) =
181
+ **Improvements**
182
+
183
+ - Added option to avoid search engine crawlers/bots from logging errors.
184
+
185
+ **Bug Fixes**
186
+
187
+ - Fixed error log per page issue.
188
+
189
+ = 2.0.4 (26/08/2015) =
190
+
191
+ **Bug Fixes**
192
+
193
+ - Fixed an issue where error log table is not being created.
194
+
195
+ = 2.0.3 (21/08/2015) =
196
+
197
+ **Bug Fixes**
198
+
199
+ - Fixed a serious issue which may cause SQL injection attack.
200
+
201
+ = 2.0.2 (16/08/2015) =
202
+ **Bug Fixes**
203
+
204
+ - Fixed an issue with https redirect.
205
+ - Fixed an issue with url preg_match.
206
+
207
+ = 2.0.1 (29/07/2015) =
208
+ **New Feature**
209
+
210
+ - Now you can log/monitor all 404 errors (optional).
211
+ - You can get email notifications on 404 errors (optional).
212
+ - You can select existing pages from dropdown to set as redirect page.
213
+ - New plugin home page.
214
+
215
+ **Improvements**
216
+
217
+ - Upgraded to WordPress plugin coding standard.
218
+ - Documented all functions.
219
+
220
+ = 1.0.8 =
221
+ * Very minor bug fix
222
+ * Tested for WP 4.2
223
+
224
+ = 1.0.7 =
225
+ * Fixed options saving issue in admin page.
226
+ * Improved performance.
227
+
228
+ = 1.0.6 =
229
+ * Tested with latest version.
230
+ * Improved structure.
231
+
232
+ = 1.0.5 =
233
+ * Bug fix.
234
+ * Fixed permission issue on redirect link on plugin activation.
235
+
236
+ = 1.0.4 =
237
+ * Bug fix.
238
+ * Fixed permission issue on activating along with some security plugins like WordFence.
239
+
240
+ = 1.0.3 =
241
+ * Added official support forum.
242
+
243
+ = 1.0.1 =
244
+ * Added official website details.
245
+
246
+ = 1.0.0 =
247
+ * Added first version with basic options.
248
+
249
+ == Upgrade Notice ==
250
+
251
+ = 2.1.4 (22/01/2016) =
252
+ - Fixed issues with deprecated functions - Thanks to [Pedro Mendonças](https://github.com/pedro-mendonca).
253
+ - Translated missing strings.
254
+ - Tested with WordPress 4.4.2.
uninstall.php CHANGED
@@ -11,26 +11,25 @@
11
  * @author Joel James
12
  * @package I4T3
13
  */
14
-
15
  // If uninstall not called from WordPress, then exit. That's it!
16
 
17
- if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
18
- exit;
19
  }
20
 
21
  // Delete plugin options
22
- if( get_option( 'i4t3_gnrl_options' ) ) {
23
- delete_option( 'i4t3_gnrl_options' );
24
  }
25
- if( get_option( 'i4t3_db_version' ) ) {
26
- delete_option( 'i4t3_db_version' );
27
  }
28
- if( get_option( 'i4t3_version_no' ) ) {
29
- delete_option( 'i4t3_version_no' );
30
  }
31
 
32
  // Drop tables
33
  global $wpdb;
34
- $wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "404_to_301" );
35
 
36
  /******* The end. Thanks for using 404 to 301 plugin ********/
11
  * @author Joel James
12
  * @package I4T3
13
  */
 
14
  // If uninstall not called from WordPress, then exit. That's it!
15
 
16
+ if (!defined('WP_UNINSTALL_PLUGIN')) {
17
+ exit;
18
  }
19
 
20
  // Delete plugin options
21
+ if (get_option('i4t3_gnrl_options')) {
22
+ delete_option('i4t3_gnrl_options');
23
  }
24
+ if (get_option('i4t3_db_version')) {
25
+ delete_option('i4t3_db_version');
26
  }
27
+ if (get_option('i4t3_version_no')) {
28
+ delete_option('i4t3_version_no');
29
  }
30
 
31
  // Drop tables
32
  global $wpdb;
33
+ $wpdb->query("DROP TABLE IF EXISTS " . $wpdb->prefix . "404_to_301");
34
 
35
  /******* The end. Thanks for using 404 to 301 plugin ********/