404 to 301 - Version 2.0.0

Version Description

(29/07/2015) = New Feature

  • Now you can log/monitor all 404 errors (optional).
  • You can get email notifications on 404 errors (optional).
  • You can select existing pages from dropdown to set as redirect page.
  • New plugin home page.

Improvements

  • Upgraded to WordPress plugin coding standard.
  • Documented all functions.
Download this release

Release Info

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

Code changes from version 1.0.8 to 2.0.0

404-to-301.php CHANGED
@@ -1,70 +1,95 @@
1
- <?php
2
-
3
- /*
4
- Plugin Name: 404 to 301
5
- Plugin URI: http://www.joelsays.com/plugins/404-to-301/
6
- Description: Automatically redirect all 404 page errors to any page using 301 redirect for SEO. No more 404 Errors in WebMaster tool.
7
- Author: Joel James
8
- Version: 1.0.8
9
- Author URI: http://www.joelsays.com/about/
10
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
11
- Copyright (c) 2014 Joel James
12
- */
13
- ?>
14
- <?php
15
-
16
- add_action('admin_menu', 'js_404_settings_menu');
17
- if(!function_exists('js_404_settings_menu')) {
18
- function js_404_settings_menu() {
19
- add_options_page('404 to 301', '404 to 301', 'administrator', 'js-options', 'js_404_settings');
20
- }
21
- }
22
-
23
- if(!function_exists('js_404_settings')) {
24
- function js_404_settings() {
25
- require_once('js-404-admin.php');
26
- }
27
- }
28
-
29
- if(!function_exists('js_404_redirect')) {
30
- function js_404_redirect(){
31
- $type = get_option('type');
32
- $link = get_option('link');
33
- if(is_404() && !empty($link) && !empty($type)){
34
- wp_redirect( $link, $type );
35
- exit;
36
- }
37
- }
38
- }
39
- add_action('template_redirect', 'js_404_redirect');
40
-
41
- register_activation_hook(__FILE__, 'js_404_activate');
42
- add_action('admin_init', 'js_404_start_redirect');
43
-
44
- if(!function_exists('js_404_activate')) {
45
- function js_404_activate() {
46
- add_option('js_404_activation_redirect', true);
47
- }
48
- }
49
-
50
- if(!function_exists('js_404_start_redirect')) {
51
- function js_404_start_redirect() {
52
- if (get_option('js_404_activation_redirect', false)):
53
- delete_option('js_404_activation_redirect');
54
- wp_redirect('options-general.php?page=js-options');
55
- endif;
56
- }
57
- }
58
-
59
- if(!function_exists('js_404_action_links')) {
60
- function js_404_action_links($links, $file) {
61
- $plugin_file = basename(__FILE__);
62
- if (basename($file) == $plugin_file) :
63
- $settings_link = '<a href="options-general.php?page=js-options">Settings</a>';
64
- array_unshift($links, $settings_link);
65
- endif;
66
- return $links;
67
- }
68
- }
69
-
70
- add_filter('plugin_action_links', 'js_404_action_links', 10, 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: 404 to 301
4
+ * Plugin URI: http://iscode.co/product/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.0.0
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
17
+ * the Free Software Foundation, either version 2 of the License, or
18
+ * any later version.
19
+ *
20
+ * 404 to 301 is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with Easy Digital Downloads. If not, see <http://www.gnu.org/licenses/>.
27
+ *
28
+ * @package I4T3
29
+ * @category Core
30
+ * @author Joel James
31
+ * @version 2.0.0
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', '1.0' );
53
+ }
54
+ if(!defined('I4T3_VERSION')) {
55
+ define( 'I4T3_VERSION', '2.0.0' );
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
+ /**
63
+ * The code that runs during plugin activation.
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.
80
+ *
81
+ * Since everything within the plugin is registered via hooks,
82
+ * then kicking off the plugin from this point in the file does
83
+ * not affect the page life cycle.
84
+ *
85
+ * @since 2.0.0
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 ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *
9
+ * Defines the plugin name, version, and enqueue the dashboard-specific stylesheet, JavaScript
10
+ * and all other admin side functions.
11
+ *
12
+ * @link http://iscode.co/product/404-to-301/
13
+ * @since 2.0.0
14
+ * @package I4T3
15
+ * @subpackage I4T3/admin
16
+ * @author Joel James <me@joelsays.com>
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
+ * Initialize the class and set its properties.
58
+ *
59
+ * @since 2.0.0
60
+ * @var string $plugin_name The name of this plugin.
61
+ * @var string $version The version of this plugin.
62
+ * @var string $table The name of the database table of this plugin.
63
+ */
64
+ public function __construct( $plugin_name, $version, $table ) {
65
+
66
+ $this->plugin_name = $plugin_name;
67
+ $this->version = $version;
68
+ $this->table = $table;
69
+ }
70
+
71
+
72
+ /**
73
+ * Register the stylesheets for the Dashboard.
74
+ *
75
+ * This function is used to register all the required stylesheets for
76
+ * dashboard. Styles will be registered only for i4t3 pages for performance.
77
+ *
78
+ * @since 2.0.0
79
+ * @uses wp_enqueue_style To register style
80
+ */
81
+ public function enqueue_styles() {
82
+
83
+ global $pagenow;
84
+
85
+ if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings','i4t3-logs')))) {
86
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/min/admin.css', array(), $this->version, 'all' );
87
+ }
88
+
89
+ }
90
+
91
+
92
+ /**
93
+ * Register the scripts for the Dashboard.
94
+ *
95
+ * This function is used to register all the required scripts for
96
+ * dashboard. Scripts will be registered only for i4t3 pages for performance.
97
+ *
98
+ * @since 2.0.0
99
+ * @uses wp_enqueue_script To register script
100
+ */
101
+ public function enqueue_scripts() {
102
+
103
+ global $pagenow;
104
+
105
+ if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings')))) {
106
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), $this->version, false );
107
+ }
108
+
109
+ }
110
+
111
+
112
+ /**
113
+ * Run upgrade functions
114
+ *
115
+ * If 404 to 301 is upgraded, we may need to perform few updations in db
116
+ *
117
+ * @since 2.0.0
118
+ * @uses get_option() To get the activation redirect option from db.
119
+ * @return void.
120
+ */
121
+ public function i4t3_upgrade_if_new() {
122
+
123
+ if ( !get_option('i4t3_version_no') || ( get_option('i4t3_version_no') < I4T3_VERSION ) ) {
124
+ if( class_exists( '_404_To_301_Activator' ) ) {
125
+ _404_To_301_Activator::activate();
126
+ }
127
+ update_option('i4t3_version_no', I4T3_VERSION );
128
+ }
129
+ }
130
+
131
+
132
+ /**
133
+ * Creating admin menus for 404 to 301.
134
+ *
135
+ * @since 2.0.0
136
+ * @author Joel James
137
+ * @uses action hook add_submenu_page Action hook to add new admin menu sub page.
138
+ */
139
+ public function i4t3_create_404_to_301_menu(){
140
+
141
+ // Error log menu
142
+ add_menu_page(
143
+ __( '404 Error Logs', '404-to-301' ),
144
+ __( '404 Error Logs', '404-to-301' ),
145
+ I4T3_ADMIN_PERMISSION,
146
+ 'i4t3-logs',
147
+ array( $this,'i4t3_render_list_page' ),
148
+ 'dashicons-redo',
149
+ 90
150
+ );
151
+
152
+ // 404 to 301 settings menu
153
+ add_submenu_page(
154
+ 'i4t3-logs',
155
+ __( '404 to 301 Settings', '404-to-301' ),
156
+ '404 Settings',
157
+ I4T3_ADMIN_PERMISSION,
158
+ 'i4t3-settings',
159
+ array( $this, 'i4t3_admin_page' )
160
+ );
161
+ }
162
+
163
+
164
+
165
+ /**
166
+ * Creating log table page.
167
+ *
168
+ * @since 2.0.0
169
+ * @author Joel James
170
+ * @uses class _404_To_301_Logs To initialize and load the log listing table.
171
+ */
172
+ public function i4t3_render_list_page(){
173
+
174
+ global $i4t3_errorlogtable;
175
+ $i4t3_errorlogtable = new _404_To_301_Logs( $this->table );
176
+ echo '<div class="wrap"><h2>'. __( '404 Error Logs', '404-to-301' ) .'</h2>';
177
+ $i4t3_errorlogtable->prepare_items();
178
+ echo '<form method="post">
179
+ <input type="hidden" name="page" value="i4t3_logs_list">';
180
+ $i4t3_errorlogtable->display();
181
+ echo '</form></div>';
182
+ }
183
+
184
+
185
+ /**
186
+ * Rename admin menu text to : 404 to 301.
187
+ *
188
+ * @since 2.0.0
189
+ * @author Joel James
190
+ * @var global $menu menus registered in this site.
191
+ */
192
+ public function i4t3_rename_plugin_menu() {
193
+ global $menu;
194
+ $menu[90][0] = __( '404 to 301', '404-to-301' ); // Change menu text
195
+ }
196
+
197
+
198
+ /**
199
+ * Admin options page display.
200
+ *
201
+ * Includes admin page contents to manage i4t3 settings.
202
+ * All html parts will be included in this page.
203
+ *
204
+ * @since 2.0.0
205
+ * @author Joel James
206
+ */
207
+ public function i4t3_admin_page() {
208
+
209
+ require plugin_dir_path( __FILE__ ) . 'partials/404-to-301-admin-display.php';
210
+ }
211
+
212
+
213
+ /**
214
+ * Registering i4t3 options.
215
+ * This function is used to register all settings options to the db using
216
+ * WordPress settings API.
217
+ * If we want to register another setting, we can include that here.
218
+ *
219
+ * @since 2.0.0
220
+ * @author Joel James
221
+ * @action hooks register_setting Hook to register i4t3 options in db.
222
+ */
223
+ public function i4t3_options_register(){
224
+
225
+ register_setting(
226
+ 'i4t3_gnrl_options',
227
+ 'i4t3_gnrl_options'
228
+ );
229
+
230
+ }
231
+
232
+
233
+ /**
234
+ * Custom footer text for i4t3 pages.
235
+ *
236
+ * Function to alter the default footer text to show i4t3 credits only on i4t3 pages.
237
+ *
238
+ * @since 2.0.0
239
+ * @author Joel James
240
+ */
241
+ function i4t3_dashboard_footer () {
242
+
243
+ global $pagenow;
244
+ if (( $pagenow == 'admin.php' ) && ( in_array ( $_GET['page'], array('i4t3-settings', 'i4t3-logs')))) {
245
+
246
+ _e( 'Thank you for choosing 404 to 301 to improve your website', '404-to-301' );
247
+ echo ' | Kindly give this plugin a <a href="https://wordpress.org/support/view/plugin-reviews/404-to-301?filter=5#postform">rating &#9733; &#9733;</a>';
248
+ } else {
249
+ return;
250
+ }
251
+ }
252
+
253
+
254
+ /**
255
+ * Custom Plugin Action Link.
256
+ *
257
+ * Function to add a quick link to i4t3, when being listed on your
258
+ * plugins list view.
259
+ *
260
+ * @since 2.0.0
261
+ * @return $links Links to display.
262
+ * @author Joel James
263
+ */
264
+ public function i4t3_plugin_action_links( $links, $file ) {
265
+ $plugin_file = basename('404-to-301.php');
266
+ if (basename($file) == $plugin_file) {
267
+ $settings_link = '<a href="admin.php?page=i4t3-settings">Settings</a>';
268
+ $settings_link .= ' | <a href="admin.php?page=i4t3-logs">Logs</a>';
269
+ array_unshift($links, $settings_link);
270
+ }
271
+ return $links;
272
+ }
273
+
274
+
275
+ /**
276
+ * Get debug data.
277
+ *
278
+ * Function to output the debug data for the plugin. This will be useful
279
+ * when asking for support. Just copy and paste these data to the email.
280
+ *
281
+ * @since 2.0.0
282
+ * @var array $gnrl_options Array of plugin settings
283
+ * @var array $active_plugins Array of active plugins path
284
+ * @return $html Html content to diplay.
285
+ * @author Joel James
286
+ */
287
+ public function i4t3_get_debug_data() {
288
+
289
+ $html = '';
290
+ $gnrl_options = get_option('i4t3_gnrl_options');
291
+ $active_plugins = get_option ( 'active_plugins', array () );
292
+ $active_theme = wp_get_theme();
293
+
294
+ // Dump the plugin settings data
295
+ if( !empty( $gnrl_options ) ) {
296
+ $html .= '<h4>Settings Data</h4>
297
+ <p><pre>';
298
+ foreach ( $gnrl_options as $key => $option ) {
299
+ $html .= $key.' : '.$option.'<br/>';
300
+ }
301
+ $html .= '</pre></p><hr/>';
302
+ }
303
+ // Output basic info about the site
304
+ $html .= '<h4>Basic Details</h4>
305
+ <p>
306
+ Version of Plugin : '. $this->version .'<br/>
307
+ Home Page : '. home_url() .'<br/>
308
+ </p><hr/>';
309
+
310
+ if ( $active_theme->exists() ) {
311
+
312
+ $html .= '<h4>Active Theme Details</h4>
313
+ <p>
314
+ Name : '. $active_theme->get( 'Name' ) .'<br/>
315
+ Version : '. $active_theme->get( 'Version' ) .'<br/>
316
+ Theme URI : '. $active_theme->get( 'ThemeURI' ) .'<br/>
317
+ </p><hr/>';
318
+ }
319
+
320
+ // Dump the active plugins data
321
+ if( !empty( $active_plugins ) ) {
322
+ $html .= '<h4>Active Plugins</h4>
323
+ <p>';
324
+ foreach ( $active_plugins as $plugin ) {
325
+ $html .= $plugin.'<br/>';
326
+ }
327
+ $html .= '</p>';
328
+ }
329
+
330
+ return $html;
331
+ }
332
+
333
+
334
+ }
admin/class-404-to-301-logs.php ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * WP_List_Table is marked as private by WordPress. So they change it.
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
+
13
+ if( ! class_exists( 'WP_List_Table_404' ) ) {
14
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/core/class-wp-list-table.php';
15
+ }
16
+
17
+ /**
18
+ * The listing page class for error logs.
19
+ *
20
+ * This class defines all the methods to output the error logs display table using
21
+ * WordPress listing table class.
22
+ *
23
+ * @link http://iscode.co/product/404-to-301/
24
+ * @since 2.0.0
25
+ * @package I4T3
26
+ * @subpackage I4T3/admin
27
+ * @author Joel James <me@joelsays.com>
28
+ */
29
+ class _404_To_301_Logs extends WP_List_Table_404 {
30
+
31
+ /**
32
+ * The table name of this plugin.
33
+ *
34
+ * @since 2.0.0
35
+ * @access private
36
+ * @var string $table The table name of this plugin in db.
37
+ */
38
+ private $table;
39
+
40
+ /**
41
+ * Data to be displayed in table.
42
+ *
43
+ * @since 2.0.0
44
+ * @access private
45
+ * @var array $log_data The error log data from db.
46
+ */
47
+ private $log_data;
48
+
49
+
50
+ /**
51
+ * Initialize the class and set its properties.
52
+ *
53
+ * @since 2.0.0
54
+ * @var string $table The name of the table of plugin.
55
+ * @var array $log_data The error log data from db.
56
+ * @var global $status, $page Global variables from WordPress
57
+ */
58
+ public function __construct( $table ) {
59
+
60
+ global $status, $page;
61
+ $this->table = $table;
62
+ $this->log_data = $this->i4t3_get_log_data();
63
+
64
+ parent::__construct( array(
65
+ 'singular' => __( 'i4t3_log', __( '404 Log', '404-to-301' ) ), //singular name of the listed records
66
+ 'plural' => __( 'i4t3_logs', __( '404 Logs', '404-to-301' ) ), //plural name of the listed records
67
+ 'ajax' => false //does this table support ajax?
68
+ )
69
+ );
70
+
71
+ $this->process_bulk_action(); // To perform bulk delete action
72
+ }
73
+
74
+ /**
75
+ * Error log data to be displayed.
76
+ *
77
+ * Getting the error log data from the database and converts it to
78
+ * the required structure.
79
+ *
80
+ * @since 2.0.0
81
+ * @author Joel James.
82
+ * @var $wpdb Global variable for db class.
83
+ * @uses apply_filters i4t3_log_list_per_page Custom filter to modify per page view.
84
+ * @return array $error_data Array of error log data.
85
+ */
86
+ public function i4t3_get_log_data() {
87
+
88
+ global $wpdb;
89
+ // Let us hide sql query errors
90
+ $wpdb->hide_errors();
91
+
92
+ // Per page filter
93
+ $per_page = apply_filters( 'i4t3_log_list_per_page', 10 );
94
+
95
+ $current_page = $this->get_pagenum();
96
+ $limit = ( $current_page-1 )* $per_page;
97
+
98
+ // If no sort, default to title
99
+ $orderby = ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'date';
100
+ // If no order, default to asc
101
+ $order = ( isset($_GET['order'] ) ) ? $_GET['order'] : 'ASC';
102
+
103
+ $log_data = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS id as ID,date,url,ref,ip,ua FROM $this->table ORDER BY $orderby $order LIMIT %d,%d", array( $limit, $per_page) ), ARRAY_A );
104
+
105
+ $error_data = array();
106
+ foreach ($log_data as $key) {
107
+ $error_data[] = $key;
108
+ }
109
+
110
+ return $error_data;
111
+ }
112
+
113
+ /**
114
+ * Empty record text.
115
+ *
116
+ * Custom text to display where there is nothing to display in error
117
+ * log table.
118
+ *
119
+ * @since 2.0.0
120
+ * @author Joel James.
121
+ * @return void
122
+ */
123
+ public function no_items() {
124
+
125
+ _e( 'Ulta pulta..! Seems like you had no errors to log.' );
126
+ }
127
+
128
+
129
+ /**
130
+ * Default columns in list table.
131
+ *
132
+ * To show columns in error log list table. If there is nothing
133
+ * for switch, printing the whole array.
134
+ *
135
+ * @since 2.0.0
136
+ * @author Joel James.
137
+ * @uses switch To switch between colums.
138
+ */
139
+ public function column_default( $item, $column_name ) {
140
+
141
+ switch( $column_name ) {
142
+ case 'date':
143
+ case 'url':
144
+ case 'ref':
145
+ case 'ip':
146
+ case 'ua':
147
+ return $item[ $column_name ];
148
+ default:
149
+ return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
150
+ }
151
+ }
152
+
153
+
154
+ /**
155
+ * Make colums sortable
156
+ *
157
+ * To make our custom columns in list table sortable. We have included
158
+ * 4 columns except 'User Agent' column here.
159
+ *
160
+ * @since 2.0.0
161
+ * @author Joel James.
162
+ * @return array $sortable_columns Array of columns to enable sorting.
163
+ */
164
+ public function get_sortable_columns() {
165
+
166
+ $sortable_columns = array(
167
+ 'date' => array('date',false),
168
+ 'url' => array('url',false),
169
+ 'ref' => array('ref',false),
170
+ 'ip' => array('ip',false)
171
+ );
172
+
173
+ return $sortable_columns;
174
+ }
175
+
176
+
177
+ /**
178
+ * Column titles
179
+ *
180
+ * Custom column titles to be displayed in listing table. You can change this to anything
181
+ *
182
+ * @since 2.0.0
183
+ * @author Joel James.
184
+ * @return array $columns Array of cloumn titles.
185
+ */
186
+ public function get_columns() {
187
+
188
+ $columns = array(
189
+ 'date'=> __( 'Date and Time', '404-to-301' ),
190
+ 'url' => __( '404 Path', '404-to-301' ),
191
+ 'ref' => __( 'Came From', '404-to-301' ), // referer
192
+ 'ip' => __( 'IP Address', '404-to-301' ),
193
+ 'ua' => __( 'User Agent', '404-to-301' )
194
+ );
195
+
196
+ return $columns;
197
+ }
198
+
199
+
200
+ /**
201
+ * Bulk actions drop down
202
+ *
203
+ * Options to be added to the bulk actions drop down for users
204
+ * to select. We have added 'clear log' action.
205
+ *
206
+ * @since 2.0.0
207
+ * @author Joel James.
208
+ * @return array $actions Options to be added to the action select box.
209
+ */
210
+ public function get_bulk_actions() {
211
+
212
+ $actions = array(
213
+ 'clear' => __( 'Clear Logs', '404-to-301' )
214
+ );
215
+
216
+ return $actions;
217
+ }
218
+
219
+
220
+ /**
221
+ * To modify the date column data
222
+ *
223
+ * This function is used to modify the column data for date in listing table.
224
+ * We can change styles, texts etc. using this function.
225
+ *
226
+ * @since 2.0.0
227
+ * @author Joel James.
228
+ * @return string $date_data Date column text data.
229
+ */
230
+ public function column_date( $item ) {
231
+
232
+ // Apply filter - i4t3_log_list_date_column
233
+ $date_data = apply_filters( 'i4t3_log_list_date_column', date("j M Y, g:i a", strtotime($item['date'])) );
234
+
235
+ return $date_data;
236
+ }
237
+
238
+
239
+ /**
240
+ * To modify the url column data
241
+ *
242
+ * This function is used to modify the column data for url in listing table.
243
+ * We can change styles, texts etc. using this function.
244
+ *
245
+ * @since 2.0.0
246
+ * @author Joel James.
247
+ * @return string $url_data Url column text data.
248
+ */
249
+ public function column_url( $item ) {
250
+
251
+ // Apply filter - i4t3_log_list_url_column
252
+ $url_data = apply_filters( 'i4t3_log_list_url_column', '<p class="i4t3-url-p">'.$item['url'].'</p>' );
253
+
254
+ return $url_data;
255
+ }
256
+
257
+
258
+ /**
259
+ * To modify the ref column data
260
+ *
261
+ * This function is used to modify the column data for ref in listing table.
262
+ * We can change styles, texts etc. using this function.
263
+ *
264
+ * @since 2.0.0
265
+ * @author Joel James.
266
+ * @return string $ref_data Ref column text data.
267
+ */
268
+ public function column_ref( $item ) {
269
+
270
+ // Apply filter - i4t3_log_list_ref_column
271
+ $ref_data = apply_filters( 'i4t3_log_list_ref_column', '<a href="'.$item['ref'].'">'.$item['ref'].'</a>' );
272
+
273
+ return $ref_data;
274
+ }
275
+
276
+
277
+ /**
278
+ * Main function to output the listing table using WP_List_Table class
279
+ *
280
+ * As name says, this function is used to prepare the lsting table based
281
+ * on the custom rules and filters that we have given.
282
+ * This function extends the lsiting table class and uses our custom data
283
+ * to list in the table.
284
+ * Here we set pagination, columns, sorting etc.
285
+ * $this->items - Push our custom log data to the listing table.
286
+ *
287
+ * @since 2.0.0
288
+ * @author Joel James.
289
+ * @uses $wpdb The global variable for WordPress database operations.
290
+ * @uses hide_errors() To hide if there are SQL query errors.
291
+ */
292
+ public function prepare_items() {
293
+
294
+ global $wpdb;
295
+ // Let us hide sql query errors
296
+ $wpdb->hide_errors();
297
+
298
+ $columns = $this->get_columns();
299
+ $hidden = array();
300
+ $sortable = $this->get_sortable_columns();
301
+ $this->_column_headers = array( $columns, $hidden, $sortable );
302
+
303
+ $current_page = $this->get_pagenum();
304
+
305
+ // Per page filter
306
+ $per_page = apply_filters( 'i4t3_log_list_per_page', 10 );
307
+
308
+ $total = $wpdb->get_var( "SELECT count(id) as ID FROM $this->table" );
309
+
310
+ if( $total ) {
311
+ $total_items = $total;
312
+ } else {
313
+ $total_items = count( $this->log_data );
314
+ }
315
+
316
+ // only ncessary because we have sample data
317
+ $this->set_pagination_args( array(
318
+ 'total_items' => $total_items, //WE have to calculate the total number of items
319
+ 'per_page' => $per_page //WE have to determine how many items to show on a page
320
+ )
321
+ );
322
+
323
+ $this->items = $this->log_data;
324
+ }
325
+
326
+
327
+ /**
328
+ * To perform bulk actions.
329
+ *
330
+ * This function is used to check if bulk action is set in post.
331
+ * If set it will call the required functions to perform the task.
332
+ *
333
+ * @since 2.0.0
334
+ * @author Joel James.
335
+ * @uses wp_verify_nonce To verify if the request is from WordPress.
336
+ */
337
+ public function process_bulk_action() {
338
+
339
+ if( isset($_POST['_wpnonce'])) {
340
+
341
+ $nonce = '';
342
+ $action = '';
343
+ // security check!
344
+ if ( ! empty( $_POST['_wpnonce'] ) ) {
345
+
346
+ $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
347
+ $action = 'bulk-' . $this->_args['plural'];
348
+ }
349
+
350
+ if ( ! wp_verify_nonce( $nonce, $action ) )
351
+ wp_die( 'Nope! Security check failed!' );
352
+
353
+ $action = $this->current_action();
354
+
355
+ switch ( $action ) {
356
+
357
+ case 'clear':
358
+ $this->clear_404_logs();
359
+ break;
360
+
361
+ default:
362
+ return;
363
+ break;
364
+ }
365
+ }
366
+
367
+ }
368
+
369
+ /**
370
+ * To perform clear logs.
371
+ *
372
+ * This function is used to clear the entire log from db. This function is called
373
+ * from process_bulk_action() method.
374
+ * This function will delete the entire data from our log table and this can't be UNDONE.
375
+ *
376
+ * @since 2.0.0
377
+ * @author Joel James.
378
+ * @retun true if deleted something, else false.
379
+ */
380
+ public function clear_404_logs() {
381
+
382
+ global $wpdb;
383
+ // Let us hide sql query errors if any
384
+ $wpdb->hide_errors();
385
+ $total = $wpdb->query( "DELETE FROM $this->table" );
386
+ return ( $total > 0 ) ? true : false;
387
+ }
388
+
389
+ }
admin/core/class-wp-list-table.php ADDED
@@ -0,0 +1,1143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Base class for displaying a list of items in an ajaxified HTML table.
4
+ * We are not using this class from core WordPress since it is not
5
+ * recommended by WordPress itself.
6
+ *
7
+ * @since 3.1.0
8
+ * @access private
9
+ *
10
+ * @package I4T3
11
+ * @subpackage I4T3/List_Table
12
+ */
13
+ class WP_List_Table_404 {
14
+
15
+ /**
16
+ * The current list of items
17
+ *
18
+ * @since 3.1.0
19
+ * @var array
20
+ * @access public
21
+ */
22
+ public $items;
23
+
24
+ /**
25
+ * Various information about the current table
26
+ *
27
+ * @since 3.1.0
28
+ * @var array
29
+ * @access protected
30
+ */
31
+ protected $_args;
32
+
33
+ /**
34
+ * Various information needed for displaying the pagination
35
+ *
36
+ * @since 3.1.0
37
+ * @var array
38
+ */
39
+ protected $_pagination_args = array();
40
+
41
+ /**
42
+ * The current screen
43
+ *
44
+ * @since 3.1.0
45
+ * @var object
46
+ * @access protected
47
+ */
48
+ protected $screen;
49
+
50
+ /**
51
+ * Cached bulk actions
52
+ *
53
+ * @since 3.1.0
54
+ * @var array
55
+ * @access private
56
+ */
57
+ private $_actions;
58
+
59
+ /**
60
+ * Cached pagination output
61
+ *
62
+ * @since 3.1.0
63
+ * @var string
64
+ * @access private
65
+ */
66
+ private $_pagination;
67
+
68
+ /**
69
+ * The view switcher modes.
70
+ *
71
+ * @since 4.1.0
72
+ * @var array
73
+ * @access protected
74
+ */
75
+ protected $modes = array();
76
+
77
+ /**
78
+ * Stores the value returned by ->get_column_info()
79
+ *
80
+ * @var array
81
+ */
82
+ protected $_column_headers;
83
+
84
+ protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
85
+
86
+ protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
87
+ 'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
88
+ 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
89
+ 'single_row_columns' );
90
+
91
+ /**
92
+ * Constructor.
93
+ *
94
+ * The child class should call this constructor from its own constructor to override
95
+ * the default $args.
96
+ *
97
+ * @since 3.1.0
98
+ * @access public
99
+ *
100
+ * @param array|string $args {
101
+ * Array or string of arguments.
102
+ *
103
+ * @type string $plural Plural value used for labels and the objects being listed.
104
+ * This affects things such as CSS class-names and nonces used
105
+ * in the list table, e.g. 'posts'. Default empty.
106
+ * @type string $singular Singular label for an object being listed, e.g. 'post'.
107
+ * Default empty
108
+ * @type bool $ajax Whether the list table supports AJAX. This includes loading
109
+ * and sorting data, for example. If true, the class will call
110
+ * the {@see _js_vars()} method in the footer to provide variables
111
+ * to any scripts handling AJAX events. Default false.
112
+ * @type string $screen String containing the hook name used to determine the current
113
+ * screen. If left null, the current screen will be automatically set.
114
+ * Default null.
115
+ * }
116
+ */
117
+ public function __construct( $args = array() ) {
118
+ $args = wp_parse_args( $args, array(
119
+ 'plural' => '',
120
+ 'singular' => '',
121
+ 'ajax' => false,
122
+ 'screen' => null,
123
+ ) );
124
+
125
+ $this->screen = convert_to_screen( $args['screen'] );
126
+
127
+ add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
128
+
129
+ if ( !$args['plural'] )
130
+ $args['plural'] = $this->screen->base;
131
+
132
+ $args['plural'] = sanitize_key( $args['plural'] );
133
+ $args['singular'] = sanitize_key( $args['singular'] );
134
+
135
+ $this->_args = $args;
136
+
137
+ if ( $args['ajax'] ) {
138
+ // wp_enqueue_script( 'list-table' );
139
+ add_action( 'admin_footer', array( $this, '_js_vars' ) );
140
+ }
141
+
142
+ if ( empty( $this->modes ) ) {
143
+ $this->modes = array(
144
+ 'list' => __( 'List View' ),
145
+ 'excerpt' => __( 'Excerpt View' )
146
+ );
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Make private properties readable for backwards compatibility.
152
+ *
153
+ * @since 4.0.0
154
+ * @access public
155
+ *
156
+ * @param string $name Property to get.
157
+ * @return mixed Property.
158
+ */
159
+ public function __get( $name ) {
160
+ if ( in_array( $name, $this->compat_fields ) ) {
161
+ return $this->$name;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Make private properties settable for backwards compatibility.
167
+ *
168
+ * @since 4.0.0
169
+ * @access public
170
+ *
171
+ * @param string $name Property to check if set.
172
+ * @param mixed $value Property value.
173
+ * @return mixed Newly-set property.
174
+ */
175
+ public function __set( $name, $value ) {
176
+ if ( in_array( $name, $this->compat_fields ) ) {
177
+ return $this->$name = $value;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Make private properties checkable for backwards compatibility.
183
+ *
184
+ * @since 4.0.0
185
+ * @access public
186
+ *
187
+ * @param string $name Property to check if set.
188
+ * @return bool Whether the property is set.
189
+ */
190
+ public function __isset( $name ) {
191
+ if ( in_array( $name, $this->compat_fields ) ) {
192
+ return isset( $this->$name );
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Make private properties un-settable for backwards compatibility.
198
+ *
199
+ * @since 4.0.0
200
+ * @access public
201
+ *
202
+ * @param string $name Property to unset.
203
+ */
204
+ public function __unset( $name ) {
205
+ if ( in_array( $name, $this->compat_fields ) ) {
206
+ unset( $this->$name );
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Make private/protected methods readable for backwards compatibility.
212
+ *
213
+ * @since 4.0.0
214
+ * @access public
215
+ *
216
+ * @param callable $name Method to call.
217
+ * @param array $arguments Arguments to pass when calling.
218
+ * @return mixed|bool Return value of the callback, false otherwise.
219
+ */
220
+ public function __call( $name, $arguments ) {
221
+ if ( in_array( $name, $this->compat_methods ) ) {
222
+ return call_user_func_array( array( $this, $name ), $arguments );
223
+ }
224
+ return false;
225
+ }
226
+
227
+ /**
228
+ * Checks the current user's permissions
229
+ *
230
+ * @since 3.1.0
231
+ * @access public
232
+ * @abstract
233
+ */
234
+ public function ajax_user_can() {
235
+ die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
236
+ }
237
+
238
+ /**
239
+ * Prepares the list of items for displaying.
240
+ * @uses WP_List_Table::set_pagination_args()
241
+ *
242
+ * @since 3.1.0
243
+ * @access public
244
+ * @abstract
245
+ */
246
+ public function prepare_items() {
247
+ die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
248
+ }
249
+
250
+ /**
251
+ * An internal method that sets all the necessary pagination arguments
252
+ *
253
+ * @param array $args An associative array with information about the pagination
254
+ * @access protected
255
+ */
256
+ protected function set_pagination_args( $args ) {
257
+ $args = wp_parse_args( $args, array(
258
+ 'total_items' => 0,
259
+ 'total_pages' => 0,
260
+ 'per_page' => 0,
261
+ ) );
262
+
263
+ if ( !$args['total_pages'] && $args['per_page'] > 0 )
264
+ $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
265
+
266
+ // Redirect if page number is invalid and headers are not already sent.
267
+ if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
268
+ wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
269
+ exit;
270
+ }
271
+
272
+ $this->_pagination_args = $args;
273
+ }
274
+
275
+ /**
276
+ * Access the pagination args.
277
+ *
278
+ * @since 3.1.0
279
+ * @access public
280
+ *
281
+ * @param string $key Pagination argument to retrieve. Common values include 'total_items',
282
+ * 'total_pages', 'per_page', or 'infinite_scroll'.
283
+ * @return int Number of items that correspond to the given pagination argument.
284
+ */
285
+ public function get_pagination_arg( $key ) {
286
+ if ( 'page' == $key )
287
+ return $this->get_pagenum();
288
+
289
+ if ( isset( $this->_pagination_args[$key] ) )
290
+ return $this->_pagination_args[$key];
291
+ }
292
+
293
+ /**
294
+ * Whether the table has items to display or not
295
+ *
296
+ * @since 3.1.0
297
+ * @access public
298
+ *
299
+ * @return bool
300
+ */
301
+ public function has_items() {
302
+ return !empty( $this->items );
303
+ }
304
+
305
+ /**
306
+ * Message to be displayed when there are no items
307
+ *
308
+ * @since 3.1.0
309
+ * @access public
310
+ */
311
+ public function no_items() {
312
+ _e( 'No items found.' );
313
+ }
314
+
315
+ /**
316
+ * Display the search box.
317
+ *
318
+ * @since 3.1.0
319
+ * @access public
320
+ *
321
+ * @param string $text The search button text
322
+ * @param string $input_id The search input id
323
+ */
324
+ public function search_box( $text, $input_id ) {
325
+ if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
326
+ return;
327
+
328
+ $input_id = $input_id . '-search-input';
329
+
330
+ if ( ! empty( $_REQUEST['orderby'] ) )
331
+ echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
332
+ if ( ! empty( $_REQUEST['order'] ) )
333
+ echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
334
+ if ( ! empty( $_REQUEST['post_mime_type'] ) )
335
+ echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
336
+ if ( ! empty( $_REQUEST['detached'] ) )
337
+ echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
338
+ ?>
339
+ <p class="search-box">
340
+ <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
341
+ <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
342
+ <?php submit_button( $text, 'button', '', false, array('id' => 'search-submit') ); ?>
343
+ </p>
344
+ <?php
345
+ }
346
+
347
+ /**
348
+ * Get an associative array ( id => link ) with the list
349
+ * of views available on this table.
350
+ *
351
+ * @since 3.1.0
352
+ * @access protected
353
+ *
354
+ * @return array
355
+ */
356
+ protected function get_views() {
357
+ return array();
358
+ }
359
+
360
+ /**
361
+ * Display the list of views available on this table.
362
+ *
363
+ * @since 3.1.0
364
+ * @access public
365
+ */
366
+ public function views() {
367
+ $views = $this->get_views();
368
+ /**
369
+ * Filter the list of available list table views.
370
+ *
371
+ * The dynamic portion of the hook name, `$this->screen->id`, refers
372
+ * to the ID of the current screen, usually a string.
373
+ *
374
+ * @since 3.5.0
375
+ *
376
+ * @param array $views An array of available list table views.
377
+ */
378
+ $views = apply_filters( "views_{$this->screen->id}", $views );
379
+
380
+ if ( empty( $views ) )
381
+ return;
382
+
383
+ echo "<ul class='subsubsub'>\n";
384
+ foreach ( $views as $class => $view ) {
385
+ $views[ $class ] = "\t<li class='$class'>$view";
386
+ }
387
+ echo implode( " |</li>\n", $views ) . "</li>\n";
388
+ echo "</ul>";
389
+ }
390
+
391
+ /**
392
+ * Get an associative array ( option_name => option_title ) with the list
393
+ * of bulk actions available on this table.
394
+ *
395
+ * @since 3.1.0
396
+ * @access protected
397
+ *
398
+ * @return array
399
+ */
400
+ protected function get_bulk_actions() {
401
+ return array();
402
+ }
403
+
404
+ /**
405
+ * Display the bulk actions dropdown.
406
+ *
407
+ * @since 3.1.0
408
+ * @access protected
409
+ *
410
+ * @param string $which The location of the bulk actions: 'top' or 'bottom'.
411
+ * This is designated as optional for backwards-compatibility.
412
+ */
413
+ protected function bulk_actions( $which = '' ) {
414
+ if ( is_null( $this->_actions ) ) {
415
+ $no_new_actions = $this->_actions = $this->get_bulk_actions();
416
+ /**
417
+ * Filter the list table Bulk Actions drop-down.
418
+ *
419
+ * The dynamic portion of the hook name, `$this->screen->id`, refers
420
+ * to the ID of the current screen, usually a string.
421
+ *
422
+ * This filter can currently only be used to remove bulk actions.
423
+ *
424
+ * @since 3.5.0
425
+ *
426
+ * @param array $actions An array of the available bulk actions.
427
+ */
428
+ $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
429
+ $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
430
+ $two = '';
431
+ } else {
432
+ $two = '2';
433
+ }
434
+
435
+ if ( empty( $this->_actions ) )
436
+ return;
437
+
438
+ echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . __( 'Select bulk action' ) . "</label>";
439
+ echo "<select name='action$two' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
440
+ echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
441
+
442
+ foreach ( $this->_actions as $name => $title ) {
443
+ $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
444
+
445
+ echo "\t<option value='$name'$class>$title</option>\n";
446
+ }
447
+
448
+ echo "</select>\n";
449
+
450
+ submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
451
+ echo "\n";
452
+ }
453
+
454
+ /**
455
+ * Get the current action selected from the bulk actions dropdown.
456
+ *
457
+ * @since 3.1.0
458
+ * @access public
459
+ *
460
+ * @return string|bool The action name or False if no action was selected
461
+ */
462
+ public function current_action() {
463
+ if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
464
+ return false;
465
+
466
+ if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
467
+ return $_REQUEST['action'];
468
+
469
+ if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
470
+ return $_REQUEST['action2'];
471
+
472
+ return false;
473
+ }
474
+
475
+ /**
476
+ * Generate row actions div
477
+ *
478
+ * @since 3.1.0
479
+ * @access protected
480
+ *
481
+ * @param array $actions The list of actions
482
+ * @param bool $always_visible Whether the actions should be always visible
483
+ * @return string
484
+ */
485
+ protected function row_actions( $actions, $always_visible = false ) {
486
+ $action_count = count( $actions );
487
+ $i = 0;
488
+
489
+ if ( !$action_count )
490
+ return '';
491
+
492
+ $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
493
+ foreach ( $actions as $action => $link ) {
494
+ ++$i;
495
+ ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
496
+ $out .= "<span class='$action'>$link$sep</span>";
497
+ }
498
+ $out .= '</div>';
499
+
500
+ return $out;
501
+ }
502
+
503
+ /**
504
+ * Display a monthly dropdown for filtering items
505
+ *
506
+ * @since 3.1.0
507
+ * @access protected
508
+ *
509
+ * @param string $post_type
510
+ */
511
+ protected function months_dropdown( $post_type ) {
512
+ global $wpdb, $wp_locale;
513
+
514
+ /**
515
+ * Filter whether to remove the 'Months' drop-down from the post list table.
516
+ *
517
+ * @since 4.2.0
518
+ *
519
+ * @param bool $disable Whether to disable the drop-down. Default false.
520
+ * @param string $post_type The post type.
521
+ */
522
+ if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
523
+ return;
524
+ }
525
+
526
+ $months = $wpdb->get_results( $wpdb->prepare( "
527
+ SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
528
+ FROM $wpdb->posts
529
+ WHERE post_type = %s
530
+ ORDER BY post_date DESC
531
+ ", $post_type ) );
532
+
533
+ /**
534
+ * Filter the 'Months' drop-down results.
535
+ *
536
+ * @since 3.7.0
537
+ *
538
+ * @param object $months The months drop-down query results.
539
+ * @param string $post_type The post type.
540
+ */
541
+ $months = apply_filters( 'months_dropdown_results', $months, $post_type );
542
+
543
+ $month_count = count( $months );
544
+
545
+ if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
546
+ return;
547
+
548
+ $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
549
+ ?>
550
+ <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
551
+ <select name="m" id="filter-by-date">
552
+ <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
553
+ <?php
554
+ foreach ( $months as $arc_row ) {
555
+ if ( 0 == $arc_row->year )
556
+ continue;
557
+
558
+ $month = zeroise( $arc_row->month, 2 );
559
+ $year = $arc_row->year;
560
+
561
+ printf( "<option %s value='%s'>%s</option>\n",
562
+ selected( $m, $year . $month, false ),
563
+ esc_attr( $arc_row->year . $month ),
564
+ /* translators: 1: month name, 2: 4-digit year */
565
+ sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
566
+ );
567
+ }
568
+ ?>
569
+ </select>
570
+ <?php
571
+ }
572
+
573
+ /**
574
+ * Display a view switcher
575
+ *
576
+ * @since 3.1.0
577
+ * @access protected
578
+ *
579
+ * @param string $current_mode
580
+ */
581
+ protected function view_switcher( $current_mode ) {
582
+ ?>
583
+ <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
584
+ <div class="view-switch">
585
+ <?php
586
+ foreach ( $this->modes as $mode => $title ) {
587
+ $classes = array( 'view-' . $mode );
588
+ if ( $current_mode == $mode )
589
+ $classes[] = 'current';
590
+ printf(
591
+ "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
592
+ esc_url( add_query_arg( 'mode', $mode ) ),
593
+ implode( ' ', $classes ),
594
+ $title
595
+ );
596
+ }
597
+ ?>
598
+ </div>
599
+ <?php
600
+ }
601
+
602
+ /**
603
+ * Display a comment count bubble
604
+ *
605
+ * @since 3.1.0
606
+ * @access protected
607
+ *
608
+ * @param int $post_id The post ID.
609
+ * @param int $pending_comments Number of pending comments.
610
+ */
611
+ protected function comments_bubble( $post_id, $pending_comments ) {
612
+ $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) );
613
+
614
+ if ( $pending_comments )
615
+ echo '<strong>';
616
+
617
+ echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . "</span></a>";
618
+
619
+ if ( $pending_comments )
620
+ echo '</strong>';
621
+ }
622
+
623
+ /**
624
+ * Get the current page number
625
+ *
626
+ * @since 3.1.0
627
+ * @access public
628
+ *
629
+ * @return int
630
+ */
631
+ public function get_pagenum() {
632
+ $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
633
+
634
+ if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
635
+ $pagenum = $this->_pagination_args['total_pages'];
636
+
637
+ return max( 1, $pagenum );
638
+ }
639
+
640
+ /**
641
+ * Get number of items to display on a single page
642
+ *
643
+ * @since 3.1.0
644
+ * @access protected
645
+ *
646
+ * @param string $option
647
+ * @param int $default
648
+ * @return int
649
+ */
650
+ protected function get_items_per_page( $option, $default = 20 ) {
651
+ $per_page = (int) get_user_option( $option );
652
+ if ( empty( $per_page ) || $per_page < 1 )
653
+ $per_page = $default;
654
+
655
+ /**
656
+ * Filter the number of items to be displayed on each page of the list table.
657
+ *
658
+ * The dynamic hook name, $option, refers to the `per_page` option depending
659
+ * on the type of list table in use. Possible values include: 'edit_comments_per_page',
660
+ * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
661
+ * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
662
+ * 'edit_{$post_type}_per_page', etc.
663
+ *
664
+ * @since 2.9.0
665
+ *
666
+ * @param int $per_page Number of items to be displayed. Default 20.
667
+ */
668
+ return (int) apply_filters( $option, $per_page );
669
+ }
670
+
671
+ /**
672
+ * Display the pagination.
673
+ *
674
+ * @since 3.1.0
675
+ * @access protected
676
+ *
677
+ * @param string $which
678
+ */
679
+ protected function pagination( $which ) {
680
+ if ( empty( $this->_pagination_args ) ) {
681
+ return;
682
+ }
683
+
684
+ $total_items = $this->_pagination_args['total_items'];
685
+ $total_pages = $this->_pagination_args['total_pages'];
686
+ $infinite_scroll = false;
687
+ if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
688
+ $infinite_scroll = $this->_pagination_args['infinite_scroll'];
689
+ }
690
+
691
+ $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
692
+
693
+ $current = $this->get_pagenum();
694
+
695
+ $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
696
+
697
+ $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
698
+
699
+ $page_links = array();
700
+
701
+ $disable_first = $disable_last = '';
702
+ if ( $current == 1 ) {
703
+ $disable_first = ' disabled';
704
+ }
705
+ if ( $current == $total_pages ) {
706
+ $disable_last = ' disabled';
707
+ }
708
+ $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
709
+ 'first-page' . $disable_first,
710
+ esc_attr__( 'Go to the first page' ),
711
+ esc_url( remove_query_arg( 'paged', $current_url ) ),
712
+ '&laquo;'
713
+ );
714
+
715
+ $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
716
+ 'prev-page' . $disable_first,
717
+ esc_attr__( 'Go to the previous page' ),
718
+ esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
719
+ '&lsaquo;'
720
+ );
721
+
722
+ if ( 'bottom' == $which ) {
723
+ $html_current_page = $current;
724
+ } else {
725
+ $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' title='%s' type='text' name='paged' value='%s' size='%d' />",
726
+ '<label for="current-page-selector" class="screen-reader-text">' . __( 'Select Page' ) . '</label>',
727
+ esc_attr__( 'Current page' ),
728
+ $current,
729
+ strlen( $total_pages )
730
+ );
731
+ }
732
+ $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
733
+ $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
734
+
735
+ $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
736
+ 'next-page' . $disable_last,
737
+ esc_attr__( 'Go to the next page' ),
738
+ esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
739
+ '&rsaquo;'
740
+ );
741
+
742
+ $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
743
+ 'last-page' . $disable_last,
744
+ esc_attr__( 'Go to the last page' ),
745
+ esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
746
+ '&raquo;'
747
+ );
748
+
749
+ $pagination_links_class = 'pagination-links';
750
+ if ( ! empty( $infinite_scroll ) ) {
751
+ $pagination_links_class = ' hide-if-js';
752
+ }
753
+ $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
754
+
755
+ if ( $total_pages ) {
756
+ $page_class = $total_pages < 2 ? ' one-page' : '';
757
+ } else {
758
+ $page_class = ' no-pages';
759
+ }
760
+ $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
761
+
762
+ echo $this->_pagination;
763
+ }
764
+
765
+ /**
766
+ * Get a list of columns. The format is:
767
+ * 'internal-name' => 'Title'
768
+ *
769
+ * @since 3.1.0
770
+ * @access public
771
+ * @abstract
772
+ *
773
+ * @return array
774
+ */
775
+ public function get_columns() {
776
+ die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
777
+ }
778
+
779
+ /**
780
+ * Get a list of sortable columns. The format is:
781
+ * 'internal-name' => 'orderby'
782
+ * or
783
+ * 'internal-name' => array( 'orderby', true )
784
+ *
785
+ * The second format will make the initial sorting order be descending
786
+ *
787
+ * @since 3.1.0
788
+ * @access protected
789
+ *
790
+ * @return array
791
+ */
792
+ protected function get_sortable_columns() {
793
+ return array();
794
+ }
795
+
796
+ /**
797
+ * Get a list of all, hidden and sortable columns, with filter applied
798
+ *
799
+ * @since 3.1.0
800
+ * @access protected
801
+ *
802
+ * @return array
803
+ */
804
+ protected function get_column_info() {
805
+ if ( isset( $this->_column_headers ) )
806
+ return $this->_column_headers;
807
+
808
+ $columns = get_column_headers( $this->screen );
809
+ $hidden = get_hidden_columns( $this->screen );
810
+
811
+ $sortable_columns = $this->get_sortable_columns();
812
+ /**
813
+ * Filter the list table sortable columns for a specific screen.
814
+ *
815
+ * The dynamic portion of the hook name, `$this->screen->id`, refers
816
+ * to the ID of the current screen, usually a string.
817
+ *
818
+ * @since 3.5.0
819
+ *
820
+ * @param array $sortable_columns An array of sortable columns.
821
+ */
822
+ $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
823
+
824
+ $sortable = array();
825
+ foreach ( $_sortable as $id => $data ) {
826
+ if ( empty( $data ) )
827
+ continue;
828
+
829
+ $data = (array) $data;
830
+ if ( !isset( $data[1] ) )
831
+ $data[1] = false;
832
+
833
+ $sortable[$id] = $data;
834
+ }
835
+
836
+ $this->_column_headers = array( $columns, $hidden, $sortable );
837
+
838
+ return $this->_column_headers;
839
+ }
840
+
841
+ /**
842
+ * Return number of visible columns
843
+ *
844
+ * @since 3.1.0
845
+ * @access public
846
+ *
847
+ * @return int
848
+ */
849
+ public function get_column_count() {
850
+ list ( $columns, $hidden ) = $this->get_column_info();
851
+ $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
852
+ return count( $columns ) - count( $hidden );
853
+ }
854
+
855
+ /**
856
+ * Print column headers, accounting for hidden and sortable columns.
857
+ *
858
+ * @since 3.1.0
859
+ * @access public
860
+ *
861
+ * @param bool $with_id Whether to set the id attribute or not
862
+ */
863
+ public function print_column_headers( $with_id = true ) {
864
+ list( $columns, $hidden, $sortable ) = $this->get_column_info();
865
+
866
+ $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
867
+ $current_url = remove_query_arg( 'paged', $current_url );
868
+
869
+ if ( isset( $_GET['orderby'] ) )
870
+ $current_orderby = $_GET['orderby'];
871
+ else
872
+ $current_orderby = '';
873
+
874
+ if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
875
+ $current_order = 'desc';
876
+ else
877
+ $current_order = 'asc';
878
+
879
+ if ( ! empty( $columns['cb'] ) ) {
880
+ static $cb_counter = 1;
881
+ $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
882
+ . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
883
+ $cb_counter++;
884
+ }
885
+
886
+ foreach ( $columns as $column_key => $column_display_name ) {
887
+ $class = array( 'manage-column', "column-$column_key" );
888
+
889
+ $style = '';
890
+ if ( in_array( $column_key, $hidden ) )
891
+ $style = 'display:none;';
892
+
893
+ $style = ' style="' . $style . '"';
894
+
895
+ if ( 'cb' == $column_key )
896
+ $class[] = 'check-column';
897
+ elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
898
+ $class[] = 'num';
899
+
900
+ if ( isset( $sortable[$column_key] ) ) {
901
+ list( $orderby, $desc_first ) = $sortable[$column_key];
902
+
903
+ if ( $current_orderby == $orderby ) {
904
+ $order = 'asc' == $current_order ? 'desc' : 'asc';
905
+ $class[] = 'sorted';
906
+ $class[] = $current_order;
907
+ } else {
908
+ $order = $desc_first ? 'desc' : 'asc';
909
+ $class[] = 'sortable';
910
+ $class[] = $desc_first ? 'asc' : 'desc';
911
+ }
912
+
913
+ $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
914
+ }
915
+
916
+ $id = $with_id ? "id='$column_key'" : '';
917
+
918
+ if ( !empty( $class ) )
919
+ $class = "class='" . join( ' ', $class ) . "'";
920
+
921
+ echo "<th scope='col' $id $class $style>$column_display_name</th>";
922
+ }
923
+ }
924
+
925
+ /**
926
+ * Display the table
927
+ *
928
+ * @since 3.1.0
929
+ * @access public
930
+ */
931
+ public function display() {
932
+ $singular = $this->_args['singular'];
933
+
934
+ $this->display_tablenav( 'top' );
935
+
936
+ ?>
937
+ <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
938
+ <thead>
939
+ <tr>
940
+ <?php $this->print_column_headers(); ?>
941
+ </tr>
942
+ </thead>
943
+
944
+ <tbody id="the-list"<?php
945
+ if ( $singular ) {
946
+ echo " data-wp-lists='list:$singular'";
947
+ } ?>>
948
+ <?php $this->display_rows_or_placeholder(); ?>
949
+ </tbody>
950
+
951
+ <tfoot>
952
+ <tr>
953
+ <?php $this->print_column_headers( false ); ?>
954
+ </tr>
955
+ </tfoot>
956
+
957
+ </table>
958
+ <?php
959
+ $this->display_tablenav( 'bottom' );
960
+ }
961
+
962
+ /**
963
+ * Get a list of CSS classes for the list table table tag.
964
+ *
965
+ * @since 3.1.0
966
+ * @access protected
967
+ *
968
+ * @return array List of CSS classes for the table tag.
969
+ */
970
+ protected function get_table_classes() {
971
+ return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
972
+ }
973
+
974
+ /**
975
+ * Generate the table navigation above or below the table
976
+ *
977
+ * @since 3.1.0
978
+ * @access protected
979
+ * @param string $which
980
+ */
981
+ protected function display_tablenav( $which ) {
982
+ if ( 'top' == $which )
983
+ wp_nonce_field( 'bulk-' . $this->_args['plural'] );
984
+ ?>
985
+ <div class="tablenav <?php echo esc_attr( $which ); ?>">
986
+
987
+ <div class="alignleft actions bulkactions">
988
+ <?php $this->bulk_actions( $which ); ?>
989
+ </div>
990
+ <?php
991
+ $this->extra_tablenav( $which );
992
+ $this->pagination( $which );
993
+ ?>
994
+
995
+ <br class="clear" />
996
+ </div>
997
+ <?php
998
+ }
999
+
1000
+ /**
1001
+ * Extra controls to be displayed between bulk actions and pagination
1002
+ *
1003
+ * @since 3.1.0
1004
+ * @access protected
1005
+ *
1006
+ * @param string $which
1007
+ */
1008
+ protected function extra_tablenav( $which ) {}
1009
+
1010
+ /**
1011
+ * Generate the tbody element for the list table.
1012
+ *
1013
+ * @since 3.1.0
1014
+ * @access public
1015
+ */
1016
+ public function display_rows_or_placeholder() {
1017
+ if ( $this->has_items() ) {
1018
+ $this->display_rows();
1019
+ } else {
1020
+ echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1021
+ $this->no_items();
1022
+ echo '</td></tr>';
1023
+ }
1024
+ }
1025
+
1026
+ /**
1027
+ * Generate the table rows
1028
+ *
1029
+ * @since 3.1.0
1030
+ * @access public
1031
+ */
1032
+ public function display_rows() {
1033
+ foreach ( $this->items as $item )
1034
+ $this->single_row( $item );
1035
+ }
1036
+
1037
+ /**
1038
+ * Generates content for a single row of the table
1039
+ *
1040
+ * @since 3.1.0
1041
+ * @access public
1042
+ *
1043
+ * @param object $item The current item
1044
+ */
1045
+ public function single_row( $item ) {
1046
+ echo '<tr>';
1047
+ $this->single_row_columns( $item );
1048
+ echo '</tr>';
1049
+ }
1050
+
1051
+ protected function column_default( $item, $column_name ) {}
1052
+
1053
+ protected function column_cb( $item ) {}
1054
+
1055
+ /**
1056
+ * Generates the columns for a single row of the table
1057
+ *
1058
+ * @since 3.1.0
1059
+ * @access protected
1060
+ *
1061
+ * @param object $item The current item
1062
+ */
1063
+ protected function single_row_columns( $item ) {
1064
+ list( $columns, $hidden ) = $this->get_column_info();
1065
+
1066
+ foreach ( $columns as $column_name => $column_display_name ) {
1067
+ $class = "class='$column_name column-$column_name'";
1068
+
1069
+ $style = '';
1070
+ if ( in_array( $column_name, $hidden ) )
1071
+ $style = ' style="display:none;"';
1072
+
1073
+ $attributes = "$class$style";
1074
+
1075
+ if ( 'cb' == $column_name ) {
1076
+ echo '<th scope="row" class="check-column">';
1077
+ echo $this->column_cb( $item );
1078
+ echo '</th>';
1079
+ }
1080
+ elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1081
+ echo "<td $attributes>";
1082
+ echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1083
+ echo "</td>";
1084
+ }
1085
+ else {
1086
+ echo "<td $attributes>";
1087
+ echo $this->column_default( $item, $column_name );
1088
+ echo "</td>";
1089
+ }
1090
+ }
1091
+ }
1092
+
1093
+ /**
1094
+ * Handle an incoming ajax request (called from admin-ajax.php)
1095
+ *
1096
+ * @since 3.1.0
1097
+ * @access public
1098
+ */
1099
+ public function ajax_response() {
1100
+ $this->prepare_items();
1101
+
1102
+ ob_start();
1103
+ if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1104
+ $this->display_rows();
1105
+ } else {
1106
+ $this->display_rows_or_placeholder();
1107
+ }
1108
+
1109
+ $rows = ob_get_clean();
1110
+
1111
+ $response = array( 'rows' => $rows );
1112
+
1113
+ if ( isset( $this->_pagination_args['total_items'] ) ) {
1114
+ $response['total_items_i18n'] = sprintf(
1115
+ _n( '1 item', '%s items', $this->_pagination_args['total_items'] ),
1116
+ number_format_i18n( $this->_pagination_args['total_items'] )
1117
+ );
1118
+ }
1119
+ if ( isset( $this->_pagination_args['total_pages'] ) ) {
1120
+ $response['total_pages'] = $this->_pagination_args['total_pages'];
1121
+ $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1122
+ }
1123
+
1124
+ die( wp_json_encode( $response ) );
1125
+ }
1126
+
1127
+ /**
1128
+ * Send required variables to JavaScript land
1129
+ *
1130
+ * @access public
1131
+ */
1132
+ public function _js_vars() {
1133
+ $args = array(
1134
+ 'class' => get_class( $this ),
1135
+ 'screen' => array(
1136
+ 'id' => $this->screen->id,
1137
+ 'base' => $this->screen->base,
1138
+ )
1139
+ );
1140
+
1141
+ printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1142
+ }
1143
+ }
admin/css/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/css/min/admin.css ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * All of the CSS for your admin-specific functionality should be
3
+ * included in this file.
4
+ */
5
+
6
+ /* Utils */
7
+ .c4p-center {
8
+ text-align: center;
9
+ }
10
+ .c4p-author-image {
11
+ height: 10em;
12
+ margin-top: 1em;
13
+ margin-left: 1em;
14
+ margin-right: 2em;
15
+ /*margin: 2em 1.5em;*/
16
+ }
17
+ .c4p-full-card {
18
+ max-width: none;
19
+ }
20
+ .c4p-left {
21
+ float: left;
22
+ }
23
+ .c4p-right {
24
+ float: right;
25
+ }
26
+ .c4p-clearfix:after {
27
+ content: "";
28
+ display: table;
29
+ clear: both;
30
+ }
31
+ /* Notices */
32
+
33
+ .updated, .error {
34
+ margin: 15px 0 20px !important;
35
+ }
36
+
37
+ .i4t3-author-link { text-decoration: none; }
38
+
39
+ .c4p-update-nag {
40
+ padding: 0px 15px;
41
+ width: 96%;
42
+ margin: 15px 15px 0 2px;
43
+ }
44
+ /* Stats Section */
45
+ /* .wp-list-table .column-id { width: 5%; } */
46
+ .wp-list-table .column-date { width: 15%; }
47
+ .wp-list-table .column-url { width: 25%; }
48
+ .wp-list-table .column-ref { width: 20%; }
49
+ .wp-list-table .column-ip { width: 15%;}
50
+ .wp-list-table .column-ua { width: 25%;}
51
+ .i4t3-url-p { color:red !important; }
admin/css/min/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/images/buy-now-dcl.png ADDED
Binary file
admin/images/coder.png ADDED
Binary file
admin/images/debug.png ADDED
Binary file
admin/images/gray-grad.png ADDED
Binary file
admin/images/icon-128x128.png ADDED
Binary file
admin/images/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/images/js-icon.png ADDED
Binary file
admin/images/logo.png ADDED
Binary file
admin/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/js/admin.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * All of the code for our admin-specific JavaScript source
6
+ * should reside in this file.
7
+ *
8
+ * Note that this assume you're going to use jQuery, so it prepares
9
+ * the $ function reference to be used within the scope of this
10
+ * function.
11
+ *
12
+ * From here, we are able to define handlers for when the DOM is
13
+ * ready:
14
+ *
15
+ * $(function() {
16
+ *
17
+ * });
18
+ *
19
+ * Or when the window is loaded:
20
+ *
21
+ * $( window ).load(function() {
22
+ *
23
+ * });
24
+ *
25
+ * ...and so on.
26
+ */
27
+ $(function() {
28
+ $('#i4t3_redirect_to').change(function() {
29
+ var redirect_to = $(this).val();
30
+ if(redirect_to == 'page') {
31
+ $('#custom_page').show();
32
+ $('#custom_url').hide();
33
+ } else if(redirect_to == 'link') {
34
+ $('#custom_url').show();
35
+ $('#custom_page').hide();
36
+ } else if(redirect_to == 'none') {
37
+ $('#custom_page').hide();
38
+ $('#custom_url').hide();
39
+ }
40
+ })
41
+ })
42
+ })(jQuery);
admin/js/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/js/min/admin-ck.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(t,$,n){$(document).ready(function(){i()});var i=function(){e()},e=function(){$("#tabs").tabs(),a(),o()},a=function(){$("#tabs").on("tabsactivate",function(t,n){var i=n.newTab.children("li a").first().attr("href");history.pushState(null,null,i),history.pushState?history.pushState(null,null,i):location.hash=i})},o=function(){setTimeout(function(){location.hash&&$("html, body").animate({scrollTop:0},1e3)},1)},u=function(){$("#kevinw_picker_bgcolor").farbtastic("#kevinw_picker_input_bgcolor")};$('input[type="number"]').keyup(function(){this.value!==this.value.replace(/[^0-9\.]/g,"")&&(this.value=this.value.replace(/[^0-9\.]/g,""))})}(window.kevinw_framework=window.kevinw_framework||{},jQuery);
admin/js/min/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/partials/404-to-301-admin-credits-tab.php ADDED
@@ -0,0 +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
+ So you installed this plugin and how is it doing? Feel free to <a href="http://iscode.co/contact/" class="i4t3-author-link" target="_blank" title="<?php _e( 'Contact the developer', '404-to-301' ); ?>">get in touch with me</a> anytime for help. I am always happy to help.
24
+ </p>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ <div class="postbox">
30
+ <h3 class="hndle"><span>Debugging Data</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> Plugin Information</h3>
44
+ <div class="inside">
45
+ <div class="misc-pub-section">
46
+ <label>Name : </label>
47
+ <span><strong>404 to 301</strong></span>
48
+ </div>
49
+ <div class="misc-pub-section">
50
+ <label>Version : v<?php echo $this->version; ?></label>
51
+ <span></span>
52
+ </div>
53
+ <div class="misc-pub-section">
54
+ <label>Author : <a href="http://iscode.co/" class="i4t3-author-link" target="_blank" title="Visit author website">is_code()</a></label>
55
+ <span></span>
56
+ </div>
57
+ <div class="misc-pub-section">
58
+ <label><a href="http://iscode.co/docs_cat/404-to-301/" class="i4t3-author-link" target="_blank" title="Visit plugin website"><strong>Plugin documentation</strong></a></label>
59
+ <span></span>
60
+ </div>
61
+ <div class="misc-pub-section">
62
+ <label><a href="http://iscode.co/product/404-to-301/" class="i4t3-author-link" target="_blank" title="Visit plugin website"><strong>More plugin details</strong></a></label>
63
+ <span></span>
64
+ </div>
65
+ <div class="misc-pub-section">
66
+ <label>Need help?</label>
67
+ <span><strong><a href="http://iscode.co/support/">contact support</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> Like the plugin?</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="Rate now">Rate this on WordPress</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="Donate now">Make a small donation</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="Contribute now">Contribute to the Plugin</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="Tweet now">Tweet about the Plugin</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 ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'WPINC' ) ) {
3
+ die('Nice try dude. But I am sorry');
4
+ }
5
+ /**
6
+ * Provide a dashboard view for the plugin
7
+ *
8
+ * This file is used to markup the dashboard pages of the plugin.
9
+ *
10
+ * @link http://iscode.co/product/404-to-301/
11
+ * @since 2.0.0
12
+ *
13
+ * @package I4T3
14
+ * @subpackage I4T3/admin/partials
15
+ */
16
+ ?>
17
+
18
+ <!-- This should be primarily consist of HTML with a little bit of PHP in it. -->
19
+ <?php $active_tab = ( !isset( $_GET['tab'] ) ) ? 'general' : $_GET['tab'];
20
+
21
+ $general_class = '';
22
+ $credits_class = '';
23
+ ${$active_tab.'_class'} = 'nav-tab-active';
24
+ ?>
25
+
26
+ <div class="wrap">
27
+ <h2>404 to 301 | Settings</h2><br>
28
+ <?php if( isset($_GET['settings-updated']) ) { ?>
29
+ <div class="updated">
30
+ <p><strong>404 to 301 settings updated successfully</strong></p>
31
+ </div>
32
+ <?php } ?>
33
+ <h2 class="nav-tab-wrapper">
34
+ <a href="?page=i4t3-settings&tab=general" class="nav-tab <?php echo $general_class; ?>">General</a>
35
+ <a href="?page=i4t3-settings&tab=credits" class="nav-tab <?php echo $credits_class ?>">Help & Info</a>
36
+ </h2>
37
+ </div>
38
+
39
+ <?php
40
+
41
+ switch ( $active_tab ) {
42
+
43
+ case 'general':
44
+ // Get list of active pages
45
+ $args = array(
46
+ 'post_type' => 'page',
47
+ 'post_status' => 'publish'
48
+ );
49
+ $pages = get_pages( $args );
50
+ include_once('404-to-301-admin-general-tab.php');
51
+ break;
52
+ case 'credits':
53
+ $current_user = wp_get_current_user();
54
+ include_once('404-to-301-admin-credits-tab.php');
55
+ break;
56
+ default:
57
+ include_once('404-to-301-admin-general-tab.php');
58
+ }
admin/partials/404-to-301-admin-general-tab.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Redirect type</th>
28
+ <td>
29
+ <select name='i4t3_gnrl_options[redirect_type]'>
30
+ <option value='301' <?php selected( $options['redirect_type'], '301' ); ?>>301 Redirect (SEO)</option>
31
+ <option value='302' <?php selected( $options['redirect_type'], '302' ); ?>>302 Redirect</option>
32
+ <option value='307' <?php selected( $options['redirect_type'], '307' ); ?>>307 Redirect</option>
33
+ </select>
34
+ <p class="description"><a target="_blank" href="https://moz.com/learn/seo/redirection"><strong>Learn more</strong></a> about these redirect types</p>
35
+ </td>
36
+ </tr>
37
+ <tr>
38
+ <th>Redirect to</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' ); ?>>Existing Page</option>
42
+ <option value='link' <?php selected( $options['redirect_to'], 'link' ); ?>>Custom URL</option>
43
+ <option value='none' <?php selected( $options['redirect_to'], 'none' ); ?>>No Redirect</option>
44
+ </select>
45
+ <p class="description"><strong>Existing Page:</strong> Select any WordPress page as a 404 page.</p>
46
+ <p class="description"><strong>Custom URL:</strong> Redirect 404 requests to a specific URL.</p>
47
+ <p class="description"><strong>No Redirect:</strong> To disable redirect.</p>
48
+ </td>
49
+ </tr>
50
+ <tr id="custom_page" <?php echo $cp_style; ?>>
51
+ <th>Select the page</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">The default 404 page will be replaced by the page you choose in this list.</p>
59
+ </td>
60
+ </tr>
61
+ <tr id="custom_url"<?php echo $cl_style; ?>>
62
+ <th>Custom URL</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">Enter any url (including http://)</p>
66
+ </td>
67
+ </tr>
68
+ <tr>
69
+ <th>Email notifications</th>
70
+ <td>
71
+ <?php $email_notify = 0; if( isset( $options['email_notify'] ) ) { $email_notify = $options['email_notify']; } ?>
72
+ <input type="checkbox" name="i4t3_gnrl_options[email_notify]" value="1" <?php checked( $email_notify, 1 ); ?> />
73
+ <p class="description">If you check this, an email will be sent on every 404 log on the admin's email account.</p>
74
+ </td>
75
+ </tr>
76
+ <tr>
77
+ <th>Log 404 Errors</th>
78
+ <td>
79
+ <select name='i4t3_gnrl_options[redirect_log]'>
80
+ <option value='1' <?php selected( $options['redirect_log'], 1 ); ?>>Enable Error Logs</option>
81
+ <option value='0' <?php selected( $options['redirect_log'], 0 ); ?>>Disable Error Logs</option>
82
+ </select>
83
+ <p class="description">Enable/Disable Logging</p>
84
+ </td>
85
+ </tr>
86
+ </tbody>
87
+ </table>
88
+ <?php submit_button( 'Save All Changes' ); ?>
89
+ </p>
90
+ </form>
91
+ </div>
admin/partials/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
includes/class-404-to-301-activator.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'WPINC' ) ) {
3
+ die('Damn it.! Dude you are looking for what?');
4
+ }
5
+ /**
6
+ * Fired during plugin activation.
7
+ *
8
+ * This class defines all code necessary to run during the plugin's activation.
9
+ *
10
+ * @link http://iscode.co/product/404-to-301/
11
+ * @since 2.0.0
12
+ * @package I4T3
13
+ * @subpackage I4T3/includes
14
+ * @author Joel James <me@joelsays.com>
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', 1 );
38
+
39
+ // New general settings array to be added
40
+ $i4t3GnrlOptions = array(
41
+ 'redirect_type' => $i4t3_type,
42
+ 'redirect_link' => $i4t3_link,
43
+ 'redirect_log' => $i4t3_enable,
44
+ 'redirect_to' => $i4t3_to,
45
+ 'redirect_page' => $i4t3_page,
46
+ 'email_notify' => $i4t3_notify
47
+ );
48
+
49
+ /**
50
+ * Array of all settings arrays.
51
+ * We are adding this to an array as we need to register
52
+ * multiple settings in future for addons
53
+ */
54
+ $i4t3_options = array(
55
+ 'i4t3_gnrl_options' => $i4t3GnrlOptions
56
+ );
57
+
58
+ // If not already exist, adding values
59
+ foreach ($i4t3_options as $key => $value) {
60
+ update_option($key, $value );
61
+ }
62
+
63
+ // remember, two spaces after PRIMARY KEY otherwise WP borks
64
+ $installed_version = get_option('i4t3_db_version');
65
+
66
+ if( I4T3_DB_VERSION != $installed_version ) {
67
+
68
+ global $wpdb;
69
+ $table = $wpdb->prefix . "404_to_301";
70
+
71
+ $sql = "CREATE TABLE $table (
72
+ id BIGINT NOT NULL AUTO_INCREMENT,
73
+ date DATETIME NOT NULL,
74
+ url VARCHAR(512) NOT NULL,
75
+ ref VARCHAR(512) NOT NULL default '',
76
+ ip VARCHAR(40) NOT NULL default '',
77
+ ua VARCHAR(512) NOT NULL default '',
78
+ PRIMARY KEY (id)
79
+ );";
80
+
81
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
82
+ dbDelta($sql); // To be safe on db upgrades
83
+ update_option( 'i4t3_db_version', I4T3_DB_VERSION );
84
+ }
85
+ }
86
+
87
+
88
+ /**
89
+ * Function to get existing settings
90
+ *
91
+ * This function used to check if the new setting is already available
92
+ * in datatabse, then consider that. Otherwise check for the old one
93
+ * and if available, takes that.
94
+ * If both the values are not available, then creates new default settings.
95
+ *
96
+ * @since 2.0.0
97
+ * @author Joel James
98
+ */
99
+ public static function transfer( $old, $new, $fresh ){
100
+
101
+ $option = 'i4t3_gnrl_options';
102
+
103
+ // let us check if new options already exists
104
+ if( get_option( $option ) ) {
105
+ $i4t3_option = get_option( $option );
106
+ // If exists, then take that option value
107
+ $fresh = $i4t3_option[$new];
108
+ // Check if old value is available for the same option
109
+ if(get_option( $old )) {
110
+ // If available delete it, as we are moving to new settings
111
+ delete_option( $old );
112
+ }
113
+ }
114
+ // Fine, new options doesn't exist, then let us search for old
115
+ else if( get_option( $old ) ) {
116
+ // Take old value and set it to new
117
+ $fresh = get_option($old);
118
+ // Delete it, as we are moving to new settings
119
+ delete_option( $old );
120
+ }
121
+
122
+ return $fresh;
123
+ }
124
+
125
+ }
includes/class-404-to-301-loader.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Register all actions and filters for the plugin.
9
+ *
10
+ * Maintain a list of all hooks that are registered throughout
11
+ * the plugin, and register them with the WordPress API. Call the
12
+ * run function to execute the list of actions and filters.
13
+ *
14
+ * @package I4T3
15
+ * @subpackage I4T3/includes
16
+ * @link http://iscode.co/product/404-to-301/
17
+ * @since 2.0.0
18
+ * @author Joel James <me@joelsays.com>
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
+ }
includes/class-404-to-301.php ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *
9
+ * A class definition that includes attributes and functions used across both the
10
+ * public-facing side of the site and the dashboard.
11
+ * Also maintains the unique identifier of this plugin as well as the current
12
+ * version of the plugin.
13
+ *
14
+ * @link http://iscode.co/product/404-to-301/
15
+ * @since 2.0.0
16
+ * @package I4T3
17
+ * @subpackage I4T3/includes
18
+ * @author Joel James <me@joelsays.com>
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.0.0';
71
+ $this->table = $GLOBALS['wpdb']->prefix . '404_to_301';
72
+ $this->load_dependencies();
73
+ $this->define_admin_hooks();
74
+ $this->define_handler_hooks();
75
+ }
76
+
77
+ /**
78
+ * Load the required dependencies for this plugin.
79
+ *
80
+ * Include the following files that make up the plugin:
81
+ *
82
+ * - _404_To_301_Loader. Orchestrates the hooks of the plugin.
83
+ * - _404_To_301_Admin. Defines all hooks for the dashboard.
84
+ * - _404_To_301_Public. Defines all hooks for the public functions.
85
+ * - _404_To_301_Logs. Defines all hooks for listing logs.
86
+ *
87
+ * Create an instance of the loader which will be used to register the hooks
88
+ * with WordPress.
89
+ *
90
+ * @since 2.0.0
91
+ * @access private
92
+ */
93
+ private function load_dependencies() {
94
+
95
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-404-to-301-loader.php';
96
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-404-to-301-admin.php';
97
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-404-to-301-logs.php';
98
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-404-to-301-public.php';
99
+
100
+ $this->loader = new _404_To_301_Loader();
101
+ }
102
+
103
+
104
+ /**
105
+ * Register all of the hooks related to the dashboard functionality
106
+ * of the plugin.
107
+ * This function is used to register all styles and JavaScripts for admin side.
108
+ *
109
+ * @since 2.0.0
110
+ * @access private
111
+ * @uses add_action() and add_filter()
112
+ */
113
+ private function define_admin_hooks() {
114
+
115
+ $plugin_admin = new _404_To_301_Admin( $this->get_plugin_name(), $this->get_version(), $this->get_table() );
116
+
117
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
118
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
119
+ $this->loader->add_action( 'admin_menu', $plugin_admin, 'i4t3_create_404_to_301_menu');
120
+ $this->loader->add_action( 'admin_menu', $plugin_admin, 'i4t3_rename_plugin_menu' );
121
+ $this->loader->add_action( 'admin_init', $plugin_admin, 'i4t3_options_register' );
122
+ $this->loader->add_filter( 'admin_footer_text', $plugin_admin, 'i4t3_dashboard_footer');
123
+ $this->loader->add_filter( 'plugin_action_links', $plugin_admin, 'i4t3_plugin_action_links', 10, 5 );
124
+ $this->loader->add_action( 'plugins_loaded', $plugin_admin, 'i4t3_upgrade_if_new' );
125
+ }
126
+
127
+
128
+ /**
129
+ * Register all of the hooks related to handle 404 actions of the plugin.
130
+ *
131
+ * @since 2.0.0
132
+ * @access private
133
+ * @uses add_filter()
134
+ */
135
+ private function define_handler_hooks() {
136
+
137
+ $plugin_public = new _404_To_301_Public( $this->get_plugin_name(), $this->get_version(), $this->get_table() );
138
+ // Main Hook to perform redirections on 404s
139
+ $this->loader->add_filter( 'template_redirect', $plugin_public, 'i4t3_redirect_404' );
140
+ }
141
+
142
+ /**
143
+ * Run the loader to execute all of the hooks with WordPress.
144
+ *
145
+ * @since 2.0.0
146
+ */
147
+ public function run() {
148
+ $this->loader->run();
149
+ }
150
+
151
+ /**
152
+ * The name of the plugin used to uniquely identify it within the context of
153
+ * WordPress and to define internationalization functionality.
154
+ *
155
+ * @since 2.0.0
156
+ * @return string The name of the plugin.
157
+ */
158
+ public function get_plugin_name() {
159
+ return $this->plugin_name;
160
+ }
161
+
162
+ /**
163
+ * The reference to the class that orchestrates the hooks with the plugin.
164
+ *
165
+ * @since 2.0.0
166
+ * @return i4t3_Loader Orchestrates the hooks of the plugin.
167
+ */
168
+ public function get_loader() {
169
+ return $this->loader;
170
+ }
171
+
172
+ /**
173
+ * Retrieve the version number of the plugin.
174
+ *
175
+ * @since 2.0.0
176
+ * @return string The version number of the plugin.
177
+ */
178
+ public function get_version() {
179
+ return $this->version;
180
+ }
181
+
182
+ /**
183
+ * Retrieve the table name of the plugin.
184
+ *
185
+ * @since 2.0.0
186
+ * @return string The table name of the plugin.
187
+ */
188
+ public function get_table() {
189
+ return $this->table;
190
+ }
191
+ }
includes/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
license.txt ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
public/class-404-to-301-public.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *
9
+ *
10
+ * @link http://iscode.co/product/404-to-301
11
+ * @since 2.0.0
12
+ * @package I4T3
13
+ * @subpackage I4T3/public
14
+ * @author Joel James <me@joelsays.com>
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
+ // Get the site name
73
+ $site_name = get_bloginfo( 'name' );
74
+
75
+ $headers[] = 'From: ' . $site_name . ' <' . $admin_email . '>' . "\r\n";
76
+ $headers[] = 'Content-Type: text/html; charset=UTF-8';
77
+ $message = '<p>'. __( 'Bummer! You have one more 404', '404-to-301' ) .'</p>';
78
+ $message .= '<table>';
79
+ $message .= '<tr>';
80
+ $message .= '<th>'. __( 'IP Address', '404-to-301' ) .'</th>';
81
+ $message .= '<td>' . $log_data['ip'] . '</td>';
82
+ $message .= '</tr>';
83
+ $message .= '<tr>';
84
+ $message .= '<th>'. __( '404 Path', '404-to-301' ) .'</th>';
85
+ $message .= '<td>' . $log_data['url'] . '</td>';
86
+ $message .= '</tr>';
87
+ $message .= '<tr>';
88
+ $message .= '<th>'. __( 'User Agent', '404-to-301' ) .'</th>';
89
+ $message .= '<td>' . $log_data['ua'] . '</td>';
90
+ $message .= '</tr>';
91
+ $message .= '</table>';
92
+
93
+ // Action hook that will be performed before sending 404 error mail
94
+ do_action( 'i4t3_before_404_log_mail', $message );
95
+
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() ) {
118
+
119
+ // Get the settings options
120
+ $logging_status = ( $this->gnrl_options['redirect_log'] ) ? $this->gnrl_options['redirect_log'] : 1;
121
+ $redirect_type = ( $this->gnrl_options['redirect_type'] ) ? $this->gnrl_options['redirect_type'] : '301';
122
+ // Get the email notification settings
123
+ $is_email_send = ( !empty( $this->gnrl_options['email_notify'] ) ) ? true : false;
124
+ // Get error details if emailnotification or log is enabled
125
+ if( $logging_status == 1 || $is_email_send ) {
126
+
127
+ // Action hook that will be performed before logging 404 errors
128
+ do_action( 'i4t3_before_404_logging' );
129
+
130
+ global $wpdb;
131
+ $data = array(
132
+ 'date' => current_time('mysql'),
133
+ 'url' => $_SERVER['REQUEST_URI']
134
+ );
135
+ if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
136
+ $data['ip'] = $_SERVER['HTTP_CLIENT_IP'];
137
+ } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
138
+ $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
139
+ } else {
140
+ $data['ip'] = $_SERVER['REMOTE_ADDR'];
141
+ }
142
+ $data['ref'] = $_SERVER['HTTP_REFERER'];
143
+ $data['ua'] = $_SERVER['HTTP_USER_AGENT'];
144
+ // trim stuff
145
+ foreach( array( 'url', 'ref', 'ua' ) as $k )
146
+ if( isset( $data[$k] ) )
147
+ $data[$k] = substr( $data[$k], 0, 512 );
148
+ }
149
+
150
+ // Add log data to db if log is enabled by user
151
+ if($logging_status == 1) {
152
+
153
+ $wpdb->insert( $this->table, $data );
154
+
155
+ // pop old entry if we exceeded the limit
156
+ //$max = intval( $this->options['max_entries'] );
157
+ $max = 500;
158
+ $cutoff = $wpdb->get_var( "SELECT id FROM $this->table ORDER BY id DESC LIMIT $max,1" );
159
+ if( $cutoff ) {
160
+ $wpdb->delete( $this->table, array( 'id' => intval( $cutoff ) ), array( '%d' ) );
161
+ }
162
+ }
163
+
164
+ // Send email notification if enabled
165
+ if ($is_email_send) {
166
+ $this->i4t3_send_404_log_email($data);
167
+ }
168
+
169
+ // Get redirect settings
170
+ $redirect_to = $this->gnrl_options['redirect_to'];
171
+
172
+ switch( $redirect_to ) {
173
+ // Do not redirect if none is set
174
+ case 'none':
175
+ break;
176
+ // Redirect to an existing WordPress site inside our site
177
+ case 'page':
178
+ $url = get_permalink( $this->gnrl_options['redirect_page'] );
179
+ break;
180
+ // Redirect to a custom link given by user
181
+ case 'link':
182
+ $naked_url = $this->gnrl_options['redirect_link'];
183
+ $url = 'http://' . preg_replace( '~^http://~', '', $naked_url );
184
+ break;
185
+ // If nothing, be chill and do nothing!
186
+ default:
187
+ break;
188
+ }
189
+
190
+ // Perform the redirect if $url is set
191
+ if (!empty($url)) {
192
+ // Action hook that will be performed before 404 redirect starts
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_no_redirect_action' );
199
+ }
200
+ }
201
+
202
+ }
public/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
readme.txt CHANGED
@@ -1,74 +1,128 @@
1
  === 404 to 301 ===
2
- Contributors: joelcj91,joelsays
3
- Tags: 404, 301, 302, 307, not found, 404 redirect, 404 to 301, 301 redirect, seo
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
5
- Requires at least: 3.0.1
6
- Tested up to: 4.2
7
- Stable tag: 1.0.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Automatically redirect 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 your website has some 404 error pages then it will affect your SEO badly. Users will leave your site if they get 404 not found error.
16
 
17
- Using <a href="http://www.joelsays.com/plugins/404-to-301/">this plugin</a> you can redirect users or Google bot to any other pages using 301 redirect method. That will show them as permanently moved and it is good for SEO.
18
 
19
- Also you can use 302 and 307 redirect too (Temporary redirect method).
20
 
 
 
21
 
22
- Features of <a href="http://www.joelsays.com/plugins/404-to-301/">404 to 301</a> plugin are,
23
 
24
- * You can use any link to redirect.
25
- * No more 404 errors.
26
- * You can choose which redirect method to be used (301,302,307).
27
- * Will not irritate your visitors if they type a non existing page url.
28
- * Light weight.
29
- * Increase your SEO by telling google that all 404 pages are moved to some other page.
30
- * Quick <a href="http://www.joelsays.com/members-area/support/plugin-support-404-to-301/">Direct Support Forum</a>.
31
- * Free to use with lifetime updates.
32
- * More feature coming soon.. (Suggest a feature <a href="http://www.joelsays.com/members-area/support/plugin-support-404-to-301/">here</a>)
 
 
 
 
 
 
 
33
 
34
-
35
- == Support ==
36
 
37
- Current Version: 1.0.8
38
 
39
- Author: Joel James
40
- Author URI: http://www.joelsays.com/ <br/>
41
- <a href="http://www.joelsays.com/plugins/404-to-301/">Plugin Website</a><br/>
42
- <a href="http://www.joelsays.com/members-area/support/plugin-support-404-to-301/">Plugin Support</a>
 
 
 
 
 
 
 
43
 
44
 
45
  == Installation ==
46
 
47
- 1. Upload `404 to 301` plug-in zip file to the `/wp-content/plugins/` directory
48
- 2. Activate the plugin through the 'Plugins' menu in WordPress
49
- 3. You will see a options menu "401 to 301" under settings tab. Go there.
50
- 4. Choose which type redirection you want (301 recommended).
51
- 5. Enter a link to where you want your users to get redirected.
52
- 6. Save it by clicking on "Update Options".
53
 
54
- == Screenshots ==
 
 
 
 
 
55
 
56
- 1. **Settings** - Settings page of 404 to 301.
 
 
 
 
 
57
 
58
  == Frequently Asked Questions ==
59
 
60
  = What is the use of 404 to 301? =
61
 
62
- It will increase your SEO by redirecting using 301.
 
 
 
 
 
 
 
 
 
 
 
 
63
 
 
64
 
65
- = What type of redirection is used? =
66
 
67
- You can choose redirection types like 301,302 and 307.
 
 
 
 
 
 
 
 
 
 
 
68
 
69
 
70
  == Changelog ==
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  = 1.0.8 =
73
  * Very minor bug fix
74
  * Tested for WP 4.2
@@ -98,9 +152,8 @@ You can choose redirection types like 301,302 and 307.
98
  = 1.0.0 =
99
  * Added first version with basic options.
100
 
101
-
102
  == Upgrade Notice ==
103
 
104
  = 1.0.8 =
105
  * Very minor bug fix
106
- * Tested for WP 4.2
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
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.2.4
7
+ Stable tag: 2.0.0
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
+ > - You can optionally monitor/log all errors.<br />
30
+ > - You can optionally enable email notification on all 404 errors.<br />
31
+ > - You can choose which redirect method to be used (301,302,307).<br />
32
+ > - Will not irritate your visitors if they land on a non-existing page/url.<br />
33
+ > - Super Light weight.<br />
34
+ > - Increase your SEO by telling Google that all 404 pages are moved to some other page.<br />
35
+ > - Completely free to use with lifetime updates.<br />
36
+ > - Developer friendly.<br />
37
+ > - Follows best WordPress coding standards.<br />
38
+ > - Of course, available in [GitHub](https://github.com/joel-james/404-to-301)<br />
39
+ >
40
+ > [Installation](https://wordpress.org/plugins/404-to-301/installation/) | [Docs](http://iscode.co/docs_cat/404-to-301/) | [Screenshots](https://wordpress.org/plugins/404-to-301/screenshots/)
41
 
 
 
42
 
43
+ **Bug Reports**
44
 
45
+ Bug reports for 404 to 301 are always welcome. [Report here](http://iscode.co/support/).
46
+
47
+ **More information**
48
+
49
+ - [404 to 301 - Plugin Homepage](https://iscode.co/product/404-to-301/), containing more details and docs.
50
+ - Follow the developer [@Twitter](https://twitter.com/Joel_James)
51
+ - Other [WordPress plugins](https://profiles.wordpress.org/joelcj91/#content-plugins) by [Joel James for is_code()](https://iscode.co/)
52
+
53
+ **404 Errors and Redirect - More Details**
54
+
55
+ 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.
56
 
57
 
58
  == Installation ==
59
 
 
 
 
 
 
 
60
 
61
+ = Installing the plugin - Simple =
62
+ 1. In your WordPress admin panel, go to *Plugins > New Plugin*, search for **404 to 301** and click "*Install now*"
63
+ 2. Alternatively, download the plugin and upload the contents of `404-to-301.zip` to your plugins directory, which usually is `/wp-content/plugins/`.
64
+ 3. Activate the plugin
65
+ 4. Go to 404 to 301 tab on your admin menus.
66
+ 5. Configure the plugin options with available settings.
67
 
68
+
69
+ = Need more help? =
70
+ Please take a look at the [plugin documentation](http://iscode.co/docs_cat/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
71
+
72
+ = Missing something? =
73
+ If you would like to have an additional feature for this plugin, [let me know](http://iscode.co/support/)
74
 
75
  == Frequently Asked Questions ==
76
 
77
  = What is the use of 404 to 301? =
78
 
79
+ It will increase your SEO by redirecting all 404 errors using SEO redirects.
80
+
81
+ = Can I monitor 404 errors? =
82
+
83
+ Yes. You can. If you enable logs from settings, it will list all the errors.
84
+
85
+ = How can I clear logs? =
86
+
87
+ Select 'clear logs' from bulk actions and submit. It will delete all log data from your db.
88
+
89
+ = Can I get email notifications? =
90
+
91
+ Yes. You can enable email notifications on each 404 errors (optional).
92
 
93
+ = I need more details =
94
 
95
+ Please take a look at the [plugin documentation](http://iscode.co/docs_cat/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
96
 
97
+
98
+ == Other Notes ==
99
+
100
+ = Bug Reports =
101
+
102
+ Bug reports for 404 to 301 are always welcome. [Report here](https://iscode.co/support/).
103
+
104
+
105
+ == Screenshots ==
106
+
107
+ 1. **Settings** - Settings page of 404 to 301.
108
+ 2. **Error Logs** - Logged 404 Errors.
109
 
110
 
111
  == Changelog ==
112
 
113
+ = 2.0.0 (29/07/2015) =
114
+ **New Feature**
115
+
116
+ - Now you can log/monitor all 404 errors (optional).
117
+ - You can get email notifications on 404 errors (optional).
118
+ - You can select existing pages from dropdown to set as redirect page.
119
+ - New plugin home page.
120
+
121
+ **Improvements**
122
+
123
+ - Upgraded to WordPress plugin coding standard.
124
+ - Documented all functions.
125
+
126
  = 1.0.8 =
127
  * Very minor bug fix
128
  * Tested for WP 4.2
152
  = 1.0.0 =
153
  * Added first version with basic options.
154
 
 
155
  == Upgrade Notice ==
156
 
157
  = 1.0.8 =
158
  * Very minor bug fix
159
+ * Tested for WP 4.2
screenshot-1.png CHANGED
Binary file
screenshot-2.png ADDED
Binary file
uninstall.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fired only when the 404 to 301 is un-installed.
5
+ *
6
+ * Removes everything that 404 to 301 added to your db.
7
+ *
8
+ *
9
+ * @link http://iscode.co/product/404-to-301/
10
+ * @since 2.0.0
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 ********/