Eggplant 301 Redirects - Version 2.2.7

Version Description

That silly bug with the database tables not being created has been squashed. Improved query performance.

Download this release

Release Info

Developer shawn@eggplantstudios.ca
Plugin Icon 128x128 Eggplant 301 Redirects
Version 2.2.7
Comparing to
See all releases

Code changes from version 2.2.6 to 2.2.7

class.drop-down-pages.php CHANGED
@@ -10,9 +10,15 @@
10
  * @return string or HTML content, if not displaying.
11
  */
12
 
 
13
 
14
- if( !function_exists('eps_dropdown_pages')) {
15
- function eps_dropdown_pages($args = '') {
 
 
 
 
 
16
  $defaults = array(
17
  'posts_per_page' => -1,
18
  'offset' => 0,
@@ -73,5 +79,7 @@ class EPS_Walker_PageDropdown extends Walker {
73
  $output[$object->ID] = $pad . esc_html( apply_filters( 'list_pages', $object->post_title, $object ) );
74
  }
75
  }
76
- }
 
 
77
  ?>
10
  * @return string or HTML content, if not displaying.
11
  */
12
 
13
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
 
15
+
16
+ if( !function_exists('eps_dropdown_pages'))
17
+ {
18
+
19
+
20
+ function eps_dropdown_pages($args = '')
21
+ {
22
  $defaults = array(
23
  'posts_per_page' => -1,
24
  'offset' => 0,
79
  $output[$object->ID] = $pad . esc_html( apply_filters( 'list_pages', $object->post_title, $object ) );
80
  }
81
  }
82
+
83
+
84
+ } // End function exists.
85
  ?>
eps-301-redirects.php CHANGED
@@ -15,7 +15,7 @@
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
- * @version 2.2.6
19
  */
20
 
21
 
@@ -25,7 +25,7 @@
25
  Plugin Name: Eggplant 301 Redirects
26
  Plugin URI: http://www.eggplantstudios.ca
27
  Description: Create your own 301 redirects using this powerful plugin.
28
- Version: 2.2.6
29
  Author: Shawn Wernig http://www.eggplantstudios.ca
30
  License: GPLv2 or later
31
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -36,16 +36,16 @@ if( ! defined( 'EPS_REDIRECT_PRO' ) )
36
 
37
  define ( 'EPS_REDIRECT_PATH', plugin_dir_path(__FILE__) );
38
  define ( 'EPS_REDIRECT_URL', plugins_url() . '/eps-301-redirects/');
39
- define ( 'EPS_REDIRECT_VERSION', '2.2.6');
40
  define ( 'EPS_REDIRECT_PRO', false);
41
 
42
  include( EPS_REDIRECT_PATH.'eps-form-elements.php');
43
  include( EPS_REDIRECT_PATH.'class.drop-down-pages.php');
44
- include( EPS_REDIRECT_PATH.'libs/eps-plugin.php');
45
  include( EPS_REDIRECT_PATH.'libs/eps-plugin-options.php');
46
  include( EPS_REDIRECT_PATH.'plugin.php');
47
 
48
-
 
49
 
50
  class EPS_Redirects {
51
 
@@ -101,6 +101,7 @@ class EPS_Redirects {
101
  */
102
  public function do_redirect() {
103
  if ( is_admin() ) return false;
 
104
  $redirects = self::get_redirects( true ); // True for only active redirects.
105
 
106
  if (empty($redirects)) return false; // No redirects.
@@ -108,30 +109,30 @@ class EPS_Redirects {
108
  // Get current url
109
  $url_request = self::get_url();
110
 
 
111
  $query_string = explode('?', $url_request);
112
  $query_string = ( isset($query_string[1]) ) ? $query_string[1] : false;
113
 
114
-
115
  foreach ($redirects as $redirect )
116
  {
117
  $from = urldecode( $redirect->url_from );
118
- $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
119
 
120
  if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) )
121
  {
122
-
123
  // Match, this needs to be redirected
 
124
  // increment this hit counter.
125
- self::increment_field($redirect->id, 'count');
126
-
127
- if( $redirect->status == '301' ) {
128
- header ('HTTP/1.1 301 Moved Permanently');
129
- } elseif ( $redirect->status == '302' ) {
130
- header ('HTTP/1.1 301 Moved Temporarily');
131
- }
132
 
 
 
133
  $to = ( $query_string ) ? $to . "?" . $query_string : $to;
134
 
 
135
  header ('Location: ' . $to, true, (int) $redirect->status);
136
  exit();
137
  }
@@ -139,6 +140,18 @@ class EPS_Redirects {
139
  }
140
  }
141
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  /**
143
  *
144
  * FORMAT FROM URL
@@ -150,7 +163,8 @@ class EPS_Redirects {
150
  *
151
  */
152
  private function format_from_url( $string ) {
153
- //$from = home_url() . '/' . $string;
 
154
  //return strtolower( rtrim( $from,'/') );
155
 
156
 
@@ -172,16 +186,12 @@ class EPS_Redirects {
172
  */
173
  public static function get_url() {
174
  return strtolower( urldecode( $_SERVER['REQUEST_URI'] ) );
 
175
  //$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
176
  //return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
177
  }
178
 
179
-
180
-
181
-
182
-
183
 
184
-
185
  /**
186
  *
187
  * PARSE SERIAL ARRAY
@@ -443,6 +453,7 @@ class EPS_Redirects {
443
  echo json_encode( array( 'id' => $_POST['id']) );
444
  exit();
445
  }
 
446
  private static function _delete( $id ){
447
  global $wpdb;
448
  $table_name = $wpdb->prefix . "redirects";
@@ -527,39 +538,12 @@ class EPS_Redirects {
527
 
528
  public static function check_404()
529
  {
530
-
 
531
  }
532
 
533
  }
534
 
535
-
536
-
537
-
538
-
539
- /**
540
- * Outputs an object or array in a readable form.
541
- *
542
- * @return void
543
- * @param $string = the object to prettify; Typically a string.
544
- * @author epstudios
545
- */
546
- if( !function_exists('eps_prettify')) {
547
- function eps_prettify( $string ) {
548
- return ucwords( str_replace("_"," ",$string) );
549
- }
550
- }
551
-
552
- if( !function_exists('eps_view')) {
553
- function eps_view( $object ) {
554
- echo '<pre>';
555
- print_r($object);
556
- echo '</pre>';
557
- }
558
- }
559
-
560
-
561
-
562
-
563
  // Run the plugin.
564
  $EPS_Redirects = new EPS_Redirects();
565
 
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
+ * @version 2.2.7
19
  */
20
 
21
 
25
  Plugin Name: Eggplant 301 Redirects
26
  Plugin URI: http://www.eggplantstudios.ca
27
  Description: Create your own 301 redirects using this powerful plugin.
28
+ Version: 2.2.7
29
  Author: Shawn Wernig http://www.eggplantstudios.ca
30
  License: GPLv2 or later
31
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
36
 
37
  define ( 'EPS_REDIRECT_PATH', plugin_dir_path(__FILE__) );
38
  define ( 'EPS_REDIRECT_URL', plugins_url() . '/eps-301-redirects/');
39
+ define ( 'EPS_REDIRECT_VERSION', '2.2.7');
40
  define ( 'EPS_REDIRECT_PRO', false);
41
 
42
  include( EPS_REDIRECT_PATH.'eps-form-elements.php');
43
  include( EPS_REDIRECT_PATH.'class.drop-down-pages.php');
 
44
  include( EPS_REDIRECT_PATH.'libs/eps-plugin-options.php');
45
  include( EPS_REDIRECT_PATH.'plugin.php');
46
 
47
+ register_activation_hook( __FILE__, array('EPS_Redirects_Plugin', '_activation'));
48
+ register_deactivation_hook( __FILE__, array('EPS_Redirects_Plugin', '_deactivation'));
49
 
50
  class EPS_Redirects {
51
 
101
  */
102
  public function do_redirect() {
103
  if ( is_admin() ) return false;
104
+
105
  $redirects = self::get_redirects( true ); // True for only active redirects.
106
 
107
  if (empty($redirects)) return false; // No redirects.
109
  // Get current url
110
  $url_request = self::get_url();
111
 
112
+ // Extract the query string
113
  $query_string = explode('?', $url_request);
114
  $query_string = ( isset($query_string[1]) ) ? $query_string[1] : false;
115
 
116
+ // Check all redirects for matches
117
  foreach ($redirects as $redirect )
118
  {
119
  $from = urldecode( $redirect->url_from );
 
120
 
121
  if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) )
122
  {
 
123
  // Match, this needs to be redirected
124
+
125
  // increment this hit counter.
126
+ self::increment_field( $redirect->id, 'count');
127
+
128
+ // Set the header status
129
+ self::set_header_status( $redirect->status );
 
 
 
130
 
131
+ // Resolve the new location
132
+ $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
133
  $to = ( $query_string ) ? $to . "?" . $query_string : $to;
134
 
135
+ // Send em off!
136
  header ('Location: ' . $to, true, (int) $redirect->status);
137
  exit();
138
  }
140
  }
141
  }
142
 
143
+ private static function set_header_status( $status = '301' )
144
+ {
145
+ if( $status == '302' )
146
+ {
147
+ header ('HTTP/1.1 301 Moved Permanently');
148
+ }
149
+ else
150
+ {
151
+ header ('HTTP/1.1 301 Moved Temporarily');
152
+ }
153
+ }
154
+
155
  /**
156
  *
157
  * FORMAT FROM URL
163
  *
164
  */
165
  private function format_from_url( $string ) {
166
+ // Legacy, just in case I need it again.
167
+ //$from = home_url() . '/' . $string;
168
  //return strtolower( rtrim( $from,'/') );
169
 
170
 
186
  */
187
  public static function get_url() {
188
  return strtolower( urldecode( $_SERVER['REQUEST_URI'] ) );
189
+ // Legacy, just in case I need it again.
190
  //$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
191
  //return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
192
  }
193
 
 
 
 
 
194
 
 
195
  /**
196
  *
197
  * PARSE SERIAL ARRAY
453
  echo json_encode( array( 'id' => $_POST['id']) );
454
  exit();
455
  }
456
+
457
  private static function _delete( $id ){
458
  global $wpdb;
459
  $table_name = $wpdb->prefix . "redirects";
538
 
539
  public static function check_404()
540
  {
541
+ // deprecated
542
+ return false;
543
  }
544
 
545
  }
546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  // Run the plugin.
548
  $EPS_Redirects = new EPS_Redirects();
549
 
eps-form-elements.php CHANGED
@@ -25,6 +25,7 @@
25
  * @author epstudios
26
  *
27
  */
 
28
 
29
  function eps_get_selector( $redirect = false ) {
30
  $current_post = ( isset( $redirect->url_to ) && is_numeric( $redirect->url_to ) ) ? get_post( intval( $redirect->url_to ) ) : null;
25
  * @author epstudios
26
  *
27
  */
28
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
29
 
30
  function eps_get_selector( $redirect = false ) {
31
  $current_post = ( isset( $redirect->url_to ) && is_numeric( $redirect->url_to ) ) ? get_post( intval( $redirect->url_to ) ) : null;
js/scripts.js CHANGED
@@ -1,8 +1,3 @@
1
- /* Author:
2
-
3
- */
4
-
5
-
6
  jQuery(document).ready(function ($) {
7
 
8
  /**
 
 
 
 
 
1
  jQuery(document).ready(function ($) {
2
 
3
  /**
libs/eps-plugin-options.php CHANGED
@@ -1,20 +1,21 @@
1
  <?php
2
  /**
3
  *
4
- * Plugin Options Handler
5
  *
6
  * @author Shawn Wernig, Eggplant Studios, www.eggplantstudios.ca
7
- * @version 1.0.0
8
  * @copyright 2015 Eggplant Studios
9
  * @package EPS Boilerplate
10
  *
11
  *
12
  */
 
13
 
14
- if( ! class_exists('EPS_Plugin_Options') )
15
  {
16
 
17
- class EPS_Plugin_Options {
18
 
19
  /**
20
  *
@@ -37,12 +38,13 @@ class EPS_Plugin_Options {
37
  * Initialize the Theme Options, and register some actions.
38
  *
39
  */
40
- public function __construct( EPS_Plugin $Plugin ){
41
  $this->plugin = $Plugin;
42
  $this->build_settings();
43
  add_action( 'admin_init', array($this, 'options_defaults') );
44
  add_action( 'admin_init', array($this, 'register_settings') );
45
  add_action( 'admin_menu', array($this, 'add_options_page') );
 
46
  }
47
 
48
  /**
1
  <?php
2
  /**
3
  *
4
+ * Plugin Options Handler - Customized for EPS 301 Redirects
5
  *
6
  * @author Shawn Wernig, Eggplant Studios, www.eggplantstudios.ca
7
+ * @version 1.0.5
8
  * @copyright 2015 Eggplant Studios
9
  * @package EPS Boilerplate
10
  *
11
  *
12
  */
13
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
 
15
+ if( ! class_exists('EPS_Redirects_Plugin_Options') )
16
  {
17
 
18
+ class EPS_Redirects_Plugin_Options {
19
 
20
  /**
21
  *
38
  * Initialize the Theme Options, and register some actions.
39
  *
40
  */
41
+ public function __construct( EPS_Redirects_Plugin $Plugin ){
42
  $this->plugin = $Plugin;
43
  $this->build_settings();
44
  add_action( 'admin_init', array($this, 'options_defaults') );
45
  add_action( 'admin_init', array($this, 'register_settings') );
46
  add_action( 'admin_menu', array($this, 'add_options_page') );
47
+
48
  }
49
 
50
  /**
libs/eps-plugin.php DELETED
@@ -1,193 +0,0 @@
1
- <?php
2
- /**
3
- * EPS Plugin
4
- *
5
- * @author Shawn Wernig, Eggplant Studios, www.eggplantstudios.ca
6
- * @version 1.0.0
7
- * @copyright 2015 Eggplant Studios
8
- * @package EPS Boilerplate
9
- */
10
-
11
- if( ! class_exists('EPS_Plugin') )
12
- {
13
- class EPS_Plugin {
14
-
15
- protected $config = array(
16
- 'version' => '',
17
- 'option_slug' => '',
18
- 'page_slug' => '',
19
- 'page_title' => '',
20
- 'url' => '',
21
- 'path' => ''
22
- );
23
-
24
- protected $resources = array(
25
- 'css' => array(
26
- 'admin.css'
27
- ),
28
- 'js' => array(
29
- 'admin.js'
30
- )
31
- );
32
-
33
-
34
- protected $tables = array();
35
-
36
- protected $dependencies = array();
37
-
38
- protected $options;
39
-
40
- public $name = '';
41
-
42
-
43
- /**
44
- *
45
- * Constructor
46
- *
47
- * Add some actions.
48
- *
49
- */
50
- public function __construct(){
51
- $this->config['url'] = plugins_url() . $this->config['directory'] . '/';
52
- $this->config['path'] = EPS_REDIRECT_PATH . $this->config['directory'] . '/';
53
-
54
- if( class_exists('EPS_Plugin_Options') )
55
- $this->settings = new EPS_Plugin_Options( $this );
56
-
57
- register_activation_hook( __FILE__, array($this, '_activation'));
58
- register_deactivation_hook( __FILE__, array($this, '_deactivation'));
59
- if ( !self::is_current_version() ) self::update_self();
60
- add_action('init', array($this, 'plugin_resources'));
61
- }
62
-
63
-
64
- public function resolve_dependencies()
65
- {
66
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
67
- foreach( $this->dependencies as $name => $path_to_plugin )
68
- {
69
- if ( ! is_plugin_active( $path_to_plugin ) )
70
- {
71
- echo $name . ' IS NOT INSTALLED!';
72
- }
73
- }
74
- }
75
-
76
- public static function plugin_resources()
77
- {
78
-
79
- }
80
-
81
- private function resource_path( $path, $resource )
82
- {
83
- return strtolower(
84
- $this->config['url']
85
- . $path . '/'
86
- . $resource );
87
- }
88
-
89
- private function resource_name( $resource )
90
- {
91
- return strtolower( $this->name . '_' . key( $resource ) );
92
- }
93
-
94
- /**
95
- *
96
- *
97
- * Activation and Deactivation Handlers.
98
- *
99
- * @return nothing
100
- * @author epstudios
101
- */
102
- public function activation_error() {
103
- file_put_contents($this->config('path'). '/error_activation.html', ob_get_contents());
104
- }
105
-
106
- public function _activation() {
107
- if ( !self::is_current_version() ) self::update_self();
108
- }
109
-
110
- public function _deactivation() {}
111
-
112
- public static function is_current_version()
113
- {
114
- return version_compare( self::current_version(), EPS_REDIRECT_VERSION, '=') ? true : false; // TODO decouple
115
- }
116
- public static function current_version()
117
- {
118
- return get_option( 'eps_redirects_version' ); // TODO decouple
119
- }
120
- public static function set_current_version( $version )
121
- {
122
- update_option( 'eps_redirects_version', $version );
123
- }
124
- /**
125
- *
126
- * CHECK VERSION
127
- *
128
- * This function will check the current version and do any fixes required
129
- *
130
- * @return string - version number.
131
- * @author epstudios
132
- *
133
- */
134
- public function update_self() {
135
- $this->set_current_version( $this->config['version'] );
136
- return $this->config['version'];
137
- }
138
-
139
- public function config($name)
140
- {
141
- return ( isset($this->config[ $name ]) ) ? $this->config[ $name ] : false;
142
- }
143
-
144
- /**
145
- *
146
- * CREATE TABLES
147
- *
148
- * Creates the new database architecture
149
- *
150
- * TODO This could be more elegant - and check for syntax errors too.
151
- *
152
- * @return nothing
153
- * @author epstudios
154
- *
155
- */
156
- protected function _create_tables()
157
- {
158
- global $wpdb;
159
-
160
- $sql = '';
161
-
162
- foreach( $this->tables as $name => $data )
163
- {
164
- $sql .= sprintf("CREATE TABLE `%s` (\n", $wpdb->prefix . $name );
165
-
166
- foreach($data['columns'] as $name => $attr )
167
- {
168
- $sql .= sprintf( "`%s` %s, \n", $name, $attr );
169
- }
170
-
171
- $sql .= "PRIMARY KEY (`ID`), \n";
172
-
173
- if( isset($data['foreign_keys']) && !empty($data['foreign_keys']) )
174
- {
175
- foreach( $data['foreign_keys'] as $name => $reference )
176
- {
177
- $sql .= sprintf( "FOREIGN KEY (`%s`) REFERENCES %s%s ON DELETE CASCADE ON UPDATE CASCADE, \n", $name, $wpdb->prefix, $reference );
178
- }
179
- }
180
-
181
- $sql = substr($sql, 0, -3);
182
- $sql .= "\n";
183
- $sql .= ");\n\n";
184
- }
185
-
186
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
187
- dbDelta( $sql );
188
- }
189
- }
190
-
191
- }
192
-
193
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin.php CHANGED
@@ -6,11 +6,11 @@
6
  *
7
  *
8
  */
 
9
 
10
- register_activation_hook( __FILE__, array('EPS_Redirects_Plugin', '_activation'));
11
- register_deactivation_hook( __FILE__, array('EPS_Redirects_Plugin', '_deactivation'));
12
 
13
- class EPS_Redirects_Plugin extends EPS_Plugin {
 
14
 
15
  protected $config = array(
16
  'version' => EPS_REDIRECT_VERSION,
@@ -28,9 +28,33 @@ class EPS_Redirects_Plugin extends EPS_Plugin {
28
 
29
  public $name = 'EPS Redirects';
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  public function __construct()
32
  {
33
- parent::__construct();
 
 
 
 
 
 
 
 
 
 
34
 
35
  // Template Hooks
36
  add_action( 'redirects_admin_tab', array($this, 'admin_tab_redirects'), 10, 1 );
@@ -46,11 +70,39 @@ class EPS_Redirects_Plugin extends EPS_Plugin {
46
 
47
  }
48
 
49
- public function _activation()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  {
51
  self::_create_redirect_table(); // Maybe create the tables
52
  if ( !self::is_current_version() ) self::update_self();
53
  }
 
 
54
  /**
55
  *
56
  * update_self
@@ -130,7 +182,7 @@ class EPS_Redirects_Plugin extends EPS_Plugin {
130
  );";
131
 
132
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
- dbDelta( $sql );
134
  }
135
 
136
 
@@ -195,6 +247,11 @@ class EPS_Redirects_Plugin extends EPS_Plugin {
195
  if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
196
  self::_save_redirects( EPS_Redirects::_parse_serial_array($_POST['redirect']) );
197
  }
 
 
 
 
 
198
  }
199
  }
200
 
@@ -392,14 +449,66 @@ class EPS_Redirects_Plugin extends EPS_Plugin {
392
  public static function admin_header_notices()
393
  {
394
  global $wp_rewrite;
 
 
395
  if( !isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure) ) {
396
  echo '<div class="error clear"><div class="eps-padding">';
397
  echo '<strong>WARNING:</strong> EPS 301 Redirects requires that a permalink structure is set. The Default Wordpress permalink structure is not compatible. Please update the <a href="options-permalink.php" title="Permalinks">Permalink Structure</a>.</div>';
398
  echo '</div></div>';
399
  }
 
 
 
 
 
 
 
 
400
  }
401
 
402
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
 
404
  /**
405
  *
@@ -410,6 +519,10 @@ class EPS_Redirects_Plugin extends EPS_Plugin {
410
  * @author epstudios
411
  *
412
  */
 
 
 
 
413
  function admin_notice_bad_csv() {
414
  $this->admin_notice("WARNING: Not a valid CSV file! No new redirects have been added.", "error");
415
  }
6
  *
7
  *
8
  */
9
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
10
 
 
 
11
 
12
+
13
+ class EPS_Redirects_Plugin {
14
 
15
  protected $config = array(
16
  'version' => EPS_REDIRECT_VERSION,
28
 
29
  public $name = 'EPS Redirects';
30
 
31
+
32
+ protected $resources = array(
33
+ 'css' => array(
34
+ 'admin.css'
35
+ ),
36
+ 'js' => array(
37
+ 'admin.js'
38
+ )
39
+ );
40
+
41
+
42
+ protected $options;
43
+
44
+
45
  public function __construct()
46
  {
47
+ $this->config['url'] = plugins_url() . $this->config['directory'] . '/';
48
+ $this->config['path'] = EPS_REDIRECT_PATH . $this->config['directory'] . '/';
49
+
50
+ if( class_exists('EPS_Redirects_Plugin_Options') )
51
+ $this->settings = new EPS_Redirects_Plugin_Options( $this );
52
+
53
+ register_activation_hook( __FILE__, array($this, '_activation'));
54
+ register_deactivation_hook( __FILE__, array($this, '_deactivation'));
55
+
56
+ if ( !self::is_current_version() ) self::update_self();
57
+ add_action('init', array($this, 'plugin_resources'));
58
 
59
  // Template Hooks
60
  add_action( 'redirects_admin_tab', array($this, 'admin_tab_redirects'), 10, 1 );
70
 
71
  }
72
 
73
+ public function resolve_dependencies()
74
+ {
75
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
76
+ foreach( $this->dependencies as $name => $path_to_plugin )
77
+ {
78
+ if ( ! is_plugin_active( $path_to_plugin ) )
79
+ {
80
+ echo $name . ' IS NOT INSTALLED!';
81
+ }
82
+ }
83
+ }
84
+
85
+
86
+ private function resource_path( $path, $resource )
87
+ {
88
+ return strtolower(
89
+ $this->config['url']
90
+ . $path . '/'
91
+ . $resource );
92
+ }
93
+
94
+ private function resource_name( $resource )
95
+ {
96
+ return strtolower( $this->name . '_' . key( $resource ) );
97
+ }
98
+
99
+ public static function _activation()
100
  {
101
  self::_create_redirect_table(); // Maybe create the tables
102
  if ( !self::is_current_version() ) self::update_self();
103
  }
104
+ public static function _deactivation() {}
105
+
106
  /**
107
  *
108
  * update_self
182
  );";
183
 
184
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
185
+ return dbDelta( $sql );
186
  }
187
 
188
 
247
  if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
248
  self::_save_redirects( EPS_Redirects::_parse_serial_array($_POST['redirect']) );
249
  }
250
+
251
+ // Create tables
252
+ if( isset($_GET['action']) && $_GET['action'] == 'eps_create_tables' ) {
253
+ $result = self::_create_redirect_table();
254
+ }
255
  }
256
  }
257
 
449
  public static function admin_header_notices()
450
  {
451
  global $wp_rewrite;
452
+ global $wpdb;
453
+ $table_name = $wpdb->prefix . "redirects";
454
  if( !isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure) ) {
455
  echo '<div class="error clear"><div class="eps-padding">';
456
  echo '<strong>WARNING:</strong> EPS 301 Redirects requires that a permalink structure is set. The Default Wordpress permalink structure is not compatible. Please update the <a href="options-permalink.php" title="Permalinks">Permalink Structure</a>.</div>';
457
  echo '</div></div>';
458
  }
459
+
460
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
461
+ {
462
+ $url = admin_url('options-general.php?page=eps_redirects');
463
+ echo '<div class="error clear"><div class="eps-padding">';
464
+ echo '<strong>WARNING:</strong> It looks like we need to <a href="'.$url.'&action=eps_create_tables" title="Permalinks">Create the Database Tables First!</a></div>';
465
+ echo '</div></div>'; }
466
+
467
  }
468
 
469
 
470
+ /**
471
+ *
472
+ * CHECK VERSION
473
+ *
474
+ * This function will check the current version and do any fixes required
475
+ *
476
+ * @return string - version number.
477
+ * @author epstudios
478
+ *
479
+ */
480
+
481
+ public function config($name)
482
+ {
483
+ return ( isset($this->config[ $name ]) ) ? $this->config[ $name ] : false;
484
+ }
485
+
486
+ /**
487
+ *
488
+ *
489
+ * Activation and Deactivation Handlers.
490
+ *
491
+ * @return nothing
492
+ * @author epstudios
493
+ */
494
+ public function activation_error() {
495
+ file_put_contents($this->config('path'). '/error_activation.html', ob_get_contents());
496
+ }
497
+
498
+
499
+ public static function is_current_version()
500
+ {
501
+ return version_compare( self::current_version(), EPS_REDIRECT_VERSION, '=') ? true : false; // TODO decouple
502
+ }
503
+ public static function current_version()
504
+ {
505
+ return get_option( 'eps_redirects_version' ); // TODO decouple
506
+ }
507
+ public static function set_current_version( $version )
508
+ {
509
+ update_option( 'eps_redirects_version', $version );
510
+ }
511
+
512
 
513
  /**
514
  *
519
  * @author epstudios
520
  *
521
  */
522
+ function admin_notice_tables() {
523
+ $this->admin_notice('SUCCESS: Table has been created. Happy redirecting!', "success");
524
+ }
525
+
526
  function admin_notice_bad_csv() {
527
  $this->admin_notice("WARNING: Not a valid CSV file! No new redirects have been added.", "error");
528
  }
readme.txt CHANGED
@@ -10,7 +10,7 @@ Requires at least: 3.0.1
10
 
11
  Tested up to: 4.2.1
12
 
13
- Stable tag: 2.2.6
14
 
15
  License: GPLv2 or later
16
 
@@ -116,6 +116,9 @@ By default, any URL with a query string is considered unique, and will redirect
116
 
117
  == Changelog ==
118
 
 
 
 
119
  = 2.2.6 =
120
  Added support for custom plugin directories.
121
 
@@ -173,6 +176,9 @@ Overhauled the entire plugin. Redirects are stored in their own table. Gracefull
173
 
174
  == Upgrade Notice ==
175
 
 
 
 
176
  = 2.2.6 =
177
  Added support for custom plugin directories.
178
 
10
 
11
  Tested up to: 4.2.1
12
 
13
+ Stable tag: 2.2.7
14
 
15
  License: GPLv2 or later
16
 
116
 
117
  == Changelog ==
118
 
119
+ = 2.2.7 =
120
+ That silly bug with the database tables not being created has been squashed. Improved query performance.
121
+
122
  = 2.2.6 =
123
  Added support for custom plugin directories.
124
 
176
 
177
  == Upgrade Notice ==
178
 
179
+ = 2.2.7 =
180
+ That silly bug with the database tables not being created has been squashed. Improved query performance.
181
+
182
  = 2.2.6 =
183
  Added support for custom plugin directories.
184
 
templates/admin-panel-cache.php CHANGED
@@ -8,6 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
  <div class="eps-panel eps-margin-top">
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
+
13
  ?>
14
 
15
  <div class="eps-panel eps-margin-top">
templates/admin-panel-donate.php CHANGED
@@ -8,6 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
+
13
  ?>
14
 
15
 
templates/admin-tab-404s.php CHANGED
@@ -8,6 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
  <div class="wrap">
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
+
13
  ?>
14
 
15
  <div class="wrap">
templates/admin-tab-error.php CHANGED
@@ -8,6 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
+
13
  ?>
14
 
15
 
templates/admin-tab-import-export.php CHANGED
@@ -8,6 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
  <div class="wrap">
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
+
13
  ?>
14
 
15
  <div class="wrap">
templates/admin-tab-redirects.php CHANGED
@@ -8,6 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
+
13
  ?>
14
 
15
 
templates/template.redirect-entry-edit-inline.php CHANGED
@@ -9,6 +9,7 @@
9
  *
10
  */
11
 
 
12
 
13
  ?>
14
  <tr id="eps-redirect-edit">
9
  *
10
  */
11
 
12
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
 
14
  ?>
15
  <tr id="eps-redirect-edit">
templates/template.redirect-entry-edit.php CHANGED
@@ -8,6 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
 
12
  $redirect = self::get_redirect( $redirect_id );
13
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
+
13
 
14
  $redirect = self::get_redirect( $redirect_id );
15
 
templates/template.redirect-entry.php CHANGED
@@ -7,6 +7,8 @@
7
  * @package EPS 301 Redirects
8
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
9
  */
 
 
10
 
11
  global $EPS_Redirects_Plugin;
12
  $query_args = array( 'page' => $EPS_Redirects_Plugin->config('page_slug'), 'delete_redirect' => esc_attr( $redirect->id ) );
7
  * @package EPS 301 Redirects
8
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
9
  */
10
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
11
+
12
 
13
  global $EPS_Redirects_Plugin;
14
  $query_args = array( 'page' => $EPS_Redirects_Plugin->config('page_slug'), 'delete_redirect' => esc_attr( $redirect->id ) );