404 to 301 - Version 3.1.4

Version Description

(22/06/2022) = ** Improvements**

  • Sanitize variables.
Download this release

Release Info

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

Code changes from version 3.1.3 to 3.1.4

404-to-301.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: 404 to 301 - Redirect, Log and Notify 404 Errors
4
  * Plugin URI: https://duckdev.com/products/404-to-301/
5
  * Description: Automatically redirect all <strong>404 errors</strong> to any page using <strong>301 redirect for SEO</strong>. You can <strong>redirect and log</strong> every 404 errors. No more 404 errors in Webmaster tool.
6
- * Version: 3.1.3
7
  * Author: Joel James
8
  * Author URI: https://duckdev.com/
9
  * Donate link: https://paypal.me/JoelCJ
@@ -44,7 +44,7 @@ define( 'JJ4T3_URL', plugin_dir_url( __FILE__ ) );
44
  // Define plugin base file.
45
  define( 'JJ4T3_BASE_FILE', __FILE__ );
46
  // Define plugin version.
47
- define( 'JJ4T3_VERSION', '3.1.3' );
48
  // Define plugin version.
49
  define( 'JJ4T3_DB_VERSION', '11.0' );
50
  // Define plugin log table.
3
  * Plugin Name: 404 to 301 - Redirect, Log and Notify 404 Errors
4
  * Plugin URI: https://duckdev.com/products/404-to-301/
5
  * Description: Automatically redirect all <strong>404 errors</strong> to any page using <strong>301 redirect for SEO</strong>. You can <strong>redirect and log</strong> every 404 errors. No more 404 errors in Webmaster tool.
6
+ * Version: 3.1.4
7
  * Author: Joel James
8
  * Author URI: https://duckdev.com/
9
  * Donate link: https://paypal.me/JoelCJ
44
  // Define plugin base file.
45
  define( 'JJ4T3_BASE_FILE', __FILE__ );
46
  // Define plugin version.
47
+ define( 'JJ4T3_VERSION', '3.1.4' );
48
  // Define plugin version.
49
  define( 'JJ4T3_DB_VERSION', '11.0' );
50
  // Define plugin log table.
includes/admin/class-jj4t3-log-listing.php CHANGED
@@ -111,13 +111,14 @@ class JJ4T3_Log_Listing extends WP_List_Table {
111
  * Apply all filtering, sorting and paginations.
112
  * Registering filter - "jj4t3_logs_list_result".
113
  *
114
- * @param int $per_page Logs per page.
115
- * @param int $page_number Current page number.
116
- *
117
  * @since 3.0.0
118
  * @access public
119
  *
120
  * @global object $wpdb WP DB object
 
 
 
 
121
  * @return array
122
  */
123
  private function get_error_logs( $per_page = 20, $page_number = 1 ) {
@@ -125,24 +126,24 @@ class JJ4T3_Log_Listing extends WP_List_Table {
125
 
126
  // Current offset.
127
  $offset = ( $page_number - 1 ) * $per_page;
128
-
129
- // Sort by column.
130
- $orderby = $this->get_order_by();
131
-
132
  // Set group b query, if set.
133
- $groupby_query = empty( $this->group_by ) ? '' : ' GROUP BY ' . $this->group_by;
134
  // Get count of grouped items.
135
  $count = empty( $this->group_by ) ? '' : ', COUNT(id) as count ';
136
 
137
- // Sort order.
138
- $order = $this->get_order();
139
-
140
  // Get error logs.
141
  $result = $wpdb->get_results(
142
  $wpdb->prepare(
143
- "SELECT *{$count} FROM " . JJ4T3_TABLE . " WHERE status != 0 $groupby_query ORDER BY $orderby $order LIMIT %d OFFSET %d",
144
- array( $per_page, $offset ) ),
145
- 'ARRAY_A'
 
 
 
 
 
 
 
146
  );
147
 
148
  /**
111
  * Apply all filtering, sorting and paginations.
112
  * Registering filter - "jj4t3_logs_list_result".
113
  *
 
 
 
114
  * @since 3.0.0
115
  * @access public
116
  *
117
  * @global object $wpdb WP DB object
118
+ *
119
+ * @param int $per_page Logs per page.
120
+ * @param int $page_number Current page number.
121
+ *
122
  * @return array
123
  */
124
  private function get_error_logs( $per_page = 20, $page_number = 1 ) {
126
 
127
  // Current offset.
128
  $offset = ( $page_number - 1 ) * $per_page;
 
 
 
 
129
  // Set group b query, if set.
130
+ $groupby_query = empty( $this->group_by ) ? '' : 'GROUP BY ' . $this->group_by;
131
  // Get count of grouped items.
132
  $count = empty( $this->group_by ) ? '' : ', COUNT(id) as count ';
133
 
 
 
 
134
  // Get error logs.
135
  $result = $wpdb->get_results(
136
  $wpdb->prepare(
137
+ 'SELECT *%1$s FROM %2$s WHERE status != 0 %3$s ORDER BY %4$s %5$s LIMIT %6$d OFFSET %7$d',
138
+ $count,
139
+ JJ4T3_TABLE,
140
+ $groupby_query,
141
+ $this->get_order_by(),
142
+ $this->get_order(),
143
+ $per_page,
144
+ $offset
145
+ ),
146
+ ARRAY_A
147
  );
148
 
149
  /**
includes/functions/jj4t3-general-functions.php CHANGED
@@ -354,22 +354,21 @@ function jj4t3_log_columns() {
354
  * @return array|string
355
  */
356
  function jj4t3_from_request( $key = '', $default = '' ) {
357
-
358
  // Return default value if key is not given.
359
  if ( empty( $key ) || ! is_string( $key ) ) {
360
  return $default;
361
  }
362
 
363
  // Return default value if key not set.
364
- if ( ! isset( $_REQUEST[ $key ] ) ) { // phpcs:ignore
365
  return $default;
366
  }
367
 
368
  // Trim output.
369
- if ( is_string( $_REQUEST[ $key ] ) ) { // phpcs:ignore
370
- return sanitize_text_field( $_REQUEST[ $key ] ); // phpcs:ignore
371
- } elseif ( is_array( $_REQUEST[ $key ] ) ) { // phpcs:ignore
372
- return array_map( 'sanitize_text_field', $_REQUEST[ $key ] ); // phpcs:ignore
373
  }
374
 
375
  return $default;
354
  * @return array|string
355
  */
356
  function jj4t3_from_request( $key = '', $default = '' ) {
 
357
  // Return default value if key is not given.
358
  if ( empty( $key ) || ! is_string( $key ) ) {
359
  return $default;
360
  }
361
 
362
  // Return default value if key not set.
363
+ if ( ! isset( $_REQUEST[ $key ] ) ) {
364
  return $default;
365
  }
366
 
367
  // Trim output.
368
+ if ( is_string( $_REQUEST[ $key ] ) ) {
369
+ return sanitize_text_field( $_REQUEST[ $key ] );
370
+ } elseif ( is_array( $_REQUEST[ $key ] ) ) {
371
+ return array_map( 'sanitize_text_field', $_REQUEST[ $key ] );
372
  }
373
 
374
  return $default;
includes/public/class-jj4t3-404-actions.php CHANGED
@@ -211,7 +211,7 @@ class JJ4T3_404_Actions extends JJ4T3_404_Data {
211
  */
212
  do_action( 'jj4t3_before_redirect', $this->redirect_url );
213
 
214
- // Perform redirect using WordPres.
215
  wp_redirect( $this->redirect_url, $this->redirect_type );
216
  // Exit, because WordPress will not exit automatically.
217
  exit;
@@ -225,14 +225,13 @@ class JJ4T3_404_Actions extends JJ4T3_404_Data {
225
  * set that link.
226
  * Registering filter "jj4t3_custom_redirect_url".
227
  *
228
- * @global object $wpdb WP DB object
229
  * @since 2.2.0
230
  * @access private
231
  *
 
232
  * @return void
233
  */
234
  private function set_options() {
235
-
236
  if ( empty( $this->url ) ) {
237
  return;
238
  }
@@ -242,7 +241,13 @@ class JJ4T3_404_Actions extends JJ4T3_404_Data {
242
  $wpdb->hide_errors();
243
 
244
  // Get custom redirect if set.
245
- $result = $result = $wpdb->get_row( "SELECT redirect, options FROM " . JJ4T3_TABLE . " WHERE url = '" . $this->url . "' AND redirect IS NOT NULL LIMIT 0,1", "OBJECT" );
 
 
 
 
 
 
246
 
247
  $options = empty( $result->options ) ? array() : maybe_unserialize( $result->options );
248
 
211
  */
212
  do_action( 'jj4t3_before_redirect', $this->redirect_url );
213
 
214
+ // Perform redirect using WordPress.
215
  wp_redirect( $this->redirect_url, $this->redirect_type );
216
  // Exit, because WordPress will not exit automatically.
217
  exit;
225
  * set that link.
226
  * Registering filter "jj4t3_custom_redirect_url".
227
  *
 
228
  * @since 2.2.0
229
  * @access private
230
  *
231
+ * @global object $wpdb WP DB object
232
  * @return void
233
  */
234
  private function set_options() {
 
235
  if ( empty( $this->url ) ) {
236
  return;
237
  }
241
  $wpdb->hide_errors();
242
 
243
  // Get custom redirect if set.
244
+ $result = $wpdb->get_row(
245
+ $wpdb->prepare(
246
+ 'SELECT redirect, options FROM %1$s WHERE url = \'%2$s\' AND redirect IS NOT NULL LIMIT 0,1',
247
+ JJ4T3_TABLE,
248
+ $this->url
249
+ )
250
+ );
251
 
252
  $options = empty( $result->options ) ? array() : maybe_unserialize( $result->options );
253
 
includes/public/class-jj4t3-404-data.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  // If this file is called directly, abort.
4
- defined( 'ABSPATH' ) or exit;
5
 
6
  /**
7
  * The 404 error data class.
@@ -82,27 +82,25 @@ class JJ4T3_404_Data {
82
  * @since 2.2.6
83
  * @access private
84
  *
85
- * @param string $ip Default value for IP Address.
86
- *
87
  * @return void
88
  */
89
- private function set_ip( $ip = '' ) {
90
  // IP variables in priority oder.
91
  $headers = array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' );
92
  foreach ( $headers as $header ) {
93
- if ( isset( $_SERVER[ $header ] ) ) {
94
- $ip = $_SERVER[ $header ]; // phpcs:ignore
 
 
 
 
 
 
 
 
 
95
  }
96
  }
97
-
98
- /**
99
- * Filter to alter visitors IP address.
100
- *
101
- * @since 3.0.0
102
- */
103
- $ip = apply_filters( 'jj4t3_404_ip', $ip );
104
-
105
- $this->ip = sanitize_text_field( $ip );
106
  }
107
 
108
  /**
@@ -111,23 +109,19 @@ class JJ4T3_404_Data {
111
  * @since 3.0.0
112
  * @access private
113
  *
114
- * @param string $ua Default value for User Agent.
115
- *
116
  * @return void
117
  */
118
- private function set_ua( $ua = '' ) {
119
  if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
120
- $ua = $_SERVER['HTTP_USER_AGENT']; // phpcs:ignore
 
 
 
 
 
 
 
121
  }
122
-
123
- /**
124
- * Filter to alter User Agent.
125
- *
126
- * @since 3.0.0
127
- */
128
- $ua = apply_filters( 'jj4t3_404_ua', $ua );
129
-
130
- $this->ua = sanitize_text_field( $ua );
131
  }
132
 
133
  /**
@@ -136,25 +130,21 @@ class JJ4T3_404_Data {
136
  * @since 3.0.0
137
  * @access private
138
  *
139
- * @param string $ref Default value for Ref.
140
- *
141
  * @return void
142
  */
143
- private function set_ref( $ref = '' ) {
144
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
145
- $ref = $_SERVER['HTTP_REFERER']; // phpcs:ignore
 
 
 
 
 
 
 
 
 
146
  }
147
-
148
- /**
149
- * Filter to alter referrer url.
150
- *
151
- * To alter the url where the visitor comes from.
152
- *
153
- * @since 3.0.0
154
- */
155
- $ref = apply_filters( 'jj4t3_404_ref', $ref );
156
-
157
- $this->ref = esc_url_raw( $ref );
158
  }
159
 
160
  /**
@@ -163,25 +153,21 @@ class JJ4T3_404_Data {
163
  * @since 3.0.0
164
  * @access private
165
  *
166
- * @param string $url Default value for 404 URL.
167
- *
168
  * @return void
169
  */
170
- private function set_url( $url = '' ) {
171
  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
172
- $url = $_SERVER['REQUEST_URI']; // phpcs:ignore
 
 
 
 
 
 
 
 
 
173
  }
174
-
175
- /**
176
- * Filter to alter current 404 path.
177
- *
178
- * It is not recommended to change this value.
179
- *
180
- * @since 3.0.0
181
- */
182
- $url = apply_filters( 'jj4t3_404_url', $url );
183
-
184
- $this->url = untrailingslashit( esc_url_raw( $url ) );
185
  }
186
 
187
  /**
1
  <?php
2
 
3
  // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) || exit;
5
 
6
  /**
7
  * The 404 error data class.
82
  * @since 2.2.6
83
  * @access private
84
  *
 
 
85
  * @return void
86
  */
87
+ private function set_ip() {
88
  // IP variables in priority oder.
89
  $headers = array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' );
90
  foreach ( $headers as $header ) {
91
+ if ( ! empty( $_SERVER[ $header ] ) ) {
92
+ /**
93
+ * Filter to alter visitors IP address.
94
+ *
95
+ * @since 3.0.0
96
+ *
97
+ * @param string $ip Value for IP Address.
98
+ */
99
+ $this->ip = sanitize_text_field( apply_filters( 'jj4t3_404_ip', $_SERVER[ $header ] ) );
100
+
101
+ break;
102
  }
103
  }
 
 
 
 
 
 
 
 
 
104
  }
105
 
106
  /**
109
  * @since 3.0.0
110
  * @access private
111
  *
 
 
112
  * @return void
113
  */
114
+ private function set_ua() {
115
  if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
116
+ /**
117
+ * Filter to alter User Agent.
118
+ *
119
+ * @since 3.0.0
120
+ *
121
+ * @param string $ua Value for User Agent.
122
+ */
123
+ $this->ua = sanitize_text_field( apply_filters( 'jj4t3_404_ua', $_SERVER['HTTP_USER_AGENT'] ) );
124
  }
 
 
 
 
 
 
 
 
 
125
  }
126
 
127
  /**
130
  * @since 3.0.0
131
  * @access private
132
  *
 
 
133
  * @return void
134
  */
135
+ private function set_ref() {
136
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
137
+ /**
138
+ * Filter to alter referrer url.
139
+ *
140
+ * To alter the url where the visitor comes from.
141
+ *
142
+ * @since 3.0.0
143
+ *
144
+ * @param string $ref Value for referral.
145
+ */
146
+ $this->ref = esc_url_raw( apply_filters( 'jj4t3_404_ref', $_SERVER['HTTP_REFERER'] ) );
147
  }
 
 
 
 
 
 
 
 
 
 
 
148
  }
149
 
150
  /**
153
  * @since 3.0.0
154
  * @access private
155
  *
 
 
156
  * @return void
157
  */
158
+ private function set_url() {
159
  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
160
+ /**
161
+ * Filter to alter current 404 path.
162
+ *
163
+ * It is not recommended to change this value.
164
+ *
165
+ * @since 3.0.0
166
+ *
167
+ * @param string $url Value for 404 URL.
168
+ */
169
+ $this->url = untrailingslashit( esc_url_raw( apply_filters( 'jj4t3_404_url', $_SERVER['REQUEST_URI'] ) ) );
170
  }
 
 
 
 
 
 
 
 
 
 
 
171
  }
172
 
173
  /**
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: joelcj91,duckdev
3
  Tags: 404, 301, 302, 307, not found, 404 redirect, 404 to 301, 301 redirect, seo redirect, error redirect, 404 seo, custom 404 page
4
  Donate link: https://www.paypal.me/JoelCJ
5
  Requires at least: 3.5
6
- Tested up to: 6.0
7
- Stable tag: 3.1.3
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -128,6 +128,11 @@ Bug reports for 404 to 301 are always welcome. [Report here](https://duckdev.com
128
 
129
  == Changelog ==
130
 
 
 
 
 
 
131
  = 3.1.3 (17/06/2022) =
132
  **👌 Improvements**
133
 
@@ -460,7 +465,7 @@ Bug reports for 404 to 301 are always welcome. [Report here](https://duckdev.com
460
 
461
  == Upgrade Notice ==
462
 
463
- = 3.1.3 (17/06/2022) =
464
  **👌 Improvements**
465
 
466
- * Security checks and improvements.
3
  Tags: 404, 301, 302, 307, not found, 404 redirect, 404 to 301, 301 redirect, seo redirect, error redirect, 404 seo, custom 404 page
4
  Donate link: https://www.paypal.me/JoelCJ
5
  Requires at least: 3.5
6
+ Tested up to: 6.1
7
+ Stable tag: 3.1.4
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
128
 
129
  == Changelog ==
130
 
131
+ = 3.1.4 (22/06/2022) =
132
+ **👌 Improvements**
133
+
134
+ * Sanitize variables.
135
+
136
  = 3.1.3 (17/06/2022) =
137
  **👌 Improvements**
138
 
465
 
466
  == Upgrade Notice ==
467
 
468
+ = 3.1.4 (22/06/2022) =
469
  **👌 Improvements**
470
 
471
+ * Sanitize variables.