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,