Eggplant 301 Redirects - Version 2.3.5

Version Description

  • 2019/03/11
  • WebFactory took over development
  • 50,000 installations; 151,500 downloads
  • bug fixes
  • compatibility fixes for new versions of PHP and WP
Download this release

Release Info

Developer WebFactory
Plugin Icon 128x128 Eggplant 301 Redirects
Version 2.3.5
Comparing to
See all releases

Code changes from version 2.3.0 to 2.3.5

class.drop-down-pages.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Drop Down Pages
4
- *
5
  * Will return a heirarchical list of pages in a key->value pair.
6
  *
7
  * @since 2.1.0
@@ -11,67 +11,73 @@
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,
19
- 'category' => '',
20
- 'orderby' => 'post_title',
21
- 'order' => 'DESC',
22
- 'include' => '',
23
- 'exclude' => '',
24
- 'meta_key' => '',
25
- 'meta_value' => '',
26
- 'post_type' => 'post',
27
- 'post_mime_type' => '',
28
- 'post_parent' => '',
29
- 'post_status' => 'publish',
30
- 'suppress_filters' => true,
31
- 'depth' => 5
32
  );
33
-
34
-
35
 
36
- $r = wp_parse_args( $args, $defaults );
37
- extract( $r, EXTR_SKIP );
38
 
39
- $pages = get_posts( $r );
40
 
41
- if ( empty($pages) ) return array();
 
42
 
43
- return array_flip( eps_walk_page_dropdown_tree($pages, $depth, $r) );
44
- }
45
 
46
- /**
 
 
 
 
 
47
  * Retrieve HTML dropdown (select) content for page list.
48
  *
49
  * @uses Walker_PageDropdown to create HTML dropdown content.
50
  * @since 2.1.0
51
  * @see Walker_PageDropdown::walk() for parameters and return description.
52
  */
53
- function eps_walk_page_dropdown_tree() {
 
54
  $args = func_get_args();
55
- $walker = ( empty($args[2]['walker']) ) ? new EPS_Walker_PageDropdown : $args[2]['walker'];
56
  return call_user_func_array(array($walker, 'walk'), $args);
57
- }
58
 
59
- /**
60
  * Create an array of pages.
61
  *
62
  * @package WordPress
63
  * @since 2.1.0
64
  * @uses Walker
65
  */
66
- class EPS_Walker_PageDropdown extends Walker {
 
67
  var $tree_type = 'page';
68
- var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
69
 
70
- function start_el(&$output, $object, $depth = 0, $args = Array(), $current_object_id = 0)
71
  {
72
- $pad = str_repeat('&nbsp;', $depth * 3);
73
- $output[$object->ID] = $pad . esc_html( apply_filters( 'list_pages', $object->post_title, $object ) );
 
 
 
 
74
  }
 
75
  }
76
- }
77
- ?>
1
  <?php
2
  /**
3
  * Drop Down Pages
4
+ *
5
  * Will return a heirarchical list of pages in a key->value pair.
6
  *
7
  * @since 2.1.0
11
  */
12
 
13
 
14
+ if (!function_exists('eps_dropdown_pages')) {
15
+ function eps_dropdown_pages($args = '')
16
+ {
17
  $defaults = array(
18
+ 'posts_per_page' => -1,
19
+ 'offset' => 0,
20
+ 'category' => '',
21
+ 'orderby' => 'post_title',
22
+ 'order' => 'DESC',
23
+ 'include' => '',
24
+ 'exclude' => '',
25
+ 'meta_key' => '',
26
+ 'meta_value' => '',
27
+ 'post_type' => 'post',
28
+ 'post_mime_type' => '',
29
+ 'post_parent' => '',
30
+ 'post_status' => 'publish',
31
+ 'suppress_filters' => true,
32
+ 'depth' => 5
33
  );
 
 
34
 
 
 
35
 
 
36
 
37
+ $r = wp_parse_args($args, $defaults);
38
+ extract($r, EXTR_SKIP);
39
 
40
+ $pages = get_posts($r);
 
41
 
42
+ if (empty($pages)) return array();
43
+
44
+ return array_flip(eps_walk_page_dropdown_tree($pages, $depth, $r));
45
+ }
46
+
47
+ /**
48
  * Retrieve HTML dropdown (select) content for page list.
49
  *
50
  * @uses Walker_PageDropdown to create HTML dropdown content.
51
  * @since 2.1.0
52
  * @see Walker_PageDropdown::walk() for parameters and return description.
53
  */
54
+ function eps_walk_page_dropdown_tree()
55
+ {
56
  $args = func_get_args();
57
+ $walker = (empty($args[2]['walker'])) ? new EPS_Walker_PageDropdown : $args[2]['walker'];
58
  return call_user_func_array(array($walker, 'walk'), $args);
59
+ }
60
 
61
+ /**
62
  * Create an array of pages.
63
  *
64
  * @package WordPress
65
  * @since 2.1.0
66
  * @uses Walker
67
  */
68
+ class EPS_Walker_PageDropdown extends Walker
69
+ {
70
  var $tree_type = 'page';
71
+ var $db_fields = array('parent' => 'post_parent', 'id' => 'ID');
72
 
73
+ function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
74
  {
75
+ if (!is_array($output)) {
76
+ $output = array();
77
+ }
78
+
79
+ $pad = str_repeat('&nbsp;', $depth * 3);
80
+ $output[$object->ID] = $pad . esc_html(apply_filters('list_pages', $object->post_title, $object));
81
  }
82
+ }
83
  }
 
 
css/eps_redirect.css CHANGED
@@ -2,180 +2,190 @@
2
  /*--------------------- Entries Table ----------------------*/
3
  /*----------------------------------------------------------*/
4
 
5
- .eps-table {
6
- width: 100%;
7
- table-layout:fixed;
8
  }
9
-
10
- .eps-table .eps-table tr, #eps-redirect-save tr {
11
- background: #fefefe;
 
12
  }
13
 
14
  #eps-redirect-save,
15
  #eps-redirect-entries,
16
  .eps-table .eps-table {
17
- border: 1px solid #eeeeee;
18
  }
19
 
20
-
21
-
22
  .eps-table tr {
23
- background: #fcfcfc;
24
  }
25
  .eps-table tr.active {
26
- display: none;
27
  }
28
 
29
  .eps-table.eps-table-striped tr:nth-child(even) {
30
- background: #fafafa;
31
  }
32
 
33
  .eps-table td,
34
  .eps-table th {
35
- padding: 5px;
36
- text-align: left;
37
- overflow: hidden;
38
  }
39
 
40
  .eps-table th a:link,
41
  .eps-table th a:visited {
42
- color: white;
43
- text-decoration: none;
44
  }
45
 
46
  .eps-table th {
47
- padding: 6px 10px;
48
- background: #2A95C5;
49
- color:#FFFFFF;
50
  }
51
 
52
- .eps-table td.redirect-small, .eps-table th.redirect-small {
53
- width: 40px;
54
- text-align: center;
55
- padding-left: 4px;
56
- padding-right: 4px;
 
57
  }
58
- .eps-table td.redirect-actions, .eps-table th.redirect-actions {
59
- width: 120px;
 
60
  }
61
 
62
-
63
  /*----------------------------------------------------------*/
64
  /*---------------------- notifications ---------------------*/
65
  /*----------------------------------------------------------*/
66
 
67
  .eps-notification-area {
68
- -webkit-border-radius: 4px;
69
- -moz-border-radius: 4px;
70
- border-radius: 4px;
71
- margin: 0px 4px; padding: 4px 8px;
72
- text-shadow: 1px 1px 1px white; display: inline-block;
73
- zoom: 1;
 
 
74
  }
75
 
76
  .eps-notification-area.valid {
77
- background: #cdf2d9; color: #195b2d; border: 1px solid #587b63;
 
 
78
  }
79
 
80
  .eps-notification-area.invalid {
81
- background: #f2cdcd; color: #6a2222; border: 1px solid #935e5e;
 
 
82
  }
83
 
84
  /*----------------------------------------------------------*/
85
  /*-------------------------- Buttons -----------------------*/
86
  /*----------------------------------------------------------*/
87
 
88
- #eps-redirect-new {
89
  display: block;
90
  background: #fafafa;
91
  border: 2px solid #f4f4f4;
92
  text-align: center;
93
  padding: 8px;
94
  text-decoration: none;
95
- width: 10%; min-width: 100px;
 
96
  margin: 0px auto;
97
  }
98
- #eps-redirect-new:hover {
99
- background: #fcfcfc;
100
- }
101
- #eps-redirect-new span {
102
- display: block;
103
- margin: 0px auto;
104
- font-size: 32px;
105
- background: #fcfcfc;
106
- border: 2px solid #f4f4f4;
107
- width: 32px; height: 32px; line-height: 32px;
108
- -webkit-border-radius: 16px;
109
- -moz-border-radius: 16px;
110
- border-radius: 16px;
111
- }
112
- #eps-redirect-new:hover span {
113
- background: #ffffff;
114
- }
115
-
116
- .url-input { display: inline-block; width: 350px; max-width: 100%; }
117
 
118
- select.eps-small-select { display: inline-block; }
 
 
 
 
119
 
 
 
 
120
 
121
  /*----------------------------------------------------------*/
122
  /*-------------------------- misc ------------------------*/
123
  /*----------------------------------------------------------*/
124
 
125
- .eps-padding { padding: 12px; }
126
- .eps-margin-top { margin-top: 12px; }
127
- .eps-grey-text { color: #999999; }
128
- .float-right { float: right; }
129
- .eps-text-center { text-align: center; }
130
- .eps-small { font-size: 10px; }
131
- .eps-url {
132
- text-decoration: none; font-size: 12px !important;
133
- background: #ffffff;
134
- display: block;
135
- border: 1px solid #eeeeee;
136
- -webkit-border-radius: 4px;
137
- -moz-border-radius: 4px;
138
- -o-border-radius: 4px;
139
- }
140
-
141
-
 
 
 
 
 
 
 
 
 
 
 
 
142
  .eps-warning.eps-url {
143
- border: 1px solid #c34343;
144
- color: #c34343;
145
  }
146
  .eps-warning.eps-url .eps-url-root {
147
- background: #f9f1f1;
148
  }
149
 
150
- #eps-redirect-save .eps-url { display: inline-block; }
151
-
152
- .eps-url > span {
153
- padding: 3px 6px;
154
- display: inline-block;
155
- background: #f4f4f4;
156
- }
157
-
158
- .eps-url .eps-url-root {
159
- color: #aaaaaa;
160
  }
161
 
162
- .eps-url .eps-url-fragment {
163
- font-weight: bold;
164
- background: #ffffff;
 
165
  }
166
 
167
- .eps-url .eps-url-endcap {
168
- -webkit-border-radius: 0px 4px 4px 0px;
169
- -moz-border-radius: 0px 4px 4px 0px;
170
- border-radius: 0px 4px 4px 0px;
171
  }
172
- .eps-url .eps-url-startcap {
173
- -webkit-border-radius: 4px 0px 0px 4px;
174
- -moz-border-radius: 4px 0px 0px 4px;
175
- border-radius: 4px 0px 0px 4px;
176
  }
177
- .eps-url .eps-url-nopadding { padding: 0px; }
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  /*----------------------------------------------------------*/
181
  /*------------------------ upgrade ------------------------*/
@@ -183,131 +193,174 @@ select.eps-small-select { display: inline-block; }
183
 
184
  .eps-redirects-big-button,
185
  .eps-redirects-big-button:link,
186
- .eps-redirects-big-button:hover
187
- {
188
- display: block;
189
- padding: 32px 16px;
190
- text-align: center;
191
- background: #444444;
192
- color: #bbbbbb;
193
- color: white;
194
- text-decoration: none;
195
- font-size: 16px;
196
- transition: all 600ms;
197
  }
198
  .eps-redirects-big-button:hover {
199
- background: #333333;
200
- color: #ffffff;
201
  }
202
  #eps-redirects-checklist {
203
- margin-top: 16px;
204
  }
205
  #eps-redirects-checklist,
206
  #eps-redirects-checklist li {
207
- display: block;
208
- list-style: none;
 
 
 
 
 
 
209
  }
210
- #eps-redirects-checklist li
211
- {
212
- border: 1px solid #eeeeee;
213
- background: url('../images/icon-check.png') left center no-repeat;
214
- padding: 16px;
215
- padding-left: 72px;
216
  }
217
- #eps-redirects-checklist li > span
218
- {
219
- border-left: 1px solid #dddddd;
220
- display: inline-block;
221
- padding: 16px;
222
- font-size: 18px; line-height: 150%;
223
  }
224
 
225
  /*----------------------------------------------------------*/
226
  /*------------------------ donate ------------------------*/
227
  /*----------------------------------------------------------*/
228
 
229
- .eps-panel { border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4; padding: 20px; }
 
 
 
 
 
230
 
231
  #donate-box {
232
- border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4;
233
- width: 250px;
234
- margin-top: 12px;
235
- float: right;
236
- text-align: center;
 
 
 
 
 
 
 
 
 
237
  }
238
- #donate-box p { margin-bottom: 12px; }
239
- #donate-box h3 { margin-bottom: 12px; font-size: 1.2em; }
240
 
241
  /*----------------------------------------------------------*/
242
  /*------------------------ Helpers ------------------------*/
243
  /*----------------------------------------------------------*/
244
 
245
  .eps-redirects-50 {
246
- width: 50%;
247
- margin: 0px; padding: 0px;
248
- float: left;
 
249
  }
250
  .eps-redirects-lead {
251
- font-size: 18px;
252
  }
253
 
254
- /* Contain floats: nicolasgallagher.com/micro-group-hack/ */
255
- .group:before, .group:after { content: ""; display: table; }
256
- .group:after { clear: both; }
257
- .group { zoom: 1; }
 
 
 
 
 
 
 
 
258
 
259
- .right { float: right; }
260
- .left { float: left; }
 
 
 
 
261
 
262
- .text-right { text-align: right; }
 
 
263
 
264
  .eps-redirects-fit {
265
- display: block; max-width: 100%; width: 100%;
 
 
266
  }
267
 
268
- .padding { padding: 16px; }
269
- .padding-lots { padding: 32px; }
270
-
 
 
 
271
 
272
  .eps-notice {
273
- padding: 16px;
274
- margin: 6px auto;
275
- background: white;
276
- box-shadow: 1px 1px 4px #dddddd;
277
- border-left: 3px solid #888888;
278
- font-weight: bold;
279
- font-size: 14px;
280
  }
281
  .eps-notice.eps-warning {
282
- border-left: 3px solid #940000;
283
- color: #940000;
284
  }
285
  /*----------------------------------------------------------*/
286
  /*-------------------- media queries ---------------------*/
287
  /*----------------------------------------------------------*/
288
 
289
- @media only screen and (max-width : 600px) {
290
- #eps-redirect-entries tr.redirect-entry .redirect-hits {
291
- width: 0px !important;
292
- }
293
- #eps-tabs { padding: 12px 12px; }
294
- .eps-url .eps-url-root { display: none; }
295
-
296
- .eps-panel{ width: 100% !important; }
297
- #eps-redirect-entries tr.redirect-entry td,
298
- #eps-redirect-entries tr.redirect-entry th { padding: 5px; }
299
- }
300
-
301
 
302
- @media only screen and (max-width : 768px) and (min-width : 600px) {
303
- .eps-panel{ width: 100% !important; }
304
- .eps-url .eps-url-root { display: none; }
305
-
 
 
 
306
  }
307
 
308
- @media only screen and (max-width : 1024px) and (min-width : 768px) {
309
- .eps-url .eps-url-root { display: none; }
310
-
311
-
 
 
 
 
312
 
 
 
 
 
313
  }
2
  /*--------------------- Entries Table ----------------------*/
3
  /*----------------------------------------------------------*/
4
 
5
+ .eps-table {
6
+ width: 100%;
7
+ table-layout: fixed;
8
  }
9
+
10
+ .eps-table .eps-table tr,
11
+ #eps-redirect-save tr {
12
+ background: #fefefe;
13
  }
14
 
15
  #eps-redirect-save,
16
  #eps-redirect-entries,
17
  .eps-table .eps-table {
18
+ border: 1px solid #eeeeee;
19
  }
20
 
 
 
21
  .eps-table tr {
22
+ background: #fcfcfc;
23
  }
24
  .eps-table tr.active {
25
+ display: none;
26
  }
27
 
28
  .eps-table.eps-table-striped tr:nth-child(even) {
29
+ background: #fafafa;
30
  }
31
 
32
  .eps-table td,
33
  .eps-table th {
34
+ padding: 5px;
35
+ text-align: left;
36
+ overflow: hidden;
37
  }
38
 
39
  .eps-table th a:link,
40
  .eps-table th a:visited {
41
+ color: white;
42
+ text-decoration: none;
43
  }
44
 
45
  .eps-table th {
46
+ padding: 6px 10px;
47
+ background: #2a95c5;
48
+ color: #ffffff;
49
  }
50
 
51
+ .eps-table td.redirect-small,
52
+ .eps-table th.redirect-small {
53
+ width: 40px;
54
+ text-align: center;
55
+ padding-left: 4px;
56
+ padding-right: 4px;
57
  }
58
+ .eps-table td.redirect-actions,
59
+ .eps-table th.redirect-actions {
60
+ width: 120px;
61
  }
62
 
 
63
  /*----------------------------------------------------------*/
64
  /*---------------------- notifications ---------------------*/
65
  /*----------------------------------------------------------*/
66
 
67
  .eps-notification-area {
68
+ -webkit-border-radius: 4px;
69
+ -moz-border-radius: 4px;
70
+ border-radius: 4px;
71
+ margin: 0px 4px;
72
+ padding: 4px 8px;
73
+ text-shadow: 1px 1px 1px white;
74
+ display: inline-block;
75
+ zoom: 1;
76
  }
77
 
78
  .eps-notification-area.valid {
79
+ background: #cdf2d9;
80
+ color: #195b2d;
81
+ border: 1px solid #587b63;
82
  }
83
 
84
  .eps-notification-area.invalid {
85
+ background: #f2cdcd;
86
+ color: #6a2222;
87
+ border: 1px solid #935e5e;
88
  }
89
 
90
  /*----------------------------------------------------------*/
91
  /*-------------------------- Buttons -----------------------*/
92
  /*----------------------------------------------------------*/
93
 
94
+ #yeps-redirect-new {
95
  display: block;
96
  background: #fafafa;
97
  border: 2px solid #f4f4f4;
98
  text-align: center;
99
  padding: 8px;
100
  text-decoration: none;
101
+ width: 10%;
102
+ min-width: 100px;
103
  margin: 0px auto;
104
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
+ .url-input {
107
+ display: inline-block;
108
+ width: 350px;
109
+ max-width: 100%;
110
+ }
111
 
112
+ select.eps-small-select {
113
+ display: inline-block;
114
+ }
115
 
116
  /*----------------------------------------------------------*/
117
  /*-------------------------- misc ------------------------*/
118
  /*----------------------------------------------------------*/
119
 
120
+ .eps-padding {
121
+ padding: 12px;
122
+ }
123
+ .eps-margin-top {
124
+ margin-top: 12px;
125
+ }
126
+ .eps-grey-text {
127
+ color: #999999;
128
+ }
129
+ .float-right {
130
+ float: right;
131
+ }
132
+ .eps-text-center {
133
+ text-align: center;
134
+ }
135
+ .eps-small {
136
+ font-size: 10px;
137
+ }
138
+ .eps-url {
139
+ text-decoration: none;
140
+ font-size: 12px !important;
141
+ background: #ffffff;
142
+ display: block;
143
+ border: 1px solid #eeeeee;
144
+ -webkit-border-radius: 4px;
145
+ -moz-border-radius: 4px;
146
+ -o-border-radius: 4px;
147
+ }
148
+
149
  .eps-warning.eps-url {
150
+ border: 1px solid #c34343;
151
+ color: #c34343;
152
  }
153
  .eps-warning.eps-url .eps-url-root {
154
+ background: #f9f1f1;
155
  }
156
 
157
+ #eps-redirect-save .eps-url {
158
+ display: inline-block;
 
 
 
 
 
 
 
 
159
  }
160
 
161
+ .eps-url > span {
162
+ padding: 3px 6px;
163
+ display: inline-block;
164
+ background: #f4f4f4;
165
  }
166
 
167
+ .eps-url .eps-url-root {
168
+ color: #aaaaaa;
 
 
169
  }
170
+
171
+ .eps-url .eps-url-fragment {
172
+ font-weight: bold;
173
+ background: #ffffff;
174
  }
 
175
 
176
+ .eps-url .eps-url-endcap {
177
+ -webkit-border-radius: 0px 4px 4px 0px;
178
+ -moz-border-radius: 0px 4px 4px 0px;
179
+ border-radius: 0px 4px 4px 0px;
180
+ }
181
+ .eps-url .eps-url-startcap {
182
+ -webkit-border-radius: 4px 0px 0px 4px;
183
+ -moz-border-radius: 4px 0px 0px 4px;
184
+ border-radius: 4px 0px 0px 4px;
185
+ }
186
+ .eps-url .eps-url-nopadding {
187
+ padding: 0px;
188
+ }
189
 
190
  /*----------------------------------------------------------*/
191
  /*------------------------ upgrade ------------------------*/
193
 
194
  .eps-redirects-big-button,
195
  .eps-redirects-big-button:link,
196
+ .eps-redirects-big-button:hover {
197
+ display: block;
198
+ padding: 32px 16px;
199
+ text-align: center;
200
+ background: #444444;
201
+ color: #bbbbbb;
202
+ color: white;
203
+ text-decoration: none;
204
+ font-size: 16px;
205
+ transition: all 600ms;
 
206
  }
207
  .eps-redirects-big-button:hover {
208
+ background: #333333;
209
+ color: #ffffff;
210
  }
211
  #eps-redirects-checklist {
212
+ margin-top: 16px;
213
  }
214
  #eps-redirects-checklist,
215
  #eps-redirects-checklist li {
216
+ display: block;
217
+ list-style: none;
218
+ }
219
+ #eps-redirects-checklist li {
220
+ border: 1px solid #eeeeee;
221
+ background: url('../images/icon-check.png') left center no-repeat;
222
+ padding: 16px;
223
+ padding-left: 72px;
224
  }
225
+ #eps-redirects-checklist li > span {
226
+ border-left: 1px solid #dddddd;
227
+ display: inline-block;
228
+ padding: 16px;
229
+ font-size: 18px;
230
+ line-height: 150%;
231
  }
232
+
233
+ a.button.eps-redirect-remove:hover {
234
+ color: red;
 
 
 
235
  }
236
 
237
  /*----------------------------------------------------------*/
238
  /*------------------------ donate ------------------------*/
239
  /*----------------------------------------------------------*/
240
 
241
+ .eps-panel {
242
+ border: 1px solid #d6d6d6;
243
+ background: white;
244
+ box-shadow: 1px 1px 6px #f4f4f4;
245
+ padding: 20px;
246
+ }
247
 
248
  #donate-box {
249
+ border: 1px solid #d6d6d6;
250
+ background: white;
251
+ box-shadow: 1px 1px 6px #f4f4f4;
252
+ width: 250px;
253
+ margin-top: 12px;
254
+ float: right;
255
+ text-align: center;
256
+ }
257
+ #donate-box p {
258
+ margin-bottom: 12px;
259
+ }
260
+ #donate-box h3 {
261
+ margin-bottom: 12px;
262
+ font-size: 1.2em;
263
  }
 
 
264
 
265
  /*----------------------------------------------------------*/
266
  /*------------------------ Helpers ------------------------*/
267
  /*----------------------------------------------------------*/
268
 
269
  .eps-redirects-50 {
270
+ width: 50%;
271
+ margin: 0px;
272
+ padding: 0px;
273
+ float: left;
274
  }
275
  .eps-redirects-lead {
276
+ font-size: 18px;
277
  }
278
 
279
+ /* Contain floats: nicolasgallagher.com/micro-group-hack/ */
280
+ .group:before,
281
+ .group:after {
282
+ content: '';
283
+ display: table;
284
+ }
285
+ .group:after {
286
+ clear: both;
287
+ }
288
+ .group {
289
+ zoom: 1;
290
+ }
291
 
292
+ .right {
293
+ float: right;
294
+ }
295
+ .left {
296
+ float: left;
297
+ }
298
 
299
+ .text-right {
300
+ text-align: right;
301
+ }
302
 
303
  .eps-redirects-fit {
304
+ display: block;
305
+ max-width: 100%;
306
+ width: 100%;
307
  }
308
 
309
+ .padding {
310
+ padding: 16px;
311
+ }
312
+ .padding-lots {
313
+ padding: 32px;
314
+ }
315
 
316
  .eps-notice {
317
+ padding: 16px;
318
+ margin: 6px auto;
319
+ background: white;
320
+ box-shadow: 1px 1px 4px #dddddd;
321
+ border-left: 3px solid #888888;
322
+ font-weight: bold;
323
+ font-size: 14px;
324
  }
325
  .eps-notice.eps-warning {
326
+ border-left: 3px solid #940000;
327
+ color: #940000;
328
  }
329
  /*----------------------------------------------------------*/
330
  /*-------------------- media queries ---------------------*/
331
  /*----------------------------------------------------------*/
332
 
333
+ @media only screen and (max-width: 600px) {
334
+ #eps-redirect-entries tr.redirect-entry .redirect-hits {
335
+ width: 0px !important;
336
+ }
337
+ #eps-tabs {
338
+ padding: 12px 12px;
339
+ }
340
+ .eps-url .eps-url-root {
341
+ display: none;
342
+ }
 
 
343
 
344
+ .eps-panel {
345
+ width: 100% !important;
346
+ }
347
+ #eps-redirect-entries tr.redirect-entry td,
348
+ #eps-redirect-entries tr.redirect-entry th {
349
+ padding: 5px;
350
+ }
351
  }
352
 
353
+ @media only screen and (max-width: 768px) and (min-width: 600px) {
354
+ .eps-panel {
355
+ width: 100% !important;
356
+ }
357
+ .eps-url .eps-url-root {
358
+ display: none;
359
+ }
360
+ }
361
 
362
+ @media only screen and (max-width: 1024px) and (min-width: 768px) {
363
+ .eps-url .eps-url-root {
364
+ display: none;
365
+ }
366
  }
eps-301-redirects.php CHANGED
@@ -1,259 +1,259 @@
1
  <?php
2
- /**
3
- *
4
- * EPS 301 REDIRECTS
5
- *
6
- *
7
- *
8
- * This plugin creates a nice Wordpress settings page for creating 301 redirects on your Wordpress
9
- * blog or website. Often used when migrating sites, or doing major redesigns, 301 redirects can
10
- * sometimes be a pain - it's my hope that this plugin helps you seamlessly create these redirects
11
- * in with this quick and efficient interface.
12
- *
13
- * PHP version 5
14
- *
15
- *
16
- * @package EPS 301 Redirects
17
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
- * @version 2.3.0
19
- */
20
-
 
 
 
 
21
 
 
 
 
 
22
 
23
-
24
- /*
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.3.0
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
32
- */
33
 
34
- if( ! defined( 'EPS_REDIRECT_PRO' ) )
35
- {
 
 
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.3.0');
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
-
52
  /**
53
- *
54
  * Constructor
55
- *
56
  * Add some actions.
57
- *
58
  */
59
- public function __construct(){
60
- global $EPS_Redirects_Plugin;
 
61
 
62
- if(is_admin() )
63
- {
64
 
65
- if( isset($_GET['page']) && $_GET['page'] == $EPS_Redirects_Plugin->config('page_slug') )
66
- {
67
- // actions
68
- add_action('activated_plugin', array($this, 'activation_error'));
69
- add_action('admin_footer_text', array($this, 'set_ajax_url'));
70
 
71
- // Other
72
- add_action('admin_init', array($this, 'clear_cache'));
 
73
 
74
- }
75
 
76
-
77
- // Ajax funcs
78
- add_action('wp_ajax_eps_redirect_get_new_entry', array($this, 'ajax_get_entry') );
79
- add_action('wp_ajax_eps_redirect_delete_entry', array($this, 'ajax_eps_delete_entry') );
80
- add_action('wp_ajax_eps_redirect_get_inline_edit_entry', array($this, 'ajax_get_inline_edit_entry') );
81
- add_action('wp_ajax_eps_redirect_save', array($this, 'ajax_save_redirect') );
 
 
 
 
 
82
 
83
- }
84
- else
85
- {
86
- add_action('init', array($this, 'do_redirect'), 1); // Priority 1 for redirects.
87
- add_action('template_redirect', array($this, 'check_404'), 1); // Priority 1 for redirects.
88
- }
 
 
89
 
90
- }
91
 
92
-
93
  /**
94
- *
95
  * DO_REDIRECT
96
- *
97
  * This function will redirect the user if it can resolve that this url request has a redirect.
98
- *
99
  * @author epstudios
100
- *
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.
107
 
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
 
119
- if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) )
120
- {
121
 
122
- // Match, this needs to be redirected
123
- // increment this hit counter.
124
- self::increment_field($redirect->id, 'count');
125
 
126
- if( $redirect->status == '301' )
127
- {
128
- header ('HTTP/1.1 301 Moved Permanently');
129
- }
130
- elseif ( $redirect->status == '302' )
131
- {
132
- header ('HTTP/1.1 302 Moved Temporarily');
133
- }
134
 
135
- $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
136
- $to = ( $query_string ) ? $to . "?" . $query_string : $to;
137
 
138
- header ('Location: ' . $to, true, (int) $redirect->status);
139
- exit();
140
- }
141
-
142
  }
 
143
  }
144
 
145
  /**
146
- *
147
  * FORMAT FROM URL
148
- *
149
  * Will construct and format the from url from what we have in storage.
150
- *
151
  * @return url string
152
  * @author epstudios
153
- *
154
  */
155
- private function format_from_url( $string ) {
156
- //$from = home_url() . '/' . $string;
157
- //return strtolower( rtrim( $from,'/') );
 
158
 
159
 
160
- $complete = home_url() . '/' . $string;
161
- list($uprotocol,$uempty,$uhost,$from) = explode( '/', $complete, 4);
162
- $from = '/' . $from;
163
- return strtolower( rtrim( $from, '/') );
164
  }
165
-
166
  /**
167
- *
168
  * GET_URL
169
- *
170
  * This function returns the current url.
171
- *
172
  * @return URL string
173
  * @author epstudios
174
- *
175
  */
176
- public static function get_url() {
177
- return strtolower( urldecode( $_SERVER['REQUEST_URI'] ) );
178
- //$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
179
- //return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
 
180
  }
181
-
182
-
183
 
184
 
185
 
186
 
187
-
 
 
188
  /**
189
- *
190
  * PARSE SERIAL ARRAY
191
- *
192
  * A necessary data parser to change the POST arrays into save-able data.
193
- *
194
  * @return array of redirects
195
  * @author epstudios
196
- *
197
  */
198
- public static function _parse_serial_array( $array ){
199
- $new_redirects = array();
200
- $total = count( $array['url_from'] );
201
-
202
- for( $i = 0; $i < $total; $i ++ ) {
203
-
204
- if( empty( $array['url_to'][$i]) || empty( $array['url_from'][$i] ) ) continue;
205
- $new_redirects[] = array(
206
- 'id' => isset( $array['id'][$i] ) ? $array['id'][$i] : null,
207
- 'url_from' => $array['url_from'][$i],
208
- 'url_to' => $array['url_to'][$i],
209
- 'type' => ( is_numeric($array['url_to'][$i]) ) ? 'post' : 'url',
210
- 'status' => isset( $array['status'][$i] ) ? $array['status'][$i] : '301'
211
- );
212
- }
213
- return $new_redirects;
 
214
  }
215
 
216
  /**
217
- *
218
  * AJAX SAVE REDIRECTS
219
- *
220
  * Saves a single redirectvia ajax.
221
- *
222
  * TODO: Maybe refactor this to reduce the number of queries.
223
- *
224
  * @return nothing
225
  * @author epstudios
226
  */
227
- public function ajax_save_redirect() {
228
-
229
- $update = array(
230
- 'id' => ( $_POST['id'] ) ? $_POST['id'] : false,
231
- 'url_from' => $_POST['url_from'], // remove the $root from the url if supplied, and a leading /
232
- 'url_to' => $_POST['url_to'],
233
- 'type' => ( is_numeric($_POST['url_to']) ? 'post' : 'url' ),
234
- 'status' => $_POST['status']
235
- );
236
-
237
- $ids = self::_save_redirects( array( $update ) );
238
-
239
- $updated_id = $ids[0]; // we expect only one returned id.
240
-
241
- // now get the new entry...
242
- $redirect = self::get_redirect( $updated_id );
243
- $html = '';
244
-
245
- ob_start();
246
- $dfrom = urldecode($redirect->url_from);
247
- $dto = urldecode($redirect->url_to );
248
- include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry.php');
249
- $html = ob_get_contents();
250
- ob_end_clean();
251
- echo json_encode( array(
252
- 'html' => $html,
253
- 'redirect_id' => $updated_id
254
- ));
255
-
256
- exit();
 
257
  }
258
 
259
  /**
@@ -265,284 +265,290 @@ class EPS_Redirects {
265
  * @param $redirect
266
  * @return bool
267
  */
268
- public static function redirect_exists( $redirect )
269
  {
270
- global $wpdb;
271
- $table_name = $wpdb->prefix . "redirects";
272
- $query = "SELECT id FROM $table_name WHERE url_from = '" . $redirect['url_from'] . "'";
273
- $result = $wpdb->get_row( $query );
274
- return ( $result ) ? $result : false;
275
  }
276
 
277
  /**
278
- *
279
  * SAVE REDIRECTS
280
- *
281
  * Saves the array of redirects.
282
- *
283
  * TODO: Maybe refactor this to reduce the number of queries.
284
- *
285
  * @return nothing
286
  * @author epstudios
287
  */
288
- public static function _save_redirects( $array ) {
289
- if( empty( $array ) ) return false;
290
- global $wpdb;
291
- $table_name = $wpdb->prefix . "redirects";
292
- $root = get_bloginfo('url') . '/';
293
- $ids = array();
294
-
295
-
296
- foreach( $array as $redirect ) {
297
-
298
- if( ! isset( $redirect['id'] ) || empty($redirect['id']) ) {
299
-
300
- // If the user supplied a post_id, is it valid? If so, use it!
301
- if( $post_id = url_to_postid( $redirect['url_to'] ) )
302
- {
303
- $redirect['url_to'] = $post_id;
304
- }
305
-
306
- // new
307
- $entry = array(
308
- 'url_from' => trim( ltrim( str_replace($root, null, $redirect['url_from']), '/' ) ),
309
- 'url_to' => trim( $redirect['url_to'] ),
310
- 'type' => trim( $redirect['type'] ),
311
- 'status' => trim( $redirect['status'] )
312
- );
313
- // Add count if exists:
314
- if( isset( $redirect['count'] ) && is_numeric( $redirect['count'] ) ) $entry['count'] = $redirect['count'];
315
-
316
- $wpdb->insert(
317
- $table_name,
318
- $entry
319
- );
320
- $ids[] = $wpdb->insert_id;
321
- }
322
- else
323
- {
324
- // existing
325
- $entry = array(
326
- 'url_from' => trim( ltrim( str_replace($root, null, $redirect['url_from']), '/' ) ),
327
- 'url_to' => trim( $redirect['url_to'] ),
328
- 'type' => trim( $redirect['type'] ),
329
- 'status' => trim( $redirect['status'] )
330
- );
331
- // Add count if exists:
332
- if( isset( $redirect['count'] ) && is_numeric( $redirect['count'] ) ) $entry['count'] = $redirect['count'];
333
-
334
- $wpdb->update(
335
- $table_name,
336
- $entry,
337
- array( 'id' => $redirect['id'] )
338
- );
339
-
340
- $ids[] = $redirect['id'];
341
- }
342
-
343
  }
344
- return $ids; // return array of affected ids.
345
-
346
  }
347
  /**
348
  *
349
- * GET REDIRECTS
350
- *
351
  * Gets the redirects. Can be switched to return Active Only redirects.
352
- *
353
  * @return array of redirects
354
  * @author epstudios
355
- *
356
  */
357
- public static function get_redirects( $active_only = false ) {
358
- global $wpdb;
359
- $table_name = $wpdb->prefix . "redirects";
360
- $orderby = ( isset($_GET['orderby']) ) ? esc_sql( $_GET['orderby'] ) : 'id';
361
- $order = ( isset($_GET['order']) ) ? esc_sql( $_GET['order'] ) : 'desc';
362
- $orderby = ( in_array( strtolower($orderby), array('id','url_from','url_to','count') ) ) ? $orderby : 'id';
363
- $order = ( in_array( strtolower($order), array('asc','desc') ) ) ? $order : 'desc';
364
-
365
- $query = "SELECT *
 
366
  FROM $table_name
367
- WHERE status != 404 " . ( ( $active_only ) ? "AND status != 'inactive'" : null ) . "
368
  ORDER BY $orderby $order";
369
- //die($query);
370
- $results = $wpdb->get_results( $query );
371
 
372
- return $results;
373
  }
374
 
375
- public static function get_all() {
376
- global $wpdb;
377
- $table_name = $wpdb->prefix . "redirects";
 
378
 
379
- $results = $wpdb->get_results(
380
- "SELECT * FROM $table_name ORDER BY id DESC"
381
- );
382
 
383
- return $results;
384
  }
385
 
386
- public static function get_redirect( $redirect_id ) {
387
- global $wpdb;
388
- $table_name = $wpdb->prefix . "redirects";
389
- $results = $wpdb->get_results(
390
- "SELECT * FROM $table_name WHERE id = " . intval($redirect_id) . " LIMIT 1"
391
- );
392
- return array_shift($results);
 
393
  }
394
-
395
  /**
396
- *
397
  * INCREMENT FIELD
398
- *
399
  * Add +1 to the specified field for a given id
400
- *
401
  * @return the result
402
  * @author epstudios
403
- *
404
  */
405
- public static function increment_field( $id, $field ) {
406
- global $wpdb;
407
- $table_name = $wpdb->prefix . "redirects";
408
- $results = $wpdb->query( "UPDATE $table_name SET $field = $field + 1 WHERE id = $id");
409
- return $results;
 
410
  }
411
-
412
  /**
413
- *
414
  * DO_INPUTS
415
- *
416
  * This function will list out all the current entries.
417
- *
418
  * @return html string
419
  * @author epstudios
420
- *
421
  */
422
- public static function list_redirects(){
423
- $redirects = self::get_redirects( );
424
- $html = '';
425
- if (empty($redirects)) return false;
426
- ob_start();
427
- foreach ($redirects as $redirect ) {
428
- $dfrom = urldecode($redirect->url_from);
429
- $dto = urldecode($redirect->url_to );
430
- include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry.php');
431
- }
432
- $html = ob_get_contents();
433
- ob_end_clean();
434
- return $html;
 
435
  }
436
 
437
  /**
438
- *
439
  * DELETE_ENTRY
440
- *
441
  * This function will remove an entry.
442
- *
443
- * @return nothing
444
  * @author epstudios
445
- *
446
  */
447
- public static function ajax_eps_delete_entry(){
448
- if( !isset($_POST['id']) ) exit();
449
-
450
- global $wpdb;
451
- $table_name = $wpdb->prefix . "redirects";
452
- $results = $wpdb->delete( $table_name, array( 'ID' => intval( $_POST['id'] ) ) );
453
- echo json_encode( array( 'id' => $_POST['id']) );
454
- exit();
 
455
  }
456
- private static function _delete( $id ){
457
- global $wpdb;
458
- $table_name = $wpdb->prefix . "redirects";
459
- $wpdb->delete( $table_name, array( 'ID' => intval( $id ) ) );
 
460
  }
461
-
462
  /**
463
- *
464
  * GET_ENTRY
465
  * AJAX_GET_ENTRY
466
  * GET_EDIT_ENTRY
467
- *
468
  * This function will return a blank row ready for user input.
469
- *
470
  * @return html string
471
  * @author epstudios
472
- *
473
  */
474
- public static function get_entry( $redirect_id = false ) {
475
- ob_start();
476
- ?>
477
- <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
478
- <?php include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit.php'); ?>
479
- </tr>
480
- <?php
481
- $html = ob_get_contents();
482
- ob_end_clean();
483
- return $html;
484
- }
485
-
486
- public static function get_inline_edit_entry($redirect_id = false) {
487
- include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit-inline.php');
488
- }
489
 
490
-
491
- public static function ajax_get_inline_edit_entry() {
492
- $redirect_id = isset( $_REQUEST['redirect_id'] ) ? intval( $_REQUEST['redirect_id'] ) : false;
493
-
494
- ob_start();
495
- self::get_inline_edit_entry($redirect_id);
496
- $html = ob_get_contents();
497
- ob_end_clean();
498
- echo json_encode( array(
499
- 'html' => $html,
500
- 'redirect_id' => $redirect_id
501
- ));
502
- exit();
503
- }
504
-
505
-
506
- public static function ajax_get_entry() {
507
- echo self::get_entry(); exit();
508
- }
509
-
510
- public function clear_cache() {
511
- header("Cache-Control: no-cache, must-revalidate");
512
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
513
- header("Content-Type: application/xml; charset=utf-8");
514
- }
515
-
516
-
517
-
518
- /**
519
- *
 
 
 
 
 
 
 
 
 
520
  * SET_AJAX_URL
521
- *
522
  * This function will output a variable containing the admin ajax url for use in javascript.
523
- *
524
  * @author epstudios
525
- *
526
  */
527
- public static function set_ajax_url() {
528
- echo '<script>var eps_redirect_ajax_url = "'. admin_url( 'admin-ajax.php' ) . '"</script>';
529
- }
530
-
531
-
532
-
533
- public function activation_error() {
534
- file_put_contents(EPS_REDIRECT_PATH. '/error_activation.html', ob_get_contents());
535
- }
536
 
537
-
538
- public static function check_404()
539
- {
540
 
541
- }
542
 
 
 
 
543
  }
544
 
545
 
 
 
 
546
 
547
 
548
 
@@ -553,41 +559,35 @@ class EPS_Redirects {
553
  * @param $string = the object to prettify; Typically a string.
554
  * @author epstudios
555
  */
556
- if( !function_exists('eps_prettify')) {
557
- function eps_prettify( $string ) {
558
- return ucwords( str_replace("_"," ",$string) );
559
- }
 
560
  }
561
 
562
- if( !function_exists('eps_view')) {
563
- function eps_view( $object ) {
 
564
  echo '<pre>';
565
  print_r($object);
566
- echo '</pre>';
567
- }
568
  }
569
 
570
 
571
-
572
-
573
  // Run the plugin.
574
  $EPS_Redirects = new EPS_Redirects();
575
-
576
- }
577
- else
578
- {
579
- if( EPS_REDIRECT_PRO === true )
580
  {
581
- add_action( 'admin_notices', 'eps_redirects_pro_conflict' );
582
- function eps_redirects_pro_conflict()
583
- {
584
- printf('<div class="%s"><p>%s</p></div>',
585
- "error",
586
- "ERROR: Please de-activate the non-Pro version of EPS 301 Redirects First!"
587
- );
588
- }
589
  }
 
590
  }
591
-
592
-
593
- ?>
1
  <?php
2
+ /*
3
+ Plugin Name: 301 Redirects
4
+ Description: Easily create and manage 301 redirects.
5
+ Version: 2.3.5
6
+ Author: WebFactory Ltd
7
+ Author URI: https://www.webfactoryltd.com/
8
+ Text Domain: eps-301-redirects
9
+
10
+ Copyright 2015 - 2019 Web factory Ltd (email: support@webfactoryltd.com)
11
+
12
+ This program is free software; you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License, version 2, as
14
+ published by the Free Software Foundation.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
+ */
25
 
26
+ // include only file
27
+ if (!defined('ABSPATH')) {
28
+ wp_die(__('Do not open this file directly.', 'eps-301-redirect'));
29
+ }
30
 
31
+ if (!defined('EPS_REDIRECT_PRO')) {
 
 
 
 
 
 
 
 
 
32
 
33
+ define('EPS_REDIRECT_PATH', plugin_dir_path(__FILE__));
34
+ define('EPS_REDIRECT_URL', plugins_url() . '/eps-301-redirects/');
35
+ define('EPS_REDIRECT_VERSION', '2.3.5');
36
+ define('EPS_REDIRECT_PRO', false);
37
 
38
+ include(EPS_REDIRECT_PATH . 'eps-form-elements.php');
39
+ include(EPS_REDIRECT_PATH . 'class.drop-down-pages.php');
40
+ include(EPS_REDIRECT_PATH . 'libs/eps-plugin-options.php');
41
+ include(EPS_REDIRECT_PATH . 'plugin.php');
42
 
43
+ register_activation_hook(__FILE__, array('EPS_Redirects_Plugin', '_activation'));
44
+ register_deactivation_hook(__FILE__, array('EPS_Redirects_Plugin', '_deactivation'));
 
 
45
 
46
+ class EPS_Redirects
47
+ {
48
 
 
 
49
  /**
50
+ *
51
  * Constructor
52
+ *
53
  * Add some actions.
54
+ *
55
  */
56
+ public function __construct()
57
+ {
58
+ global $EPS_Redirects_Plugin;
59
 
60
+ if (is_admin()) {
 
61
 
62
+ if (isset($_GET['page']) && $_GET['page'] == $EPS_Redirects_Plugin->config('page_slug')) {
63
+ // actions
64
+ add_action('activated_plugin', array($this, 'activation_error'));
65
+ add_action('admin_footer_text', array($this, 'set_ajax_url'));
 
66
 
67
+ // Other
68
+ add_action('admin_init', array($this, 'clear_cache'));
69
+ }
70
 
 
71
 
72
+ // Ajax funcs
73
+ add_action('wp_ajax_eps_redirect_get_new_entry', array($this, 'ajax_get_entry'));
74
+ add_action('wp_ajax_eps_redirect_delete_entry', array($this, 'ajax_eps_delete_entry'));
75
+ add_action('wp_ajax_eps_redirect_get_inline_edit_entry', array($this, 'ajax_get_inline_edit_entry'));
76
+ add_action('wp_ajax_eps_redirect_save', array($this, 'ajax_save_redirect'));
77
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
78
+ } else {
79
+ add_action('init', array($this, 'do_redirect'), 1); // Priority 1 for redirects.
80
+ add_action('template_redirect', array($this, 'check_404'), 1); // Priority 1 for redirects.
81
+ }
82
+ }
83
 
84
+ function plugin_action_links($links)
85
+ {
86
+ $settings_link = '<a href="' . admin_url('options-general.php?page=eps_redirects') . '" title="' . __('Configure Redirects', 'eps-301-redirects') . '">' . __('Configure Redirects', 'eps-301-redirects') . '</a>';
87
+
88
+ array_unshift($links, $settings_link);
89
+
90
+ return $links;
91
+ } // plugin_action_links
92
 
 
93
 
 
94
  /**
95
+ *
96
  * DO_REDIRECT
97
+ *
98
  * This function will redirect the user if it can resolve that this url request has a redirect.
99
+ *
100
  * @author epstudios
101
+ *
102
  */
103
+ public function do_redirect()
104
+ {
105
+ if (is_admin()) return false;
106
+ $redirects = self::get_redirects(true); // True for only active redirects.
107
 
108
+ if (empty($redirects)) return false; // No redirects.
109
 
110
+ // Get current url
111
+ $url_request = self::get_url();
112
 
113
+ $query_string = explode('?', $url_request);
114
+ $query_string = (isset($query_string[1])) ? $query_string[1] : false;
115
 
116
 
117
+ foreach ($redirects as $redirect) {
118
+ $from = urldecode($redirect->url_from);
 
119
 
120
+ if ($redirect->status != 'inactive' && rtrim(trim($url_request), '/') === self::format_from_url(trim($from))) {
 
121
 
122
+ // Match, this needs to be redirected
123
+ // increment this hit counter.
124
+ self::increment_field($redirect->id, 'count');
125
 
126
+ if ($redirect->status == '301') {
127
+ header('HTTP/1.1 301 Moved Permanently');
128
+ } elseif ($redirect->status == '302') {
129
+ header('HTTP/1.1 302 Moved Temporarily');
130
+ }
 
 
 
131
 
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
+ header('Location: ' . $to, true, (int)$redirect->status);
136
+ exit();
 
 
137
  }
138
+ }
139
  }
140
 
141
  /**
142
+ *
143
  * FORMAT FROM URL
144
+ *
145
  * Will construct and format the from url from what we have in storage.
146
+ *
147
  * @return url string
148
  * @author epstudios
149
+ *
150
  */
151
+ private function format_from_url($string)
152
+ {
153
+ //$from = home_url() . '/' . $string;
154
+ //return strtolower( rtrim( $from,'/') );
155
 
156
 
157
+ $complete = home_url() . '/' . $string;
158
+ list($uprotocol, $uempty, $uhost, $from) = explode('/', $complete, 4);
159
+ $from = '/' . $from;
160
+ return strtolower(rtrim($from, '/'));
161
  }
162
+
163
  /**
164
+ *
165
  * GET_URL
166
+ *
167
  * This function returns the current url.
168
+ *
169
  * @return URL string
170
  * @author epstudios
171
+ *
172
  */
173
+ public static function get_url()
174
+ {
175
+ return strtolower(urldecode($_SERVER['REQUEST_URI']));
176
+ //$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
177
+ //return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
178
  }
 
 
179
 
180
 
181
 
182
 
183
+
184
+
185
+
186
  /**
187
+ *
188
  * PARSE SERIAL ARRAY
189
+ *
190
  * A necessary data parser to change the POST arrays into save-able data.
191
+ *
192
  * @return array of redirects
193
  * @author epstudios
194
+ *
195
  */
196
+ public static function _parse_serial_array($array)
197
+ {
198
+ $new_redirects = array();
199
+ $total = count($array['url_from']);
200
+
201
+ for ($i = 0; $i < $total; $i++) {
202
+
203
+ if (empty($array['url_to'][$i]) || empty($array['url_from'][$i])) continue;
204
+ $new_redirects[] = array(
205
+ 'id' => isset($array['id'][$i]) ? $array['id'][$i] : null,
206
+ 'url_from' => $array['url_from'][$i],
207
+ 'url_to' => $array['url_to'][$i],
208
+ 'type' => (is_numeric($array['url_to'][$i])) ? 'post' : 'url',
209
+ 'status' => isset($array['status'][$i]) ? $array['status'][$i] : '301'
210
+ );
211
+ }
212
+ return $new_redirects;
213
  }
214
 
215
  /**
216
+ *
217
  * AJAX SAVE REDIRECTS
218
+ *
219
  * Saves a single redirectvia ajax.
220
+ *
221
  * TODO: Maybe refactor this to reduce the number of queries.
222
+ *
223
  * @return nothing
224
  * @author epstudios
225
  */
226
+ public function ajax_save_redirect()
227
+ {
228
+
229
+ $update = array(
230
+ 'id' => ($_POST['id']) ? $_POST['id'] : false,
231
+ 'url_from' => $_POST['url_from'], // remove the $root from the url if supplied, and a leading /
232
+ 'url_to' => $_POST['url_to'],
233
+ 'type' => (is_numeric($_POST['url_to']) ? 'post' : 'url'),
234
+ 'status' => $_POST['status']
235
+ );
236
+
237
+ $ids = self::_save_redirects(array($update));
238
+
239
+ $updated_id = $ids[0]; // we expect only one returned id.
240
+
241
+ // now get the new entry...
242
+ $redirect = self::get_redirect($updated_id);
243
+ $html = '';
244
+
245
+ ob_start();
246
+ $dfrom = urldecode($redirect->url_from);
247
+ $dto = urldecode($redirect->url_to);
248
+ include(EPS_REDIRECT_PATH . 'templates/template.redirect-entry.php');
249
+ $html = ob_get_contents();
250
+ ob_end_clean();
251
+ echo json_encode(array(
252
+ 'html' => $html,
253
+ 'redirect_id' => $updated_id
254
+ ));
255
+
256
+ exit();
257
  }
258
 
259
  /**
265
  * @param $redirect
266
  * @return bool
267
  */
268
+ public static function redirect_exists($redirect)
269
  {
270
+ global $wpdb;
271
+ $table_name = $wpdb->prefix . "redirects";
272
+ $query = "SELECT id FROM $table_name WHERE url_from = '" . $redirect['url_from'] . "'";
273
+ $result = $wpdb->get_row($query);
274
+ return ($result) ? $result : false;
275
  }
276
 
277
  /**
278
+ *
279
  * SAVE REDIRECTS
280
+ *
281
  * Saves the array of redirects.
282
+ *
283
  * TODO: Maybe refactor this to reduce the number of queries.
284
+ *
285
  * @return nothing
286
  * @author epstudios
287
  */
288
+ public static function _save_redirects($array)
289
+ {
290
+ if (empty($array)) return false;
291
+ global $wpdb;
292
+ $table_name = $wpdb->prefix . "redirects";
293
+ $root = get_bloginfo('url') . '/';
294
+ $ids = array();
295
+
296
+
297
+ foreach ($array as $redirect) {
298
+
299
+ if (!isset($redirect['id']) || empty($redirect['id'])) {
300
+
301
+ // If the user supplied a post_id, is it valid? If so, use it!
302
+ if ($post_id = url_to_postid($redirect['url_to'])) {
303
+ $redirect['url_to'] = $post_id;
304
+ }
305
+
306
+ // new
307
+ $entry = array(
308
+ 'url_from' => trim(ltrim(str_replace($root, null, $redirect['url_from']), '/')),
309
+ 'url_to' => trim($redirect['url_to']),
310
+ 'type' => trim($redirect['type']),
311
+ 'status' => trim($redirect['status'])
312
+ );
313
+ // Add count if exists:
314
+ if (isset($redirect['count']) && is_numeric($redirect['count'])) $entry['count'] = $redirect['count'];
315
+
316
+ $wpdb->insert(
317
+ $table_name,
318
+ $entry
319
+ );
320
+ $ids[] = $wpdb->insert_id;
321
+ } else {
322
+ // existing
323
+ $entry = array(
324
+ 'url_from' => trim(ltrim(str_replace($root, null, $redirect['url_from']), '/')),
325
+ 'url_to' => trim($redirect['url_to']),
326
+ 'type' => trim($redirect['type']),
327
+ 'status' => trim($redirect['status'])
328
+ );
329
+ // Add count if exists:
330
+ if (isset($redirect['count']) && is_numeric($redirect['count'])) $entry['count'] = $redirect['count'];
331
+
332
+ $wpdb->update(
333
+ $table_name,
334
+ $entry,
335
+ array('id' => $redirect['id'])
336
+ );
337
+
338
+ $ids[] = $redirect['id'];
 
 
 
 
339
  }
340
+ }
341
+ return $ids; // return array of affected ids.
342
  }
343
  /**
344
  *
345
+ * GET REDIRECTS
346
+ *
347
  * Gets the redirects. Can be switched to return Active Only redirects.
348
+ *
349
  * @return array of redirects
350
  * @author epstudios
351
+ *
352
  */
353
+ public static function get_redirects($active_only = false)
354
+ {
355
+ global $wpdb;
356
+ $table_name = $wpdb->prefix . "redirects";
357
+ $orderby = (isset($_GET['orderby'])) ? esc_sql($_GET['orderby']) : 'id';
358
+ $order = (isset($_GET['order'])) ? esc_sql($_GET['order']) : 'desc';
359
+ $orderby = (in_array(strtolower($orderby), array('id', 'url_from', 'url_to', 'count'))) ? $orderby : 'id';
360
+ $order = (in_array(strtolower($order), array('asc', 'desc'))) ? $order : 'desc';
361
+
362
+ $query = "SELECT *
363
  FROM $table_name
364
+ WHERE status != 404 " . (($active_only) ? "AND status != 'inactive'" : null) . "
365
  ORDER BY $orderby $order";
366
+ //die($query);
367
+ $results = $wpdb->get_results($query);
368
 
369
+ return $results;
370
  }
371
 
372
+ public static function get_all()
373
+ {
374
+ global $wpdb;
375
+ $table_name = $wpdb->prefix . "redirects";
376
 
377
+ $results = $wpdb->get_results(
378
+ "SELECT * FROM $table_name ORDER BY id DESC"
379
+ );
380
 
381
+ return $results;
382
  }
383
 
384
+ public static function get_redirect($redirect_id)
385
+ {
386
+ global $wpdb;
387
+ $table_name = $wpdb->prefix . "redirects";
388
+ $results = $wpdb->get_results(
389
+ "SELECT * FROM $table_name WHERE id = " . intval($redirect_id) . " LIMIT 1"
390
+ );
391
+ return array_shift($results);
392
  }
393
+
394
  /**
395
+ *
396
  * INCREMENT FIELD
397
+ *
398
  * Add +1 to the specified field for a given id
399
+ *
400
  * @return the result
401
  * @author epstudios
402
+ *
403
  */
404
+ public static function increment_field($id, $field)
405
+ {
406
+ global $wpdb;
407
+ $table_name = $wpdb->prefix . "redirects";
408
+ $results = $wpdb->query("UPDATE $table_name SET $field = $field + 1 WHERE id = $id");
409
+ return $results;
410
  }
411
+
412
  /**
413
+ *
414
  * DO_INPUTS
415
+ *
416
  * This function will list out all the current entries.
417
+ *
418
  * @return html string
419
  * @author epstudios
420
+ *
421
  */
422
+ public static function list_redirects()
423
+ {
424
+ $redirects = self::get_redirects();
425
+ $html = '';
426
+ if (empty($redirects)) return false;
427
+ ob_start();
428
+ foreach ($redirects as $redirect) {
429
+ $dfrom = urldecode($redirect->url_from);
430
+ $dto = urldecode($redirect->url_to);
431
+ include(EPS_REDIRECT_PATH . 'templates/template.redirect-entry.php');
432
+ }
433
+ $html = ob_get_contents();
434
+ ob_end_clean();
435
+ return $html;
436
  }
437
 
438
  /**
439
+ *
440
  * DELETE_ENTRY
441
+ *
442
  * This function will remove an entry.
443
+ *
444
+ * @return nothing
445
  * @author epstudios
446
+ *
447
  */
448
+ public static function ajax_eps_delete_entry()
449
+ {
450
+ if (!isset($_POST['id'])) exit();
451
+
452
+ global $wpdb;
453
+ $table_name = $wpdb->prefix . "redirects";
454
+ $results = $wpdb->delete($table_name, array('ID' => intval($_POST['id'])));
455
+ echo json_encode(array('id' => $_POST['id']));
456
+ exit();
457
  }
458
+ private static function _delete($id)
459
+ {
460
+ global $wpdb;
461
+ $table_name = $wpdb->prefix . "redirects";
462
+ $wpdb->delete($table_name, array('ID' => intval($id)));
463
  }
464
+
465
  /**
466
+ *
467
  * GET_ENTRY
468
  * AJAX_GET_ENTRY
469
  * GET_EDIT_ENTRY
470
+ *
471
  * This function will return a blank row ready for user input.
472
+ *
473
  * @return html string
474
  * @author epstudios
475
+ *
476
  */
477
+ public static function get_entry($redirect_id = false)
478
+ {
479
+ ob_start();
480
+ ?>
481
+ <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
482
+ <?php include(EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit.php'); ?>
483
+ </tr>
484
+ <?php
485
+ $html = ob_get_contents();
486
+ ob_end_clean();
487
+ return $html;
488
+ }
 
 
 
489
 
490
+ public static function get_inline_edit_entry($redirect_id = false)
491
+ {
492
+ include(EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit-inline.php');
493
+ }
494
+
495
+
496
+ public static function ajax_get_inline_edit_entry()
497
+ {
498
+ $redirect_id = isset($_REQUEST['redirect_id']) ? intval($_REQUEST['redirect_id']) : false;
499
+
500
+ ob_start();
501
+ self::get_inline_edit_entry($redirect_id);
502
+ $html = ob_get_contents();
503
+ ob_end_clean();
504
+ echo json_encode(array(
505
+ 'html' => $html,
506
+ 'redirect_id' => $redirect_id
507
+ ));
508
+ exit();
509
+ }
510
+
511
+
512
+ public static function ajax_get_entry()
513
+ {
514
+ echo self::get_entry();
515
+ exit();
516
+ }
517
+
518
+ public function clear_cache()
519
+ {
520
+ header("Cache-Control: no-cache, must-revalidate");
521
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
522
+ header("Content-Type: application/xml; charset=utf-8");
523
+ }
524
+
525
+
526
+
527
+ /**
528
+ *
529
  * SET_AJAX_URL
530
+ *
531
  * This function will output a variable containing the admin ajax url for use in javascript.
532
+ *
533
  * @author epstudios
534
+ *
535
  */
536
+ public static function set_ajax_url()
537
+ {
538
+ echo '<script>var eps_redirect_ajax_url = "' . admin_url('admin-ajax.php') . '"</script>';
539
+ }
 
 
 
 
 
540
 
 
 
 
541
 
 
542
 
543
+ public function activation_error()
544
+ {
545
+ file_put_contents(EPS_REDIRECT_PATH . '/error_activation.html', ob_get_contents());
546
  }
547
 
548
 
549
+ public static function check_404()
550
+ { }
551
+ }
552
 
553
 
554
 
559
  * @param $string = the object to prettify; Typically a string.
560
  * @author epstudios
561
  */
562
+ if (!function_exists('eps_prettify')) {
563
+ function eps_prettify($string)
564
+ {
565
+ return ucwords(str_replace("_", " ", $string));
566
+ }
567
  }
568
 
569
+ if (!function_exists('eps_view')) {
570
+ function eps_view($object)
571
+ {
572
  echo '<pre>';
573
  print_r($object);
574
+ echo '</pre>';
575
+ }
576
  }
577
 
578
 
 
 
579
  // Run the plugin.
580
  $EPS_Redirects = new EPS_Redirects();
581
+ } else {
582
+ if (EPS_REDIRECT_PRO === true) {
583
+ add_action('admin_notices', 'eps_redirects_pro_conflict');
584
+ function eps_redirects_pro_conflict()
 
585
  {
586
+ printf(
587
+ '<div class="%s"><p>%s</p></div>',
588
+ "error",
589
+ "ERROR: Please de-activate the non-Pro version of EPS 301 Redirects First!"
590
+ );
 
 
 
591
  }
592
+ }
593
  }
 
 
 
eps-form-elements.php CHANGED
@@ -1,213 +1,217 @@
1
  <?php
2
  /**
3
- *
4
  * EPS 301 REDIRECTS
5
- *
6
- *
7
  * eps-form-elements.php
8
- *
9
  * Responsible for some of the more 'complex' form elements such as post type dropdowns.
10
- *
11
  *
12
  *
13
  * @package EPS 301 Redirects
14
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
  * @version 2.1.0
16
  */
17
 
18
- /**
19
- *
20
  * GET_TYPE_SELECT
21
- *
22
  * This function will initialze a series of html form elements so a user can narrow down their redirect destination.
23
- *
24
  * @return html string
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;
31
-
32
- $post_types = get_post_types(array(
33
- 'public' => true
34
- ), 'objects');
35
 
36
- $html = eps_get_type_select($post_types, $current_post);
 
 
37
 
38
- // Get all the post type select boxes.
39
- foreach ($post_types as $post_type ) {
40
- $html .= eps_get_post_type_selects( $post_type->name, $current_post );
41
- }
42
-
43
- // Get the term select box.
44
- $html .= eps_get_term_archive_select();
45
-
46
- // The default input, javascript will populate this input with the final URL for submission.
47
- $html .= '<input class="eps-url-input select-eps-url-input"
 
 
48
  type="text"
49
- name="redirect[url_to][]"
50
- value="'.( isset( $redirect->url_to ) ? $redirect->url_to : null ).'"
51
- placeholder="'.get_bloginfo('url').'" ' .
52
- ( ! isset($redirect->type) || ( ( isset( $redirect->type ) && $redirect->type != 'post' ) ) ? null : ' style="display:none;"' ) .
53
- '" />';
54
 
55
- return $html;
56
  }
57
 
58
 
59
  /**
60
- *
61
  * GET_DESTINATION
62
- *
63
  * This function will output the formatted destination string.
64
- *
65
  * @return html string
66
  * @author epstudios
67
- *
68
  */
69
- function eps_get_destination( $redirect = false ) {
70
- if(isset( $redirect->url_to ) ) {
71
- if( is_numeric( $redirect->url_to ) ) {
72
- // This redirect points to a post
73
- if( get_permalink($redirect->url_to) ) {
74
- ?>
75
- <a target="_blank" class="eps-url" href="<?php echo get_permalink($redirect->url_to); ?>" title="<?php echo get_permalink($redirect->url_to); ?>">
76
- <span class="eps-url-root eps-url-startcap" ><?php echo strtoupper( get_post_type( $redirect->url_to ) ); ?></span><span class="eps-url-root">ID: <?php echo $redirect->url_to; ?> </span><span class="eps-url-fragment eps-url-endcap "><?php echo get_the_title($redirect->url_to); ?> </span>
77
- </a>
78
- <?php
79
- } else {
80
- ?>
81
- <span class="eps-url eps-warning">
82
- <span class="eps-url-root eps-url-startcap">ID: <?php echo $redirect->url_to; ?> </span>
83
- <span class="eps-url-fragment eps-url-endcap ">DOES NOT EXIST</span>
84
- </span>
85
- <?php
86
- }
87
- } else {
88
- // This is redirect points to a url
89
- ?>
90
- <a target="_blank" class="eps-url" href="<?php echo esc_attr( $redirect->url_to ); ?>" title="<?php echo esc_attr( $redirect->url_to ); ?>">
91
- <span class="eps-url-root eps-url-startcap" >URL:</span><span class="eps-url-fragment eps-url-endcap "><?php echo esc_attr( $redirect->url_to ); ?></span>
92
- </a>
93
- <?php
94
- }
95
-
96
- } else {
97
- echo '<span class="eps-warning">Invalid Destination URL</span>';
98
- }
 
 
 
 
 
99
  }
100
 
101
 
102
 
103
  /**
104
- *
105
  * GET_TYPE_SELECT
106
- *
107
  * This function will output the available destination types.
108
- *
109
  * @return html string
110
  * @author epstudios
111
- *
112
  */
113
- function eps_get_type_select( $post_types, $current_post = false ){
114
- $html = '<select class="type-select eps-small-select">';
115
- $html .= '<option value="eps-url-input">Custom</option>';
116
-
117
- foreach ($post_types as $post_type ) {
118
- $html .= '<option value="'.$post_type->name.'" '.( isset( $current_post ) && $current_post->post_type == $post_type->name ? 'selected="selected"' : null).'>'. $post_type->labels->singular_name. '</option>';
119
- }
120
- $html .= '<option value="term">Term Archive</option>';
121
- $html .= '</select>';
122
- return $html;
 
123
  }
124
 
125
 
126
  /**
127
- *
128
  * GET_POST_TYPE_SELECT
129
- *
130
  * This function will output the available post types.
131
- *
132
  * @return html string
133
  * @author epstudios
134
- *
135
  */
136
- function eps_get_post_type_selects( $post_type, $current_post = false ) {
137
- // Start the select.
138
-
139
- $html = '<select class="select-'.$post_type.' url-selector eps-small-select" '.( (isset($current_post) && $current_post->post_type == $post_type ) ? null : 'style="display:none;"').'>';
140
- $html .= '<option value="">...</option>';
141
-
142
- if ( false === ( $options = get_transient( 'post_type_cache_'.$post_type ) ) ) {
143
- $options = eps_dropdown_pages( array('post_type'=>$post_type ) );
144
- set_transient( 'post_type_cache_'.$post_type, $options, HOUR_IN_SECONDS );
145
- }
146
-
147
- foreach( $options as $option => $value ) {
148
- $html .= '<option value="'.$value.'" '.( isset($current_post) && $current_post->ID == $value ? 'selected="selected"' : null ).' >'. ucwords( $option ) . '</option>';
149
- }
150
- $html .= '</select>';
151
-
152
- return $html;
 
153
  }
154
 
155
  /**
156
- *
157
  * GET_TERM_ARCHIVE_SELECT
158
- *
159
  * This function will output a select box with all the taxonomies and terms.
160
- *
161
  * @return html string
162
  * @author epstudios
163
- *
164
  */
165
- function eps_get_term_archive_select(){
166
- $taxonomies = get_taxonomies( '', 'objects' );
167
-
168
- if (!$taxonomies) return false;
169
-
170
- // Start the select.
171
- $html = '<select class="select-term url-selector eps-small-select" style="display:none;">';
172
- $html .= '<option value="" selected default>...</option>';
173
-
174
- // Loop through all taxonomies.
175
- foreach ($taxonomies as $tax ) {
176
- $terms = get_terms( $tax->name, array('hide_empty' => false) ); // show empty terms.
177
- $html .= '<option value="'.$tax->name.'" disabled>'. $tax->labels->singular_name. '</option>';
178
-
179
- // Loop through all terms in this taxonomy and insert them as options.
180
- foreach($terms as $term)
181
- $html .= '<option value="'.get_term_link($term).'">&nbsp;&nbsp;- '. $term->name. '</option>';
182
-
183
- }
184
- $html .= '</select>';
185
- return $html;
186
  }
187
 
188
- function eps_get_ordered_filter( $field, $label, $classes = array() )
189
  {
190
- global $EPS_Redirects_Plugin;
191
- $nextOrder = 'asc';
192
- $arrow = false;
193
-
194
- if( isset( $_GET['orderby'] ) && $_GET['orderby']== $field )
195
- {
196
- $arrow = '&darr;';
197
-
198
- if( isset( $_GET['order'] ) && $_GET['order'] != 'desc' )
199
- {
200
- $nextOrder = 'desc';
201
- $arrow = '&uarr;';
202
- }
203
- }
204
 
205
- printf(
206
- '<a class="%s" href="%s">%s %s</a>',
207
- implode(' ', $classes ),
208
- $EPS_Redirects_Plugin->admin_url( array( 'orderby' => $field, 'order' => $nextOrder) ),
209
- $label,
210
- $arrow
211
- );
 
 
 
 
 
 
212
  }
213
- ?>
1
  <?php
2
  /**
3
+ *
4
  * EPS 301 REDIRECTS
5
+ *
6
+ *
7
  * eps-form-elements.php
8
+ *
9
  * Responsible for some of the more 'complex' form elements such as post type dropdowns.
10
+ *
11
  *
12
  *
13
  * @package EPS 301 Redirects
14
+ * @author WebFactory Ltd
15
  * @version 2.1.0
16
  */
17
 
18
+ /**
19
+ *
20
  * GET_TYPE_SELECT
21
+ *
22
  * This function will initialze a series of html form elements so a user can narrow down their redirect destination.
23
+ *
24
  * @return html string
25
  * @author epstudios
26
+ *
27
  */
28
 
29
+ function eps_get_selector($redirect = false)
30
+ {
31
+ $current_post = (isset($redirect->url_to) && is_numeric($redirect->url_to)) ? get_post(intval($redirect->url_to)) : null;
 
 
 
32
 
33
+ $post_types = get_post_types(array(
34
+ 'public' => true
35
+ ), 'objects');
36
 
37
+ $html = eps_get_type_select($post_types, $current_post);
38
+
39
+ // Get all the post type select boxes.
40
+ foreach ($post_types as $post_type) {
41
+ $html .= eps_get_post_type_selects($post_type->name, $current_post);
42
+ }
43
+
44
+ // Get the term select box.
45
+ $html .= eps_get_term_archive_select();
46
+
47
+ // The default input, javascript will populate this input with the final URL for submission.
48
+ $html .= '<input class="eps-url-input select-eps-url-input"
49
  type="text"
50
+ name="redirect[url_to][]"
51
+ value="' . (isset($redirect->url_to) ? $redirect->url_to : null) . '"
52
+ placeholder="' . get_bloginfo('url') . '" ' . (!isset($redirect->type) || ((isset($redirect->type) && $redirect->type != 'post')) ? null : ' style="display:none;"') .
53
+ '" />';
 
54
 
55
+ return $html;
56
  }
57
 
58
 
59
  /**
60
+ *
61
  * GET_DESTINATION
62
+ *
63
  * This function will output the formatted destination string.
64
+ *
65
  * @return html string
66
  * @author epstudios
67
+ *
68
  */
69
+ function eps_get_destination($redirect = false)
70
+ {
71
+ if (isset($redirect->url_to)) {
72
+ if (is_numeric($redirect->url_to)) {
73
+ // This redirect points to a post
74
+ if (get_permalink($redirect->url_to)) {
75
+ ?>
76
+ <a target="_blank" class="eps-url" href="<?php echo get_permalink($redirect->url_to); ?>" title="<?php echo get_permalink($redirect->url_to); ?>">
77
+ <span class="eps-url-root eps-url-startcap"><?php echo strtoupper(get_post_type($redirect->url_to)); ?></span><span class="eps-url-root">ID:
78
+ <?php echo $redirect->url_to; ?> </span><span class="eps-url-fragment eps-url-endcap "><?php echo get_the_title($redirect->url_to); ?> </span>
79
+ </a>
80
+ <?php
81
+
82
+ } else {
83
+ ?>
84
+ <span class="eps-url eps-warning">
85
+ <span class="eps-url-root eps-url-startcap">ID: <?php echo $redirect->url_to; ?> </span>
86
+ <span class="eps-url-fragment eps-url-endcap ">DOES NOT EXIST</span>
87
+ </span>
88
+ <?php
89
+
90
+ }
91
+ } else {
92
+ // This is redirect points to a url
93
+ ?>
94
+ <a target="_blank" class="eps-url" href="<?php echo esc_attr($redirect->url_to); ?>" title="<?php echo esc_attr($redirect->url_to); ?>">
95
+ <span class="eps-url-root eps-url-startcap">URL:</span><span
96
+ class="eps-url-fragment eps-url-endcap "><?php echo esc_attr($redirect->url_to); ?></span>
97
+ </a>
98
+ <?php
99
+
100
+ }
101
+ } else {
102
+ echo '<span class="eps-warning">Invalid Destination URL</span>';
103
+ }
104
  }
105
 
106
 
107
 
108
  /**
109
+ *
110
  * GET_TYPE_SELECT
111
+ *
112
  * This function will output the available destination types.
113
+ *
114
  * @return html string
115
  * @author epstudios
116
+ *
117
  */
118
+ function eps_get_type_select($post_types, $current_post = false)
119
+ {
120
+ $html = '<select class="type-select eps-small-select">';
121
+ $html .= '<option value="eps-url-input">Custom</option>';
122
+
123
+ foreach ($post_types as $post_type) {
124
+ $html .= '<option value="' . $post_type->name . '" ' . (isset($current_post) && $current_post->post_type == $post_type->name ? 'selected="selected"' : null) . '>' . $post_type->labels->singular_name . '</option>';
125
+ }
126
+ $html .= '<option value="term">Term Archive</option>';
127
+ $html .= '</select>';
128
+ return $html;
129
  }
130
 
131
 
132
  /**
133
+ *
134
  * GET_POST_TYPE_SELECT
135
+ *
136
  * This function will output the available post types.
137
+ *
138
  * @return html string
139
  * @author epstudios
140
+ *
141
  */
142
+ function eps_get_post_type_selects($post_type, $current_post = false)
143
+ {
144
+ // Start the select.
145
+
146
+ $html = '<select class="select-' . $post_type . ' url-selector eps-small-select" ' . ((isset($current_post) && $current_post->post_type == $post_type) ? null : 'style="display:none;"') . '>';
147
+ $html .= '<option value="">...</option>';
148
+
149
+ if (false === ($options = get_transient('post_type_cache_' . $post_type))) {
150
+ $options = eps_dropdown_pages(array('post_type' => $post_type));
151
+ set_transient('post_type_cache_' . $post_type, $options, HOUR_IN_SECONDS);
152
+ }
153
+
154
+ foreach ($options as $option => $value) {
155
+ $html .= '<option value="' . $value . '" ' . (isset($current_post) && $current_post->ID == $value ? 'selected="selected"' : null) . ' >' . ucwords($option) . '</option>';
156
+ }
157
+ $html .= '</select>';
158
+
159
+ return $html;
160
  }
161
 
162
  /**
163
+ *
164
  * GET_TERM_ARCHIVE_SELECT
165
+ *
166
  * This function will output a select box with all the taxonomies and terms.
167
+ *
168
  * @return html string
169
  * @author epstudios
170
+ *
171
  */
172
+ function eps_get_term_archive_select()
173
+ {
174
+ $taxonomies = get_taxonomies('', 'objects');
175
+
176
+ if (!$taxonomies) return false;
177
+
178
+ // Start the select.
179
+ $html = '<select class="select-term url-selector eps-small-select" style="display:none;">';
180
+ $html .= '<option value="" selected default>...</option>';
181
+
182
+ // Loop through all taxonomies.
183
+ foreach ($taxonomies as $tax) {
184
+ $terms = get_terms($tax->name, array('hide_empty' => false)); // show empty terms.
185
+ $html .= '<option value="' . $tax->name . '" disabled>' . $tax->labels->singular_name . '</option>';
186
+
187
+ // Loop through all terms in this taxonomy and insert them as options.
188
+ foreach ($terms as $term)
189
+ $html .= '<option value="' . get_term_link($term) . '">&nbsp;&nbsp;- ' . $term->name . '</option>';
190
+ }
191
+ $html .= '</select>';
192
+ return $html;
193
  }
194
 
195
+ function eps_get_ordered_filter($field, $label, $classes = array())
196
  {
197
+ global $EPS_Redirects_Plugin;
198
+ $nextOrder = 'asc';
199
+ $arrow = false;
200
+
201
+ if (isset($_GET['orderby']) && $_GET['orderby'] == $field) {
202
+ $arrow = '&darr;';
 
 
 
 
 
 
 
 
203
 
204
+ if (isset($_GET['order']) && $_GET['order'] != 'desc') {
205
+ $nextOrder = 'desc';
206
+ $arrow = '&uarr;';
207
+ }
208
+ }
209
+
210
+ printf(
211
+ '<a class="%s" href="%s">%s %s</a>',
212
+ implode(' ', $classes),
213
+ $EPS_Redirects_Plugin->admin_url(array('orderby' => $field, 'order' => $nextOrder)),
214
+ $label,
215
+ $arrow
216
+ );
217
  }
 
js/scripts.js CHANGED
@@ -1,253 +1,237 @@
1
- /* Author:
2
-
3
- */
4
-
5
-
6
- jQuery(document).ready(function ($) {
7
-
8
- /**
9
- *
10
- *
11
- * Loads the relevant sub-selector based on the primary selector.
12
- */
13
- $(document).on("change", 'select.type-select', function() {
14
- var input_type = $(this).val();
15
- $(this).siblings().hide();
16
- $(this).parent('td').find('.select-'+input_type).show();
17
- });
18
-
19
- /**
20
- *
21
- *
22
- * When a select box is changed, send that new value to our input.
23
- */
24
- $(document).on("change", 'select.url-selector', function() {
25
- $(this).parent('td').find('.eps-url-input').val( $(this).val() );
26
- });
27
-
28
-
29
-
30
-
31
- /**
32
- *
33
- * Edit a Redirect
34
- *
35
- * Gets the redirect edit form, and replaces the row.
36
- *
37
- *
38
- */
39
- $('.eps-table').on('click', '.redirect-actions a.eps-redirect-edit', function(e){
40
- e.preventDefault();
41
- var redirect_id = $(this).data('id');
42
- // Do the request
43
- $.ajax({
44
- type: 'POST',
45
- url: eps_redirect_ajax_url,
46
- data: {
47
- 'action': 'eps_redirect_get_inline_edit_entry',
48
- 'redirect_id': redirect_id
49
- },
50
- success: function(data){
51
- var data = jQuery.parseJSON( data );
52
- console.log( data );
53
- $('#eps-redirect-edit').remove();
54
- $('tr.redirect-entry').removeClass('active');
55
- $('tr.redirect-entry[data-id='+data.redirect_id+']').addClass('active');
56
- $(data.html).insertAfter('tr.redirect-entry[data-id='+data.redirect_id+']');
57
- $('#eps-redirect-add').show();
58
- },
59
- error: function(){
60
- // failed request; give feedback to user
61
- alert('Couldn\'t find this redirect.');
62
- }
63
- });
64
- });
65
-
66
-
67
-
68
-
69
- /**
70
- *
71
- *
72
- * Cancel an Edit.
73
- *
74
- * Cancels the Edit implement on a redirect entry.
75
- *
76
- *
77
- */
78
- $('.eps-table').on('click', 'a.eps-redirect-cancel', function(e){
79
- e.preventDefault();
80
  $('#eps-redirect-edit').remove();
81
  $('tr.redirect-entry').removeClass('active');
 
 
 
 
 
 
82
  $('#eps-redirect-add').show();
 
 
 
 
 
83
  });
84
-
85
-
86
-
87
- /**
88
- *
89
- *
90
- * AJAX Save a New or Existing Redirect.
91
- *
92
- * Checks for a form submission, then handles it VIA ajax.
93
- *
94
- */
95
- $('.eps-table').on('submit', '#eps-redirect-save', function(e){
96
- e.preventDefault();
97
-
98
- $('#eps-redirect-save input[type="submit"]').prop('disabled', true); // Disable button to disallow multiple submissions.
99
-
100
- $.ajax({
101
- type: 'POST',
102
- url: eps_redirect_ajax_url,
103
- data: {
104
- 'action': 'eps_redirect_save',
105
- 'id': $('#eps-redirect-save input[name="redirect[id][]"]').val(),
106
- 'status': $('#eps-redirect-save select[name="redirect[status][]"]').val(),
107
- 'url_from': $('#eps-redirect-save input[name="redirect[url_from][]"]').val(),
108
- 'url_to': $('#eps-redirect-save input[name="redirect[url_to][]"]').val()
109
- },
110
- success: function(data){
111
- // Successful Request:
112
- var data = jQuery.parseJSON( data );
113
-
114
- $('#eps-redirect-edit').remove();
115
- $('tr.redirect-entry').removeClass('active');
116
- if( $('tr.redirect-entry[data-id='+data.redirect_id+']').length )
117
- {
118
- // entry exists, so update it
119
- if( $('tr.redirect-entry[data-status="404"]').length )
120
- {
121
- $('tr.redirect-entry[data-id='+data.redirect_id+']').hide();
122
- }
123
- else
124
- {
125
- $('tr.redirect-entry[data-id='+data.redirect_id+']').replaceWith( data.html );
126
- }
127
- }
128
- else
129
- {
130
- // new entry, add it
131
- $(data.html).insertAfter('tr#eps-redirect-add');
132
- $('#eps-redirect-add').show();
133
- }
134
- $('#eps-redirect-save input[type="submit"]').prop('disabled', false); // Re-enable button.
135
-
136
- },
137
- error: function(){
138
- // failed request; give feedback to user
139
- alert('Couldn\'t find this redirect.');
140
- $('#eps-redirect-save input[type="submit"]').prop('disabled', false); // Re-enable button.
141
  }
142
- });
143
-
144
-
 
 
 
 
 
 
 
 
 
 
 
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  });
 
147
 
148
-
149
-
150
-
151
- /**
152
- *
153
- * New Redirect.
154
- *
155
- * Get a new blank edit form for a new redirect.
156
- *
157
- * We expect to receive an id of 0 returned from the Ajax query.
158
- *
159
- */
160
- $('.eps-table #eps-redirect-new').on('click', function(e){
161
- e.preventDefault();
162
- $(this).prop('disabled', true); $(this).attr('disabled', 'disabled'); // Disable button to disallow multiple submissions.
163
-
164
- // Do the request
165
- $.ajax({
166
- type: 'POST',
167
- url: eps_redirect_ajax_url,
168
- data: {
169
- 'action': 'eps_redirect_get_inline_edit_entry',
170
- 'redirect_id': false,
171
- },
172
- success: function(data){
173
- var data = jQuery.parseJSON( data );
174
- $('#eps-redirect-edit').remove();
175
- $('tr.redirect-entry').removeClass('active');
176
-
177
-
178
- if( data.redirect_id == 0 ) {
179
- // If it's new, do a new.
180
- $('#eps-redirect-add').hide();
181
- $(data.html).insertBefore('tr#eps-redirect-add');
182
- } else {
183
- // If it's a new blank form.. why have an id?
184
- alert('Something strange happened. A new entry could not be loaded.');
185
- }
186
- $(this).prop('disabled', false); $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
187
-
188
- },
189
- error: function(){
190
- // failed request; give feedback to user
191
- alert('A new entry form could not be loaded.');
192
- $(this).prop('disabled', false); $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
193
- }
194
- });
195
-
196
-
197
-
198
- });
199
-
200
-
201
-
202
-
203
- /**
204
- *
205
- *
206
- * Delete an entry.
207
- */
208
- $('.redirect-actions a.eps-redirect-remove').on('click', function(e){
209
- e.preventDefault();
210
- if( $(this).attr('disabled') ) return false;
211
-
212
- $(this).prop('disabled', true); $(this).attr('disabled', 'disabled'); // Disable button to disallow multiple submissions.
213
-
214
- var request = $.post( eps_redirect_ajax_url, {
215
- 'action' : 'eps_redirect_delete_entry',
216
- 'id' : $(this).data('id')
217
- });
218
- request.done(function( data ) {
219
- var response = JSON.parse(data);
220
- $('tr.redirect-entry.id-'+response.id).fadeOut();
221
- $(this).prop('disabled', false); $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
222
-
223
- });
224
-
225
- });
226
-
227
-
228
-
229
- /**
230
- *
231
- *
232
- * Tabs
233
- */
234
- $('#eps-tab-nav .eps-tab-nav-item').on('click', function(e){
235
- //e.preventDefault();
236
- var target = $(this).attr('href');
237
-
238
-
239
- $('#eps-tabs .eps-tab').hide();
240
-
241
- $(target + '-pane').show().height( 'auto' );
242
-
243
- $('#eps-tab-nav .eps-tab-nav-item').removeClass('active');
244
- $(this).addClass('active');
245
- //return false;
246
- });
247
-
248
-
249
-
250
- });
251
 
 
 
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * @package EPS 301 Redirects
3
+ * @author WebFactory Ltd
4
+ */
5
+
6
+ jQuery(document).ready(function($) {
7
+ /**
8
+ *
9
+ *
10
+ * Loads the relevant sub-selector based on the primary selector.
11
+ */
12
+ $(document).on('change', 'select.type-select', function() {
13
+ var input_type = $(this).val();
14
+ $(this)
15
+ .siblings()
16
+ .hide();
17
+ $(this)
18
+ .parent('td')
19
+ .find('.select-' + input_type)
20
+ .show();
21
+ });
22
+
23
+ /**
24
+ *
25
+ *
26
+ * When a select box is changed, send that new value to our input.
27
+ */
28
+ $(document).on('change', 'select.url-selector', function() {
29
+ $(this)
30
+ .parent('td')
31
+ .find('.eps-url-input')
32
+ .val($(this).val());
33
+ });
34
+
35
+ /**
36
+ *
37
+ * Edit a Redirect
38
+ *
39
+ * Gets the redirect edit form, and replaces the row.
40
+ *
41
+ *
42
+ */
43
+ $('.eps-table').on('click', '.redirect-actions a.eps-redirect-edit', function(
44
+ e
45
+ ) {
46
+ e.preventDefault();
47
+ var redirect_id = $(this).data('id');
48
+ // Do the request
49
+ $.ajax({
50
+ type: 'POST',
51
+ url: eps_redirect_ajax_url,
52
+ data: {
53
+ action: 'eps_redirect_get_inline_edit_entry',
54
+ redirect_id: redirect_id
55
+ },
56
+ success: function(data) {
57
+ var data = jQuery.parseJSON(data);
58
+ console.log(data);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  $('#eps-redirect-edit').remove();
60
  $('tr.redirect-entry').removeClass('active');
61
+ $('tr.redirect-entry[data-id=' + data.redirect_id + ']').addClass(
62
+ 'active'
63
+ );
64
+ $(data.html).insertAfter(
65
+ 'tr.redirect-entry[data-id=' + data.redirect_id + ']'
66
+ );
67
  $('#eps-redirect-add').show();
68
+ },
69
+ error: function() {
70
+ // failed request; give feedback to user
71
+ alert("Couldn't find this redirect.");
72
+ }
73
  });
74
+ });
75
+
76
+ /**
77
+ *
78
+ *
79
+ * Cancel an Edit.
80
+ *
81
+ * Cancels the Edit implement on a redirect entry.
82
+ *
83
+ *
84
+ */
85
+ $('.eps-table').on('click', 'a.eps-redirect-cancel', function(e) {
86
+ e.preventDefault();
87
+ $('#eps-redirect-edit').remove();
88
+ $('tr.redirect-entry').removeClass('active');
89
+ $('#eps-redirect-add').show();
90
+ });
91
+
92
+ /**
93
+ *
94
+ *
95
+ * AJAX Save a New or Existing Redirect.
96
+ *
97
+ * Checks for a form submission, then handles it VIA ajax.
98
+ *
99
+ */
100
+ $('.eps-table').on('submit', '#eps-redirect-save', function(e) {
101
+ e.preventDefault();
102
+
103
+ $('#eps-redirect-save input[type="submit"]').prop('disabled', true); // Disable button to disallow multiple submissions.
104
+
105
+ $.ajax({
106
+ type: 'POST',
107
+ url: eps_redirect_ajax_url,
108
+ data: {
109
+ action: 'eps_redirect_save',
110
+ id: $('#eps-redirect-save input[name="redirect[id][]"]').val(),
111
+ status: $('#eps-redirect-save select[name="redirect[status][]"]').val(),
112
+ url_from: $(
113
+ '#eps-redirect-save input[name="redirect[url_from][]"]'
114
+ ).val(),
115
+ url_to: $('#eps-redirect-save input[name="redirect[url_to][]"]').val()
116
+ },
117
+ success: function(data) {
118
+ // Successful Request:
119
+ var data = jQuery.parseJSON(data);
120
+
121
+ $('#eps-redirect-edit').remove();
122
+ $('tr.redirect-entry').removeClass('active');
123
+ if ($('tr.redirect-entry[data-id=' + data.redirect_id + ']').length) {
124
+ // entry exists, so update it
125
+ if ($('tr.redirect-entry[data-status="404"]').length) {
126
+ $('tr.redirect-entry[data-id=' + data.redirect_id + ']').hide();
127
+ } else {
128
+ $(
129
+ 'tr.redirect-entry[data-id=' + data.redirect_id + ']'
130
+ ).replaceWith(data.html);
131
  }
132
+ } else {
133
+ // new entry, add it
134
+ $(data.html).insertAfter('tr#eps-redirect-add');
135
+ $('#eps-redirect-add').show();
136
+ }
137
+ $('#eps-redirect-save input[type="submit"]').prop('disabled', false); // Re-enable button.
138
+ },
139
+ error: function() {
140
+ // failed request; give feedback to user
141
+ alert("Couldn't find this redirect.");
142
+ $('#eps-redirect-save input[type="submit"]').prop('disabled', false); // Re-enable button.
143
+ }
144
+ });
145
+ });
146
 
147
+ /**
148
+ *
149
+ * New Redirect.
150
+ *
151
+ * Get a new blank edit form for a new redirect.
152
+ *
153
+ * We expect to receive an id of 0 returned from the Ajax query.
154
+ *
155
+ */
156
+ $('.eps-table #eps-redirect-new').on('click', function(e) {
157
+ e.preventDefault();
158
+ $(this).prop('disabled', true);
159
+ $(this).attr('disabled', 'disabled'); // Disable button to disallow multiple submissions.
160
+
161
+ // Do the request
162
+ $.ajax({
163
+ type: 'POST',
164
+ url: eps_redirect_ajax_url,
165
+ data: {
166
+ action: 'eps_redirect_get_inline_edit_entry',
167
+ redirect_id: false
168
+ },
169
+ success: function(data) {
170
+ var data = jQuery.parseJSON(data);
171
+ $('#eps-redirect-edit').remove();
172
+ $('tr.redirect-entry').removeClass('active');
173
+
174
+ if (data.redirect_id == 0) {
175
+ // If it's new, do a new.
176
+ $('#eps-redirect-add').hide();
177
+ $(data.html).insertBefore('tr#eps-redirect-add');
178
+ } else {
179
+ // If it's a new blank form.. why have an id?
180
+ alert('Something strange happened. A new entry could not be loaded.');
181
+ }
182
+ $(this).prop('disabled', false);
183
+ $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
184
+ },
185
+ error: function() {
186
+ // failed request; give feedback to user
187
+ alert('A new entry form could not be loaded.');
188
+ $(this).prop('disabled', false);
189
+ $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
190
+ }
191
  });
192
+ });
193
 
194
+ /**
195
+ *
196
+ *
197
+ * Delete an entry.
198
+ */
199
+ $('.redirect-actions a.eps-redirect-remove').on('click', function(e) {
200
+ e.preventDefault();
201
+ if ($(this).attr('disabled')) return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
+ $(this).prop('disabled', true);
204
+ $(this).attr('disabled', 'disabled'); // Disable button to disallow multiple submissions.
205
 
206
+ var request = $.post(eps_redirect_ajax_url, {
207
+ action: 'eps_redirect_delete_entry',
208
+ id: $(this).data('id')
209
+ });
210
+ request.done(function(data) {
211
+ var response = JSON.parse(data);
212
+ $('tr.redirect-entry.id-' + response.id).fadeOut();
213
+ $(this).prop('disabled', false);
214
+ $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
215
+ });
216
+ });
217
+
218
+ /**
219
+ *
220
+ *
221
+ * Tabs
222
+ */
223
+ $('#eps-tab-nav .eps-tab-nav-item').on('click', function(e) {
224
+ //e.preventDefault();
225
+ var target = $(this).attr('href');
226
 
227
+ $('#eps-tabs .eps-tab').hide();
228
+
229
+ $(target + '-pane')
230
+ .show()
231
+ .height('auto');
232
+
233
+ $('#eps-tab-nav .eps-tab-nav-item').removeClass('active');
234
+ $(this).addClass('active');
235
+ //return false;
236
+ });
237
+ });
libs/eps-plugin-options.php CHANGED
@@ -3,18 +3,17 @@
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_Redirects_Plugin_Options') )
15
- {
16
 
17
- class EPS_Redirects_Plugin_Options {
 
18
 
19
  /**
20
  *
@@ -28,7 +27,7 @@ class EPS_Redirects_Plugin_Options {
28
  public $plugin;
29
 
30
  private $menu_locations = array(
31
- 'menu', 'dashboard', 'posts', 'media', 'links', 'pages', 'comments', 'theme', 'plugins', 'users', 'management', 'options'
32
  );
33
 
34
 
@@ -37,13 +36,13 @@ class EPS_Redirects_Plugin_Options {
37
  * Initialize the Theme Options, and register some actions.
38
  *
39
  */
40
- public function __construct( EPS_Redirects_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
 
49
  /**
@@ -51,62 +50,53 @@ class EPS_Redirects_Plugin_Options {
51
  * Pull settings from the theme-options.json file.
52
  *
53
  */
54
- private function build_settings() {
55
- $this->settings = $this->read_settings( EPS_REDIRECT_PATH . 'options.json' );
 
56
  }
57
 
58
- private function read_settings( $uri )
59
  {
60
- if( file_exists( $uri ) )
61
- {
62
- if ( is_readable( $uri ) )
63
- {
64
- $data = $this->read_json_from_file($uri);
65
- }
66
- else
67
- {
68
- chmod($uri, 0644);
69
- $data = $this->read_json_from_file($uri);
70
- if( $data )
71
- {
72
- $data = array(
73
- 'error' => array(
74
- "title" => "Oops!",
75
- "description" => "An essential file (options.json) could not be read. Please check your folder permissions.",
76
- "callback" => "error",
77
- "fields" => ''
78
- )
79
- );
80
- }
81
- }
82
- }
83
- else
84
- {
85
  $data = array(
86
- 'error' => array(
87
- "title" => "Oops!",
88
- "description" => "An essential file (options.json) could not be found. Please re-install the plugin.",
89
- "callback" => "error",
90
- "fields" => ''
91
- )
92
  );
 
93
  }
94
-
95
-
96
- return $data;
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
  private function read_json_from_file($uri)
100
  {
101
- try
102
- {
103
- $json = file_get_contents( $uri );
104
- return json_decode($json,true);
105
- }
106
- catch( Exception $e )
107
- {
108
- return false;
109
- }
110
  }
111
 
112
  /**
@@ -116,8 +106,9 @@ class EPS_Redirects_Plugin_Options {
116
  * @param string $section
117
  * @return string
118
  */
119
- private function setting_slug( $section = 'general' ) {
120
- return $this->plugin->config('option_slug') . '_' . $section;
 
121
  }
122
 
123
 
@@ -126,38 +117,38 @@ class EPS_Redirects_Plugin_Options {
126
  * Registers the settings based on the JSON file we imported.
127
  *
128
  */
129
- public function register_settings() {
130
-
131
- foreach( $this->settings as $section => $args ) {
132
-
133
- register_setting(
134
- $this->setting_slug( $section ),
135
- $this->setting_slug( $section ),
136
- array( $this, 'sanitize_inputs' )
137
- );
138
-
139
- add_settings_section(
140
- $this->setting_slug( $section ),
141
- $args['title'],
142
- // array( $this, 'section_'.$section.'_callback'),
143
- array( $this, 'section_callback'),
144
- $this->plugin->config('option_slug') . '_' . $section
145
- );
146
-
147
- foreach( $args['fields'] as $slug => $args ) {
148
- $args['section'] = $section;
149
- add_settings_field(
150
- $slug,
151
- $args['label'],
152
- array( $this, 'field_callback'),
153
- $this->setting_slug( $section ),
154
- $this->setting_slug( $section ),
155
- $args
156
- );
157
-
158
- }
159
- }
160
- }
161
 
162
 
163
  /**
@@ -167,36 +158,36 @@ class EPS_Redirects_Plugin_Options {
167
  * @param $args
168
  * @return mixed
169
  */
170
- public function sanitize_inputs( $args ) {
171
- return $args;
172
- }
 
173
 
174
  /**
175
  *
176
  * If this is the first time we're loading this, we can use the JSON file to populate some defaults.
177
  *
178
  */
179
- public function options_defaults() {
180
-
181
- foreach( $this->settings as $section => $args ) {
182
 
183
- $settings = get_option( $this->setting_slug( $section ) );
184
 
185
- if ( empty( $settings ) ) {
186
- $settings = array();
187
- foreach( $args['fields'] as $slug => $args ) {
188
- $settings[$slug] = $args['default'];
189
- }
190
 
191
- add_option( $this->setting_slug( $section ), $settings, '', 'yes' );
192
- }
 
 
 
193
 
 
194
  }
 
 
 
195
 
196
- }
197
 
198
-
199
-
200
  /**
201
  *
202
  * Outputs the Sections intro HTML. A callback.
@@ -206,18 +197,16 @@ class EPS_Redirects_Plugin_Options {
206
  * @param $args
207
  *
208
  */
209
- function section_callback( $args ) {
210
- if( isset( $_GET['tab'] ) )
211
- {
212
- $tab = $_GET['tab'];
213
- }
214
- else
215
- {
216
- $sections = array_keys( $this->settings );
217
- $tab = $sections[0];
218
- }
219
- echo $this->settings[$tab]['description'];
220
- }
221
 
222
  /**
223
  *
@@ -226,130 +215,131 @@ class EPS_Redirects_Plugin_Options {
226
  * @param $args
227
  *
228
  */
229
- function field_callback( $args ) {
230
- $option_slug = $this->setting_slug( $args['section'] );
231
- $setting = get_option( $this->setting_slug( $args['section'] ) );
232
- printf ("<input type='text' name='%s[%s]' value='%s' /><small>%s</small>",
233
- $option_slug,
234
- $args['slug'],
235
- ( isset( $setting[ $args['slug'] ] ) ? $setting[ $args['slug'] ] : null ),
236
- $args['description']
237
- );
238
- }
239
-
240
- /**
241
- *
 
 
242
  * ADD_PLUGIN_PAGE
243
- *
244
  * This function initialize the plugin settings page.
245
- *
246
  * @return string
247
  * @author epstudios
248
- *
249
  */
250
- public function add_options_page(){
251
- if( in_array( $this->plugin->config('menu_location'), $this->menu_locations ) )
252
- {
253
- $func = sprintf("add_%s_page", $this->plugin->config('menu_location') );
254
- return $func($this->plugin->name, $this->plugin->name, $this->plugin->config('page_permission'), $this->plugin->config('page_slug'), array($this, 'do_admin_page'));
255
- }
256
- else
257
- {
258
- // TODO proper errors dude.
259
- printf( 'ERROR: menu location "%s" not valid.', $this->config['menu_location'] );
260
- }
261
- return false;
262
  }
263
 
264
- /**
265
- *
266
  * DO_ADMIN_PAGE
267
- *
268
  * This function will create the admin page.
269
- *
270
  * @author epstudios
271
- *
272
  */
273
- public function do_admin_page(){
274
- $current_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : false;
275
- if( ! $current_tab )
276
- {
277
- $sections = $this->settings;
278
- $current_tab = key($sections);
279
- }
280
- ?>
281
- <div class="wrap">
282
- <h2><?php echo $this->plugin->name; ?> Settings</h2>
283
- <?php $this->get_tab_nav( $current_tab ); ?>
284
- <?php $this->get_tab( $current_tab ); ?>
285
- </div>
286
- <?php
287
- }
288
 
289
- /**
 
 
290
  *
291
  * Outputs the tab navigation based on our sections.
292
  *
293
  * @param string $current
294
  */
295
- function get_tab_nav( $current = 'general' ) {
296
- echo '<div id="icon-themes" class="icon32"><br></div>';
297
- echo '<h2 class="nav-tab-wrapper">';
298
-
299
-
300
- foreach( $this->settings as $tab => $args ){
301
- $class = ( $tab == $current ) ? ' nav-tab-active' : '';
302
- printf("<a class='nav-tab%s' href='?page=%s&tab=%s'>%s</a>",
303
- $class,
304
- $this->plugin->config('option_slug'),
305
- $tab,
306
- $args['title']
307
- );
308
- }
309
- echo '</h2>';
310
- }
311
 
312
- /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  *
314
  * Gets the content for the current tab.
315
  *
316
  * @param string $tab
317
  *
318
  */
319
- public function get_tab( $tab = 'general' ) {
320
- if ( $this->tab_exists( $tab ) ) {
321
-
322
-
323
- if( has_action( $tab.'_admin_tab'))
324
- {
325
- do_action( $tab.'_admin_tab', $this->settings[$tab] );
326
- }
327
- else
328
- {
329
- ?>
330
- <form method="post" action="<?php echo admin_url('options.php'); ?>">
331
- <?php
332
-
333
- settings_fields( $this->setting_slug( $tab ) );
334
- do_action( $this->setting_section_callback( $tab, "_before") );
335
- do_settings_sections( $this->plugin->config('option_slug') . '_' . $tab );
336
- do_action( $this->setting_section_callback($tab, '_after') );
337
- submit_button();
338
-
339
- ?>
340
- </form>
341
- <?php
342
- }
343
- }
344
- }
345
 
346
- private function setting_section_callback( $tab, $suffix = '' )
347
- {
348
- return $this->plugin->config('option_slug') . '_settings_' . $this->settings[$tab]['callback'] . $suffix;
349
- }
350
 
 
 
 
 
 
 
351
 
352
- /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  *
354
  * Checks to see if a tab exists.
355
  *
@@ -358,13 +348,12 @@ class EPS_Redirects_Plugin_Options {
358
  * @throws Exception
359
  *
360
  */
361
- public function tab_exists( $tab ) {
362
- if ( ! array_key_exists( $tab, $this->settings ) ) {
363
- throw new Exception('Tab does not exist');
364
- }
365
- return true;
366
- }
367
-
 
368
  }
369
-
370
- }
3
  *
4
  * Plugin Options Handler
5
  *
 
6
  * @version 1.0.0
7
+ * @copyright 2019 WebFactory Ltd
8
  * @package EPS Boilerplate
9
  *
10
  *
11
  */
12
 
13
+ if (!class_exists('EPS_Redirects_Plugin_Options')) {
 
14
 
15
+ class EPS_Redirects_Plugin_Options
16
+ {
17
 
18
  /**
19
  *
27
  public $plugin;
28
 
29
  private $menu_locations = array(
30
+ 'menu', 'dashboard', 'posts', 'media', 'links', 'pages', 'comments', 'theme', 'plugins', 'users', 'management', 'options'
31
  );
32
 
33
 
36
  * Initialize the Theme Options, and register some actions.
37
  *
38
  */
39
+ public function __construct(EPS_Redirects_Plugin $Plugin)
40
+ {
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
  /**
50
  * Pull settings from the theme-options.json file.
51
  *
52
  */
53
+ private function build_settings()
54
+ {
55
+ $this->settings = $this->read_settings(EPS_REDIRECT_PATH . 'options.json');
56
  }
57
 
58
+ private function read_settings($uri)
59
  {
60
+ if (file_exists($uri)) {
61
+ if (is_readable($uri)) {
62
+ $data = $this->read_json_from_file($uri);
63
+ } else {
64
+ chmod($uri, 0644);
65
+ $data = $this->read_json_from_file($uri);
66
+ if ($data) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  $data = array(
68
+ 'error' => array(
69
+ "title" => "Oops!",
70
+ "description" => "An essential file (options.json) could not be read. Please check your folder permissions.",
71
+ "callback" => "error",
72
+ "fields" => ''
73
+ )
74
  );
75
+ }
76
  }
77
+ } else {
78
+ $data = array(
79
+ 'error' => array(
80
+ "title" => "Oops!",
81
+ "description" => "An essential file (options.json) could not be found. Please re-install the plugin.",
82
+ "callback" => "error",
83
+ "fields" => ''
84
+ )
85
+ );
86
+ }
87
+
88
+
89
+ return $data;
90
  }
91
 
92
  private function read_json_from_file($uri)
93
  {
94
+ try {
95
+ $json = file_get_contents($uri);
96
+ return json_decode($json, true);
97
+ } catch (Exception $e) {
98
+ return false;
99
+ }
 
 
 
100
  }
101
 
102
  /**
106
  * @param string $section
107
  * @return string
108
  */
109
+ private function setting_slug($section = 'general')
110
+ {
111
+ return $this->plugin->config('option_slug') . '_' . $section;
112
  }
113
 
114
 
117
  * Registers the settings based on the JSON file we imported.
118
  *
119
  */
120
+ public function register_settings()
121
+ {
122
+
123
+ foreach ($this->settings as $section => $args) {
124
+
125
+ register_setting(
126
+ $this->setting_slug($section),
127
+ $this->setting_slug($section),
128
+ array($this, 'sanitize_inputs')
129
+ );
130
+
131
+ add_settings_section(
132
+ $this->setting_slug($section),
133
+ $args['title'],
134
+ // array( $this, 'section_'.$section.'_callback'),
135
+ array($this, 'section_callback'),
136
+ $this->plugin->config('option_slug') . '_' . $section
137
+ );
138
+
139
+ foreach ($args['fields'] as $slug => $args) {
140
+ $args['section'] = $section;
141
+ add_settings_field(
142
+ $slug,
143
+ $args['label'],
144
+ array($this, 'field_callback'),
145
+ $this->setting_slug($section),
146
+ $this->setting_slug($section),
147
+ $args
148
+ );
149
+ }
150
+ }
151
+ }
152
 
153
 
154
  /**
158
  * @param $args
159
  * @return mixed
160
  */
161
+ public function sanitize_inputs($args)
162
+ {
163
+ return $args;
164
+ }
165
 
166
  /**
167
  *
168
  * If this is the first time we're loading this, we can use the JSON file to populate some defaults.
169
  *
170
  */
171
+ public function options_defaults()
172
+ {
 
173
 
174
+ foreach ($this->settings as $section => $args) {
175
 
176
+ $settings = get_option($this->setting_slug($section));
 
 
 
 
177
 
178
+ if (empty($settings)) {
179
+ $settings = array();
180
+ foreach ($args['fields'] as $slug => $args) {
181
+ $settings[$slug] = $args['default'];
182
+ }
183
 
184
+ add_option($this->setting_slug($section), $settings, '', 'yes');
185
  }
186
+ }
187
+ }
188
+
189
 
 
190
 
 
 
191
  /**
192
  *
193
  * Outputs the Sections intro HTML. A callback.
197
  * @param $args
198
  *
199
  */
200
+ function section_callback($args)
201
+ {
202
+ if (isset($_GET['tab'])) {
203
+ $tab = $_GET['tab'];
204
+ } else {
205
+ $sections = array_keys($this->settings);
206
+ $tab = $sections[0];
207
+ }
208
+ echo $this->settings[$tab]['description'];
209
+ }
 
 
210
 
211
  /**
212
  *
215
  * @param $args
216
  *
217
  */
218
+ function field_callback($args)
219
+ {
220
+ $option_slug = $this->setting_slug($args['section']);
221
+ $setting = get_option($this->setting_slug($args['section']));
222
+ printf(
223
+ "<input type='text' name='%s[%s]' value='%s' /><small>%s</small>",
224
+ $option_slug,
225
+ $args['slug'],
226
+ (isset($setting[$args['slug']]) ? $setting[$args['slug']] : null),
227
+ $args['description']
228
+ );
229
+ }
230
+
231
+ /**
232
+ *
233
  * ADD_PLUGIN_PAGE
234
+ *
235
  * This function initialize the plugin settings page.
236
+ *
237
  * @return string
238
  * @author epstudios
239
+ *
240
  */
241
+ public function add_options_page()
242
+ {
243
+ if (in_array($this->plugin->config('menu_location'), $this->menu_locations)) {
244
+ $func = sprintf("add_%s_page", $this->plugin->config('menu_location'));
245
+ return $func($this->plugin->name, $this->plugin->name, $this->plugin->config('page_permission'), $this->plugin->config('page_slug'), array($this, 'do_admin_page'));
246
+ } else {
247
+ // TODO proper errors dude.
248
+ printf('ERROR: menu location "%s" not valid.', $this->config['menu_location']);
249
+ }
250
+ return false;
 
 
251
  }
252
 
253
+ /**
254
+ *
255
  * DO_ADMIN_PAGE
256
+ *
257
  * This function will create the admin page.
258
+ *
259
  * @author epstudios
260
+ *
261
  */
262
+ public function do_admin_page()
263
+ {
264
+ $current_tab = isset($_GET['tab']) ? $_GET['tab'] : false;
265
+ if (!$current_tab) {
266
+ $sections = $this->settings;
267
+ $current_tab = key($sections);
268
+ }
269
+ ?>
270
+ <div class="wrap">
271
+ <h2><?php echo $this->plugin->name; ?></h2><br>
272
+ <?php $this->get_tab_nav($current_tab); ?>
273
+ <?php $this->get_tab($current_tab); ?>
274
+ </div>
275
+ <?php
 
276
 
277
+ }
278
+
279
+ /**
280
  *
281
  * Outputs the tab navigation based on our sections.
282
  *
283
  * @param string $current
284
  */
285
+ function get_tab_nav($current = 'general')
286
+ {
287
+ echo '<h2 class="nav-tab-wrapper">';
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
+
290
+ foreach ($this->settings as $tab => $args) {
291
+ $class = ($tab == $current) ? ' nav-tab-active' : '';
292
+ printf(
293
+ "<a class='nav-tab%s' href='?page=%s&tab=%s'>%s</a>",
294
+ $class,
295
+ $this->plugin->config('option_slug'),
296
+ $tab,
297
+ $args['title']
298
+ );
299
+ }
300
+ echo '</h2>';
301
+ }
302
+
303
+ /**
304
  *
305
  * Gets the content for the current tab.
306
  *
307
  * @param string $tab
308
  *
309
  */
310
+ public function get_tab($tab = 'general')
311
+ {
312
+ if ($this->tab_exists($tab)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
 
 
 
 
 
314
 
315
+ if (has_action($tab . '_admin_tab')) {
316
+ do_action($tab . '_admin_tab', $this->settings[$tab]);
317
+ } else {
318
+ ?>
319
+ <form method="post" action="<?php echo admin_url('options.php'); ?>">
320
+ <?php
321
 
322
+ settings_fields($this->setting_slug($tab));
323
+ do_action($this->setting_section_callback($tab, "_before"));
324
+ do_settings_sections($this->plugin->config('option_slug') . '_' . $tab);
325
+ do_action($this->setting_section_callback($tab, '_after'));
326
+ submit_button();
327
+
328
+ ?>
329
+ </form>
330
+ <?php
331
+
332
+ }
333
+ }
334
+ }
335
+
336
+ private function setting_section_callback($tab, $suffix = '')
337
+ {
338
+ return $this->plugin->config('option_slug') . '_settings_' . $this->settings[$tab]['callback'] . $suffix;
339
+ }
340
+
341
+
342
+ /**
343
  *
344
  * Checks to see if a tab exists.
345
  *
348
  * @throws Exception
349
  *
350
  */
351
+ public function tab_exists($tab)
352
+ {
353
+ if (!array_key_exists($tab, $this->settings)) {
354
+ throw new Exception('Tab does not exist');
355
+ }
356
+ return true;
357
+ }
358
+ }
359
  }
 
 
options.json CHANGED
@@ -1,20 +1,20 @@
1
  {
2
- "redirects":{
3
- "title":"Redirects",
4
- "description":"",
5
- "callback":"redirects",
6
- "fields":{}
7
- },
8
- "404s":{
9
- "title":"404s",
10
- "description":"",
11
- "callback":"404s",
12
- "fields":{}
13
- },
14
- "import-export":{
15
- "title":"Import/Export",
16
- "description":"",
17
- "callback":"import_export",
18
- "fields":{}
19
- }
20
- }
1
  {
2
+ "redirects": {
3
+ "title": "Redirect Rules",
4
+ "description": "",
5
+ "callback": "redirects",
6
+ "fields": {}
7
+ },
8
+ "404s": {
9
+ "title": "404 Error Log",
10
+ "description": "",
11
+ "callback": "404s",
12
+ "fields": {}
13
+ },
14
+ "import-export": {
15
+ "title": "Import/Export Redirect Rules",
16
+ "description": "",
17
+ "callback": "import_export",
18
+ "fields": {}
19
+ }
20
+ }
plugin.php CHANGED
@@ -9,106 +9,106 @@
9
 
10
 
11
 
12
- class EPS_Redirects_Plugin {
13
-
14
- protected $config = array(
15
- 'version' => EPS_REDIRECT_VERSION,
16
- 'option_slug' => 'eps_redirects',
17
- 'page_slug' => 'eps_redirects',
18
- 'page_title' => 'EPS Redirects',
19
- 'menu_location' => 'options',
20
- 'page_permission' => 'manage_options',
21
- 'directory' => 'eps-301-redirects'
22
- );
23
-
24
- protected $dependancies = array();
25
-
26
- protected $tables = array();
27
-
28
- public $name = 'EPS Redirects';
29
-
30
-
31
- protected $resources = array(
32
- 'css' => array(
33
- 'admin.css'
34
- ),
35
- 'js' => array(
36
- 'admin.js'
37
- )
38
- );
39
-
40
-
41
- protected $options;
42
- protected $messages = array();
43
-
44
- public function __construct()
45
- {
46
- $this->config['url'] = plugins_url() . $this->config['directory'] . '/';
47
- $this->config['path'] = EPS_REDIRECT_PATH . $this->config['directory'] . '/';
48
-
49
- if( class_exists('EPS_Redirects_Plugin_Options') )
50
- $this->settings = new EPS_Redirects_Plugin_Options( $this );
51
-
52
- register_activation_hook( __FILE__, array($this, '_activation'));
53
- register_deactivation_hook( __FILE__, array($this, '_deactivation'));
54
-
55
- if ( !self::is_current_version() ) self::update_self();
56
- add_action('init', array($this, 'plugin_resources'));
57
-
58
- // Template Hooks
59
- add_action( 'redirects_admin_tab', array($this, 'admin_tab_redirects'), 10, 1 );
60
- add_action( '404s_admin_tab', array($this, 'admin_tab_404s'), 10, 1 );
61
- add_action( 'error_admin_tab', array($this, 'admin_tab_error'), 10, 1 );
62
- add_action( 'import-export_admin_tab', array($this, 'admin_tab_import_export'), 10, 1 );
63
- add_action( 'eps_redirects_panels_left', array($this, 'admin_panel_cache'));
64
- add_action( 'eps_redirects_panels_right', array($this, 'admin_panel_donate'));
65
-
66
- // Actions
67
- add_action( 'admin_init', array($this, 'check_plugin_actions'));
68
-
69
- }
70
-
71
- public function resolve_dependencies()
72
- {
73
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
74
- foreach( $this->dependencies as $name => $path_to_plugin )
75
- {
76
- if ( ! is_plugin_active( $path_to_plugin ) )
77
- {
78
- echo $name . ' IS NOT INSTALLED!';
79
- }
80
- }
81
- }
82
-
83
-
84
- private function resource_path( $path, $resource )
85
- {
86
- return strtolower(
87
- $this->config['url']
88
- . $path . '/'
89
- . $resource );
90
- }
91
-
92
- private function resource_name( $resource )
93
- {
94
- return strtolower( $this->name . '_' . key( $resource ) );
95
  }
96
-
97
- public static function _activation()
98
- {
99
- self::_create_redirect_table(); // Maybe create the tables
100
- if ( !self::is_current_version() ) self::update_self();
101
- }
102
- public static function _deactivation() {}
103
 
104
 
105
- public function admin_url( $vars = array() )
106
- {
107
- $vars = array( 'page' => $this->config['page_slug'] ) + $vars;
108
- $url = 'options-general.php?' . http_build_query( $vars );
109
- return admin_url( $url );
110
- }
111
- /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  *
113
  * update_self
114
  *
@@ -118,19 +118,19 @@ class EPS_Redirects_Plugin {
118
  * @author epstudios
119
  *
120
  */
121
- public function update_self()
122
- {
123
- $version = get_option( 'eps_redirects_version' );
124
 
125
- if( version_compare($version, '2.0.0', '<')) {
126
- // migrate old format to new format.
127
- add_action('admin_init', array($this, '_migrate_to_v2'), 1 );
128
- }
129
- $this->set_current_version( EPS_REDIRECT_VERSION );
130
- return EPS_REDIRECT_VERSION;
131
  }
 
 
 
132
 
133
- /**
134
  *
135
  * _migrate_to_v2
136
  *
@@ -140,27 +140,28 @@ class EPS_Redirects_Plugin {
140
  * @author epstudios
141
  *
142
  */
143
- public static function _migrate_to_v2() {
144
- $redirects = get_option( self::$option_slug );
145
-
146
- if (empty($redirects)) return false; // No redirects to migrate.
147
-
148
- $new_redirects = array();
149
-
150
- foreach ($redirects as $from => $to ) {
151
- $new_redirects[] = array(
152
- 'id' => false,
153
- 'url_to' => urldecode($to),
154
- 'url_from' => $from,
155
- 'type' => 'url',
156
- 'status' => '301'
157
- );
158
- }
159
-
160
- EPS_Redirects::_save_redirects( $new_redirects );
161
  }
162
 
163
- /**
 
 
 
164
  *
165
  * _create_tables
166
  *
@@ -170,13 +171,13 @@ class EPS_Redirects_Plugin {
170
  * @author epstudios
171
  *
172
  */
173
- public static function _create_redirect_table()
174
- {
175
- global $wpdb;
176
 
177
- $table_name = $wpdb->prefix . "redirects";
178
 
179
- $sql = "CREATE TABLE $table_name (
180
  id mediumint(9) NOT NULL AUTO_INCREMENT,
181
  url_from VARCHAR(256) DEFAULT '' NOT NULL,
182
  url_to VARCHAR(256) DEFAULT '' NOT NULL,
@@ -186,15 +187,15 @@ class EPS_Redirects_Plugin {
186
  UNIQUE KEY id (id)
187
  );";
188
 
189
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
190
- return dbDelta( $sql );
191
- }
192
 
193
 
194
 
195
 
196
 
197
- /**
198
  *
199
  * plugin_resources
200
  *
@@ -204,34 +205,31 @@ class EPS_Redirects_Plugin {
204
  * @author epstudios
205
  *
206
  */
207
- public static function plugin_resources()
208
- {
209
- global $EPS_Redirects_Plugin;
210
- if( is_admin() && isset($_GET['page']) && $_GET['page'] == $EPS_Redirects_Plugin->config('page_slug') ) {
211
- wp_enqueue_script('jquery');
212
-
213
 
214
- wp_enqueue_script('eps_redirect_script', EPS_REDIRECT_URL .'js/scripts.js');
215
- wp_enqueue_style('eps_redirect_styles', EPS_REDIRECT_URL .'css/eps_redirect.css');
216
- }
217
 
218
- global $wp_rewrite;
219
- if( !isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure) )
220
- {
221
- $EPS_Redirects_Plugin->add_admin_message('WARNING: 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>', "error" );
222
- }
223
 
224
- global $wpdb;
225
- $table_name = $wpdb->prefix . "redirects";
226
- if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
227
- {
228
- $url = $EPS_Redirects_Plugin->admin_url( array('action' => 'eps_create_tables') );
229
- $EPS_Redirects_Plugin->add_admin_message('WARNING: It looks like we need to <a href="'.$url.'" title="Permalinks">Create the Database Tables First!</a>', "error" );
230
- }
231
 
 
 
 
 
 
232
  }
 
233
 
234
- /**
235
  *
236
  * check_plugin_actions
237
  *
@@ -241,47 +239,42 @@ class EPS_Redirects_Plugin {
241
  * @author epstudios
242
  *
243
  */
244
- public function check_plugin_actions(){
245
- if( is_admin() && isset($_GET['page']) && $_GET['page'] == $this->config('page_slug') )
246
- {
247
- // Upload a CSV
248
- if( isset($_POST['eps_redirect_upload']) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
249
- self::_upload();
250
- }
251
- // Export a CSV
252
- if( isset($_POST['eps_redirect_export']) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') )
253
- {
254
- self::export_csv();
255
- }
256
-
257
- // Refresh the Transient Cache
258
- if ( isset( $_POST['eps_redirect_refresh'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') )
259
- {
260
- $post_types = get_post_types(array('public'=>true), 'objects');
261
- foreach ($post_types as $post_type )
262
- {
263
- $options = eps_dropdown_pages( array('post_type'=>$post_type->name ) );
264
- set_transient( 'post_type_cache_'.$post_type->name, $options, HOUR_IN_SECONDS );
265
- }
266
- $this->add_admin_message("SUCCCESS: Cache Refreshed.", "updated" );
267
- }
268
-
269
- // Save Redirects
270
- if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') )
271
- {
272
- self::_save_redirects( EPS_Redirects::_parse_serial_array($_POST['redirect']) );
273
- }
274
-
275
- // Create tables
276
- if( isset($_GET['action']) && $_GET['action'] == 'eps_create_tables' )
277
- {
278
- $result = self::_create_redirect_table();
279
- }
280
  }
 
 
 
 
 
 
 
 
 
 
 
 
281
  }
 
282
 
283
 
284
- /**
285
  *
286
  * export_csv
287
  *
@@ -289,35 +282,33 @@ class EPS_Redirects_Plugin {
289
  * @author epstudios
290
  *
291
  */
292
- public static function export_csv()
293
- {
294
- $entries = EPS_Redirects::get_all();
295
- $filename = sprintf("%s-redirects.csv",
296
- date('Y-m-d')
 
 
 
 
 
 
 
 
 
 
 
 
297
  );
298
- if( $entries )
299
- {
300
- header('Content-disposition: attachment; filename='.$filename);
301
- header('Content-type: text/csv');
302
-
303
- foreach( $entries as $entry )
304
- {
305
- $csv = array(
306
- $entry->status,
307
- $entry->url_from,
308
- $entry->url_to,
309
- $entry->count
310
- );
311
- echo implode(',',$csv);
312
- echo "\n";
313
- }
314
-
315
- die();
316
- }
317
 
 
318
  }
 
319
 
320
- /**
321
  *
322
  * _upload
323
  *
@@ -327,198 +318,193 @@ class EPS_Redirects_Plugin {
327
  * @author epstudios
328
  *
329
  */
330
- private function _upload() {
331
- $new_redirects = array();
332
-
333
- $counter = array(
334
- 'new' => 0,
335
- 'updated' => 0,
336
- 'skipped' => 0,
337
- 'errors' => 0,
338
- 'total' => 0
339
- );
 
340
 
341
- $mimes = array(
342
- 'text/csv',
343
- 'text/tsv',
344
- 'text/plain',
345
- 'application/csv',
346
- 'text/comma-separated-values',
347
- 'application/excel',
348
- 'application/vnd.ms-excel',
349
- 'application/vnd.msexcel',
350
- 'text/anytext',
351
- 'application/octet-stream',
352
- 'application/txt'
353
- );
354
- ini_set('auto_detect_line_endings',TRUE);
 
 
 
 
 
 
 
 
355
 
356
- if( !in_array($_FILES['eps_redirect_upload_file']['type'], $mimes) ) {
357
- $this->add_admin_message(sprintf("WARNING: Not a valid CSV file - the Mime Type '%s' is wrong! No new redirects have been added.",
358
- $_FILES['eps_redirect_upload_file']['type']
359
- ), "error" );
360
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  }
362
 
363
- // open the file.
364
- if (($handle = fopen($_FILES['eps_redirect_upload_file']['tmp_name'], "r")) !== FALSE)
365
- {
366
- $counter['total'] = 1;
367
- while (($redirect = fgetcsv($handle, 0, ",")) !== FALSE)
368
- {
369
- $redirect = array_filter($redirect);
370
-
371
- if( empty( $redirect ) ) continue;
372
-
373
- $args = count($redirect);
374
-
375
- if( $args > 4 || $args < 2 )
376
- {
377
- // Bad line. Too many/few arguments.
378
- $this->add_admin_message(
379
- sprintf("WARNING: Encountered a badly formed entry in your CSV file on line %d (we skipped it).",
380
- $counter['total']
381
- ),
382
- "error" );
383
- $counter['errors'] ++;
384
- continue;
385
- }
386
-
387
- $status = (isset($redirect[0])) ? $redirect[0] : false;
388
- $url_from = (isset($redirect[1])) ? $redirect[1] : false;
389
- $url_to = (isset($redirect[2])) ? $redirect[2] : false;
390
- $count = (isset($redirect[3])) ? $redirect[3] : false;
391
-
392
- switch( strtolower( $status ) ) {
393
- case '404': $status = 404; break;
394
- case '302': $status = 302; break;
395
- case 'off':
396
- case 'no':
397
- case 'inactive': $status = 'inactive'; break;
398
- default: $status = 301; break;
399
- }
400
-
401
- // If the user supplied a post_id, is it valid? If so, use it!
402
- if( $url_to && $post_id = url_to_postid( $url_to ) )
403
- {
404
- $url_to = $post_id;
405
- }
406
-
407
- // new redirect!
408
- $new_redirect = array(
409
- 'id' => false, // new
410
- 'url_from' => $url_from,
411
- 'url_to' => $url_to,
412
- 'type' => ( is_numeric( $url_to ) ) ? 'post' : 'url',
413
- 'status' => $status,
414
- 'count' => $count
415
- );
416
-
417
- array_push($new_redirects, $new_redirect);
418
- $counter['total'] ++;
419
- }
420
- fclose($handle); // close file.
421
  }
422
 
 
 
 
 
423
 
424
- if( $new_redirects )
425
- {
426
- $save_redirects = array();
427
- foreach( $new_redirects as $redirect )
428
- {
429
- // Decide how to handle duplicates:
430
- switch( strtolower( $_POST['eps_redirect_upload_method'] ) )
431
- {
432
- case 'skip':
433
- if( ! EPS_Redirects::redirect_exists( $redirect ) )
434
- {
435
- $save_redirects[] = $redirect;
436
- $counter['new'] ++;
437
- }
438
- else
439
- {
440
- $counter['skipped'] ++;
441
- }
442
- break;
443
- case 'update':
444
- if( $entry = EPS_Redirects::redirect_exists( $redirect ) )
445
- {
446
- $redirect['id'] = $entry->id;
447
- $counter['updated'] ++;
448
- $save_redirects[] = $redirect;
449
- }
450
- else
451
- {
452
- $save_redirects[] = $redirect;
453
- $counter['new'] ++;
454
- }
455
- break;
456
- default:
457
- $save_redirects[] = $redirect;
458
- $counter['new'] ++;
459
- break;
460
- }
461
- }
462
 
463
- if( ! empty( $save_redirects ) )
464
- {
465
- EPS_Redirects::_save_redirects( $save_redirects );
466
- }
 
467
 
468
- $this->add_admin_message(sprintf(
469
- "SUCCCESS: %d New Redirects, %d Updated, %d Skipped, %d Errors. (Attempted to import %d redirects).",
470
- $counter['new'],
471
- $counter['updated'],
472
- $counter['skipped'],
473
- $counter['errors'],
474
- $counter['total']
475
- ), "updated" );
476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
  }
478
- else
479
- {
480
- $this->add_admin_message("WARNING: Something's up. No new redirects were added, please review your CSV file.", "error" );
481
- }
482
- ini_set('auto_detect_line_endings',FALSE);
 
 
 
 
 
 
 
 
 
 
 
483
  }
 
 
484
 
485
 
486
 
487
- /**
488
  *
489
  * Template Hooks
490
  *
491
  * @author epstudios
492
  *
493
  */
494
- public static function admin_panel_cache()
495
- {
496
- include ( EPS_REDIRECT_PATH . 'templates/admin-panel-cache.php' );
497
- }
498
- public static function admin_panel_donate()
499
- {
500
- include ( EPS_REDIRECT_PATH . 'templates/admin-panel-donate.php' );
501
- }
502
-
503
- public static function admin_tab_redirects( $options )
504
- {
505
- include ( EPS_REDIRECT_PATH . 'templates/admin-tab-redirects.php' );
506
- }
507
- public static function admin_tab_404s( $options )
508
- {
509
- include ( EPS_REDIRECT_PATH . 'templates/admin-tab-404s.php' );
510
- }
511
- public static function admin_tab_import_export( $options )
512
- {
513
- include ( EPS_REDIRECT_PATH . 'templates/admin-tab-import-export.php' );
514
- }
515
- public static function admin_tab_error( $options )
516
- {
517
- include ( EPS_REDIRECT_PATH . 'templates/admin-tab-error.php' );
518
- }
519
-
520
-
521
- /**
522
  *
523
  * CHECK VERSION
524
  *
@@ -529,12 +515,12 @@ class EPS_Redirects_Plugin {
529
  *
530
  */
531
 
532
- public function config($name)
533
- {
534
- return ( isset($this->config[ $name ]) ) ? $this->config[ $name ] : false;
535
- }
536
 
537
- /**
538
  *
539
  *
540
  * Activation and Deactivation Handlers.
@@ -542,26 +528,27 @@ class EPS_Redirects_Plugin {
542
  * @return nothing
543
  * @author epstudios
544
  */
545
- public function activation_error() {
546
- file_put_contents($this->config('path'). '/error_activation.html', ob_get_contents());
547
- }
 
548
 
549
 
550
- public static function is_current_version()
551
- {
552
- return version_compare( self::current_version(), EPS_REDIRECT_VERSION, '=') ? true : false; // TODO decouple
553
- }
554
- public static function current_version()
555
- {
556
- return get_option( 'eps_redirects_version' ); // TODO decouple
557
- }
558
- public static function set_current_version( $version )
559
- {
560
- update_option( 'eps_redirects_version', $version );
561
- }
562
 
563
 
564
- /**
565
  *
566
  * Notices
567
  *
@@ -570,37 +557,35 @@ class EPS_Redirects_Plugin {
570
  * @author epstudios
571
  *
572
  */
573
- protected function add_admin_message( $message, $code )
574
- {
575
- $this->messages[] = array( $code => $message );
576
- add_action( 'admin_notices', array($this, 'display_admin_messages') );
577
- }
578
- public static function display_admin_messages()
579
- {
580
- global $EPS_Redirects_Plugin;
581
- if( is_array( $EPS_Redirects_Plugin->messages ) && ! empty( $EPS_Redirects_Plugin->messages ) )
582
- {
583
- foreach( $EPS_Redirects_Plugin->messages as $entry )
584
- {
585
- $code = key($entry);
586
- $message = reset($entry);
587
-
588
- if( ! in_array($code, array('error','updated') ) )
589
- {
590
- $code = 'updated';
591
- }
592
- $EPS_Redirects_Plugin->admin_notice( $message, $code);
593
- }
594
  }
 
 
595
  }
596
- public function admin_notice( $string, $type = "updated" ) {
597
- printf('<div class="%s"><p>%s</p></div>',
598
- $type,
599
- $string
600
- );
601
- }
 
 
 
602
  }
603
 
604
  // Init the plugin.
605
  $EPS_Redirects_Plugin = new EPS_Redirects_Plugin();
606
- ?>
9
 
10
 
11
 
12
+ class EPS_Redirects_Plugin
13
+ {
14
+
15
+ protected $config = array(
16
+ 'version' => EPS_REDIRECT_VERSION,
17
+ 'option_slug' => 'eps_redirects',
18
+ 'page_slug' => 'eps_redirects',
19
+ 'page_title' => '301 Redirects',
20
+ 'menu_location' => 'options',
21
+ 'page_permission' => 'manage_options',
22
+ 'directory' => 'eps-301-redirects'
23
+ );
24
+
25
+ protected $dependancies = array();
26
+
27
+ protected $tables = array();
28
+
29
+ public $name = '301 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
+ protected $messages = array();
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);
61
+ add_action('404s_admin_tab', array($this, 'admin_tab_404s'), 10, 1);
62
+ add_action('error_admin_tab', array($this, 'admin_tab_error'), 10, 1);
63
+ add_action('import-export_admin_tab', array($this, 'admin_tab_import_export'), 10, 1);
64
+ add_action('eps_redirects_panels_left', array($this, 'admin_panel_cache'));
65
+ add_action('eps_redirects_panels_right', array($this, 'admin_panel_donate'));
66
+
67
+ // Actions
68
+ add_action('admin_init', array($this, 'check_plugin_actions'));
69
+ }
70
+
71
+ public function resolve_dependencies()
72
+ {
73
+ include_once(ABSPATH . 'wp-admin/includes/plugin.php');
74
+ foreach ($this->dependencies as $name => $path_to_plugin) {
75
+ if (!is_plugin_active($path_to_plugin)) {
76
+ echo $name . ' IS NOT INSTALLED!';
77
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
+ }
 
 
 
 
 
 
80
 
81
 
82
+ private function resource_path($path, $resource)
83
+ {
84
+ return strtolower(
85
+ $this->config['url']
86
+ . $path . '/'
87
+ . $resource
88
+ );
89
+ }
90
+
91
+ private function resource_name($resource)
92
+ {
93
+ return strtolower($this->name . '_' . key($resource));
94
+ }
95
+
96
+ public static function _activation()
97
+ {
98
+ self::_create_redirect_table(); // Maybe create the tables
99
+ if (!self::is_current_version()) self::update_self();
100
+ }
101
+ public static function _deactivation()
102
+ { }
103
+
104
+
105
+ public function admin_url($vars = array())
106
+ {
107
+ $vars = array('page' => $this->config['page_slug']) + $vars;
108
+ $url = 'options-general.php?' . http_build_query($vars);
109
+ return admin_url($url);
110
+ }
111
+ /**
112
  *
113
  * update_self
114
  *
118
  * @author epstudios
119
  *
120
  */
121
+ public function update_self()
122
+ {
123
+ $version = get_option('eps_redirects_version');
124
 
125
+ if (version_compare($version, '2.0.0', '<')) {
126
+ // migrate old format to new format.
127
+ add_action('admin_init', array($this, '_migrate_to_v2'), 1);
 
 
 
128
  }
129
+ $this->set_current_version(EPS_REDIRECT_VERSION);
130
+ return EPS_REDIRECT_VERSION;
131
+ }
132
 
133
+ /**
134
  *
135
  * _migrate_to_v2
136
  *
140
  * @author epstudios
141
  *
142
  */
143
+ public static function _migrate_to_v2()
144
+ {
145
+ $redirects = get_option(self::$option_slug);
146
+
147
+ if (empty($redirects)) return false; // No redirects to migrate.
148
+
149
+ $new_redirects = array();
150
+
151
+ foreach ($redirects as $from => $to) {
152
+ $new_redirects[] = array(
153
+ 'id' => false,
154
+ 'url_to' => urldecode($to),
155
+ 'url_from' => $from,
156
+ 'type' => 'url',
157
+ 'status' => '301'
158
+ );
 
 
159
  }
160
 
161
+ EPS_Redirects::_save_redirects($new_redirects);
162
+ }
163
+
164
+ /**
165
  *
166
  * _create_tables
167
  *
171
  * @author epstudios
172
  *
173
  */
174
+ public static function _create_redirect_table()
175
+ {
176
+ global $wpdb;
177
 
178
+ $table_name = $wpdb->prefix . "redirects";
179
 
180
+ $sql = "CREATE TABLE $table_name (
181
  id mediumint(9) NOT NULL AUTO_INCREMENT,
182
  url_from VARCHAR(256) DEFAULT '' NOT NULL,
183
  url_to VARCHAR(256) DEFAULT '' NOT NULL,
187
  UNIQUE KEY id (id)
188
  );";
189
 
190
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
191
+ return dbDelta($sql);
192
+ }
193
 
194
 
195
 
196
 
197
 
198
+ /**
199
  *
200
  * plugin_resources
201
  *
205
  * @author epstudios
206
  *
207
  */
208
+ public static function plugin_resources()
209
+ {
210
+ global $EPS_Redirects_Plugin;
211
+ if (is_admin() && isset($_GET['page']) && $_GET['page'] == $EPS_Redirects_Plugin->config('page_slug')) {
212
+ wp_enqueue_script('jquery');
 
213
 
 
 
 
214
 
215
+ wp_enqueue_script('eps_redirect_script', EPS_REDIRECT_URL . 'js/scripts.js');
216
+ wp_enqueue_style('eps_redirect_styles', EPS_REDIRECT_URL . 'css/eps_redirect.css');
217
+ }
 
 
218
 
219
+ global $wp_rewrite;
220
+ if (!isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure)) {
221
+ $EPS_Redirects_Plugin->add_admin_message('WARNING: 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>', "error");
222
+ }
 
 
 
223
 
224
+ global $wpdb;
225
+ $table_name = $wpdb->prefix . "redirects";
226
+ if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
227
+ $url = $EPS_Redirects_Plugin->admin_url(array('action' => 'eps_create_tables'));
228
+ $EPS_Redirects_Plugin->add_admin_message('WARNING: It looks like we need to <a href="' . $url . '" title="Permalinks">Create the Database Tables First!</a>', "error");
229
  }
230
+ }
231
 
232
+ /**
233
  *
234
  * check_plugin_actions
235
  *
239
  * @author epstudios
240
  *
241
  */
242
+ public function check_plugin_actions()
243
+ {
244
+ if (is_admin() && isset($_GET['page']) && $_GET['page'] == $this->config('page_slug')) {
245
+ // Upload a CSV
246
+ if (isset($_POST['eps_redirect_upload']) && wp_verify_nonce($_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce')) {
247
+ self::_upload();
248
+ }
249
+ // Export a CSV
250
+ if (isset($_POST['eps_redirect_export']) && wp_verify_nonce($_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce')) {
251
+ self::export_csv();
252
+ }
253
+
254
+ // Refresh the Transient Cache
255
+ if (isset($_POST['eps_redirect_refresh']) && wp_verify_nonce($_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce')) {
256
+ $post_types = get_post_types(array('public' => true), 'objects');
257
+ foreach ($post_types as $post_type) {
258
+ $options = eps_dropdown_pages(array('post_type' => $post_type->name));
259
+ set_transient('post_type_cache_' . $post_type->name, $options, HOUR_IN_SECONDS);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  }
261
+ $this->add_admin_message("SUCCCESS: Cache Refreshed.", "updated");
262
+ }
263
+
264
+ // Save Redirects
265
+ if (isset($_POST['eps_redirect_submit']) && wp_verify_nonce($_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce')) {
266
+ self::_save_redirects(EPS_Redirects::_parse_serial_array($_POST['redirect']));
267
+ }
268
+
269
+ // Create tables
270
+ if (isset($_GET['action']) && $_GET['action'] == 'eps_create_tables') {
271
+ $result = self::_create_redirect_table();
272
+ }
273
  }
274
+ }
275
 
276
 
277
+ /**
278
  *
279
  * export_csv
280
  *
282
  * @author epstudios
283
  *
284
  */
285
+ public static function export_csv()
286
+ {
287
+ $entries = EPS_Redirects::get_all();
288
+ $filename = sprintf(
289
+ "%s-redirects.csv",
290
+ date('Y-m-d')
291
+ );
292
+ if ($entries) {
293
+ header('Content-disposition: attachment; filename=' . $filename);
294
+ header('Content-type: text/csv');
295
+
296
+ foreach ($entries as $entry) {
297
+ $csv = array(
298
+ $entry->status,
299
+ $entry->url_from,
300
+ $entry->url_to,
301
+ $entry->count
302
  );
303
+ echo implode(',', $csv);
304
+ echo "\n";
305
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
 
307
+ die();
308
  }
309
+ }
310
 
311
+ /**
312
  *
313
  * _upload
314
  *
318
  * @author epstudios
319
  *
320
  */
321
+ private function _upload()
322
+ {
323
+ $new_redirects = array();
324
+
325
+ $counter = array(
326
+ 'new' => 0,
327
+ 'updated' => 0,
328
+ 'skipped' => 0,
329
+ 'errors' => 0,
330
+ 'total' => 0
331
+ );
332
 
333
+ $mimes = array(
334
+ 'text/csv',
335
+ 'text/tsv',
336
+ 'text/plain',
337
+ 'application/csv',
338
+ 'text/comma-separated-values',
339
+ 'application/excel',
340
+ 'application/vnd.ms-excel',
341
+ 'application/vnd.msexcel',
342
+ 'text/anytext',
343
+ 'application/octet-stream',
344
+ 'application/txt'
345
+ );
346
+ ini_set('auto_detect_line_endings', true);
347
+
348
+ if (!in_array($_FILES['eps_redirect_upload_file']['type'], $mimes)) {
349
+ $this->add_admin_message(sprintf(
350
+ "WARNING: Not a valid CSV file - the Mime Type '%s' is wrong! No new redirects have been added.",
351
+ $_FILES['eps_redirect_upload_file']['type']
352
+ ), "error");
353
+ return false;
354
+ }
355
 
356
+ // open the file.
357
+ if (($handle = fopen($_FILES['eps_redirect_upload_file']['tmp_name'], "r")) !== false) {
358
+ $counter['total'] = 1;
359
+ while (($redirect = fgetcsv($handle, 0, ",")) !== false) {
360
+ $redirect = array_filter($redirect);
361
+
362
+ if (empty($redirect)) continue;
363
+
364
+ $args = count($redirect);
365
+
366
+ if ($args > 4 || $args < 2) {
367
+ // Bad line. Too many/few arguments.
368
+ $this->add_admin_message(
369
+ sprintf(
370
+ "WARNING: Encountered a badly formed entry in your CSV file on line %d (we skipped it).",
371
+ $counter['total']
372
+ ),
373
+ "error"
374
+ );
375
+ $counter['errors']++;
376
+ continue;
377
  }
378
 
379
+ $status = (isset($redirect[0])) ? $redirect[0] : false;
380
+ $url_from = (isset($redirect[1])) ? $redirect[1] : false;
381
+ $url_to = (isset($redirect[2])) ? $redirect[2] : false;
382
+ $count = (isset($redirect[3])) ? $redirect[3] : false;
383
+
384
+ switch (strtolower($status)) {
385
+ case '404':
386
+ $status = 404;
387
+ break;
388
+ case '302':
389
+ $status = 302;
390
+ break;
391
+ case 'off':
392
+ case 'no':
393
+ case 'inactive':
394
+ $status = 'inactive';
395
+ break;
396
+ default:
397
+ $status = 301;
398
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  }
400
 
401
+ // If the user supplied a post_id, is it valid? If so, use it!
402
+ if ($url_to && $post_id = url_to_postid($url_to)) {
403
+ $url_to = $post_id;
404
+ }
405
 
406
+ // new redirect!
407
+ $new_redirect = array(
408
+ 'id' => false, // new
409
+ 'url_from' => $url_from,
410
+ 'url_to' => $url_to,
411
+ 'type' => (is_numeric($url_to)) ? 'post' : 'url',
412
+ 'status' => $status,
413
+ 'count' => $count
414
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
 
416
+ array_push($new_redirects, $new_redirect);
417
+ $counter['total']++;
418
+ }
419
+ fclose($handle); // close file.
420
+ }
421
 
 
 
 
 
 
 
 
 
422
 
423
+ if ($new_redirects) {
424
+ $save_redirects = array();
425
+ foreach ($new_redirects as $redirect) {
426
+ // Decide how to handle duplicates:
427
+ switch (strtolower($_POST['eps_redirect_upload_method'])) {
428
+ case 'skip':
429
+ if (!EPS_Redirects::redirect_exists($redirect)) {
430
+ $save_redirects[] = $redirect;
431
+ $counter['new']++;
432
+ } else {
433
+ $counter['skipped']++;
434
+ }
435
+ break;
436
+ case 'update':
437
+ if ($entry = EPS_Redirects::redirect_exists($redirect)) {
438
+ $redirect['id'] = $entry->id;
439
+ $counter['updated']++;
440
+ $save_redirects[] = $redirect;
441
+ } else {
442
+ $save_redirects[] = $redirect;
443
+ $counter['new']++;
444
+ }
445
+ break;
446
+ default:
447
+ $save_redirects[] = $redirect;
448
+ $counter['new']++;
449
+ break;
450
  }
451
+ }
452
+
453
+ if (!empty($save_redirects)) {
454
+ EPS_Redirects::_save_redirects($save_redirects);
455
+ }
456
+
457
+ $this->add_admin_message(sprintf(
458
+ "SUCCCESS: %d New Redirects, %d Updated, %d Skipped, %d Errors. (Attempted to import %d redirects).",
459
+ $counter['new'],
460
+ $counter['updated'],
461
+ $counter['skipped'],
462
+ $counter['errors'],
463
+ $counter['total']
464
+ ), "updated");
465
+ } else {
466
+ $this->add_admin_message("WARNING: Something's up. No new redirects were added, please review your CSV file.", "error");
467
  }
468
+ ini_set('auto_detect_line_endings', false);
469
+ }
470
 
471
 
472
 
473
+ /**
474
  *
475
  * Template Hooks
476
  *
477
  * @author epstudios
478
  *
479
  */
480
+ public static function admin_panel_cache()
481
+ {
482
+ include(EPS_REDIRECT_PATH . 'templates/admin-panel-cache.php');
483
+ }
484
+ public static function admin_panel_donate()
485
+ {
486
+ include(EPS_REDIRECT_PATH . 'templates/admin-panel-donate.php');
487
+ }
488
+
489
+ public static function admin_tab_redirects($options)
490
+ {
491
+ include(EPS_REDIRECT_PATH . 'templates/admin-tab-redirects.php');
492
+ }
493
+ public static function admin_tab_404s($options)
494
+ {
495
+ include(EPS_REDIRECT_PATH . 'templates/admin-tab-404s.php');
496
+ }
497
+ public static function admin_tab_import_export($options)
498
+ {
499
+ include(EPS_REDIRECT_PATH . 'templates/admin-tab-import-export.php');
500
+ }
501
+ public static function admin_tab_error($options)
502
+ {
503
+ include(EPS_REDIRECT_PATH . 'templates/admin-tab-error.php');
504
+ }
505
+
506
+
507
+ /**
508
  *
509
  * CHECK VERSION
510
  *
515
  *
516
  */
517
 
518
+ public function config($name)
519
+ {
520
+ return (isset($this->config[$name])) ? $this->config[$name] : false;
521
+ }
522
 
523
+ /**
524
  *
525
  *
526
  * Activation and Deactivation Handlers.
528
  * @return nothing
529
  * @author epstudios
530
  */
531
+ public function activation_error()
532
+ {
533
+ file_put_contents($this->config('path') . '/error_activation.html', ob_get_contents());
534
+ }
535
 
536
 
537
+ public static function is_current_version()
538
+ {
539
+ return version_compare(self::current_version(), EPS_REDIRECT_VERSION, '=') ? true : false; // TODO decouple
540
+ }
541
+ public static function current_version()
542
+ {
543
+ return get_option('eps_redirects_version'); // TODO decouple
544
+ }
545
+ public static function set_current_version($version)
546
+ {
547
+ update_option('eps_redirects_version', $version);
548
+ }
549
 
550
 
551
+ /**
552
  *
553
  * Notices
554
  *
557
  * @author epstudios
558
  *
559
  */
560
+ protected function add_admin_message($message, $code)
561
+ {
562
+ $this->messages[] = array($code => $message);
563
+ add_action('admin_notices', array($this, 'display_admin_messages'));
564
+ }
565
+ public static function display_admin_messages()
566
+ {
567
+ global $EPS_Redirects_Plugin;
568
+ if (is_array($EPS_Redirects_Plugin->messages) && !empty($EPS_Redirects_Plugin->messages)) {
569
+ foreach ($EPS_Redirects_Plugin->messages as $entry) {
570
+ $code = key($entry);
571
+ $message = reset($entry);
572
+
573
+ if (!in_array($code, array('error', 'updated'))) {
574
+ $code = 'updated';
 
 
 
 
 
 
575
  }
576
+ $EPS_Redirects_Plugin->admin_notice($message, $code);
577
+ }
578
  }
579
+ }
580
+ public function admin_notice($string, $type = "updated")
581
+ {
582
+ printf(
583
+ '<div class="%s"><p>%s</p></div>',
584
+ $type,
585
+ $string
586
+ );
587
+ }
588
  }
589
 
590
  // Init the plugin.
591
  $EPS_Redirects_Plugin = new EPS_Redirects_Plugin();
 
readme.txt CHANGED
@@ -1,121 +1,68 @@
1
- === Plugin Name ===
2
-
3
- Contributors: shawneggplantstudiosca
4
-
5
- Donate link: none
6
-
7
- Tags: 301 redirects, redirects
8
-
9
- Requires at least: 3.0.1
10
-
11
- Tested up to: 4.2.1
12
-
13
- Stable tag: 2.3.0
14
-
15
  License: GPLv2 or later
16
-
17
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
18
 
19
- Easily manage and create 301 redirects for your Wordpress website. A robust interface allows you create and validate redirects.
20
 
21
  == Description ==
22
 
23
- **EPS 301 Redirects** helps you manage and create 301 redirects for your Wordpress website to improve your SEO and guest experience. With a user-friendly interface, EPS 301 Redirects is easy to install and configure. This plugin is installed on over 20,000 Wordpress Websites, and the number grows higher every day. This plugin is perfect for new site designs, repairing links after re-organizing your existing Wordpress content, or when your site has content that expires and you wish to avoid sending visitors to 404 pages.
24
 
 
25
 
26
  **Features**
27
 
28
- 1. Choose from Pages, Posts, Custom Post types, Archives, and Term Archives from dropdown menus.
29
- 1. Or, set a custom destination URL!
30
- 1. Retain query strings across redirects
31
- 1. Super-fast redirection
32
- Improved Import/Export feature for bulk additions.
33
- 1. A 404 logger (pro version), that will easily convert into new redirects.
34
-
35
- **The Pro version of EPS 301 Redirects includes a new 404 logging feature:**
36
-
37
- The Pro Version of EPS 301 Redirects will add a new 404 tracking feature. Every 404 error will be logged, and you will have the power and flexibility to redirect them wherever you want them to go.
38
 
39
- 1. See which Request URLs are causing 404 errors on your site.
40
- 1. Discover which 404 errors are receiving the most traffic.
41
- 1. Improve SEO by lowering your total number of 404 errors.
42
- 1. Easily fix the 404 errors by turning them into redirects.
43
 
44
-
45
-
46
- **What is a 301 Redirect?**
47
- A redirect is a simple way to re-route traffic coming to a *Requested URL* to different *Destination URL*.
48
 
49
  A 301 redirect indicates that the page requested has been permanently moved to the *Destination URL*, and helps pass on the *Requested URLs* traffic in a search engine friendly manner. Creating a 301 redirect tells search engines that the *Requested URL* has moved permanently, and that the content can now be found on the *Destination URL*. An important feature is that search engines will pass along any clout the *Requested URL* used to have to the *Destination URL*.
50
 
51
 
52
- **When Should I use EPS 301 Redirects?**
53
- 1. Replacing an old site design with a new site design
54
- 1. Overhauling or re-organizing your existing Wordpress content
55
- 1. You have content that expires (or is otherwise no longer available) and you wish to redirect users elsewhere.
56
-
57
 
 
 
 
58
 
59
- Created by Shawn Wernig [Eggplant Studios](http://www.eggplantstudios.ca/ "Eggplant Studios")
60
 
61
- *This release is compatible with all Wordpress versions since 3.0.1 (Tested. Plugin may not work as intended for older versions of Wordpress).*
62
-
63
- *This plugin is English only; though it is somewhat language independent.*
64
 
65
  == Installation ==
66
 
67
-
68
-
69
  1. Upload the `eps-301-redirects` folder to the `/wp-content/plugins/` directory
70
- 1. Activate the plugin through the 'Plugins' menu in WordPress
71
- 1. Begin adding redirects in the Settings -> EPS 301 Redirects menu item.
72
-
73
-
74
-
75
- == Frequently Asked Questions ==
76
-
77
- =What is a 301 Redirect?=
78
- A redirect is a simple way to re-route traffic coming to a Requested URL to different Destination URL.
79
-
80
- A 301 redirect indicates that the page requested has been permanently moved to the Destination URL, and helps pass on the Requested URLs traffic in a search engine friendly manner. Creating a 301 redirect tells search engines that the Requested URL has moved permanently, and that the content can now be found on the Destination URL. An important feature is that search engines will pass along any clout the Requested URL used to have to the Destination URL.
81
-
82
- =I'm getting an error about the default permalink structure?=
83
-
84
- EPS 301 Redirects requires that you use anything but the default permalink structure.
85
-
86
- =My redirects aren't working=
87
-
88
- This could be caused by many things, but please ensure that you are supplying valid URLs. Most common are extra spaces, extra slashes, spelling mistakes and invalid characters. If you're sure they're right, chances are your browser has cached the 301 redirect (in an attempt to make the redirection faster for you), but sometimes it doesn't refresh as fast as we would like. Clear your browser cache, or wait a few minutes to fix this problem.
89
- My redirects aren't working - the old .html page still shows
90
- For this plugin to work, the page must be within the Wordpress environment. If you are redirecting older .html or .php files, you must first delete them. The plugin can’t redirect if the file still exists, sorry! You should look into .htaccess redirects if you want to keep these files on your server.
91
-
92
- =My redirects aren't getting the 301 status code=
93
-
94
- Your Request or Redirect URLS may be incorrect; please ensure that you are supplying valid URLs. Check slashes. Try Viewing the page by clicking the Request URL - does it load correctly?
95
-
96
- =How do I delete a redirect?=
97
-
98
- Click the small X beside the redirect you wish to remove.
99
-
100
- =How do I add wildcards. or folder redirects?=
101
-
102
- Unfortunately this is not supported. You should look into .htaccess redirects for these advanced features.
103
-
104
-
105
- =What about query strings?=
106
-
107
- By default, any URL with a query string is considered unique, and will redirect to a unique page (if you so wish). The query string will be added to the Destination URL, which allows you to keep your tracking codes, affiliate codes, and other important data!
108
 
109
 
110
 
111
  == Screenshots ==
112
 
113
- 1. The administrative area, Wordpress 3.5.1
114
- 2. Examples of some of the dropdown options.
115
- 3. The redirect testing feature.
116
 
117
  == Changelog ==
118
 
 
 
 
 
 
 
 
119
  = 2.3.0 =
120
  Added sorting. Fixed a bug when upgrading from V1 to V2, and the infamous "Invalid Destination" url.
121
 
@@ -140,7 +87,6 @@ Minor bug fixes.
140
  = 2.1.1 =
141
  Fixed an issue where users with a lot of redirects were being limited, this fix also changed up the admin area. Redirects are now editable via AJAX, and the ‘add new’ form was moved to the top.
142
 
143
-
144
  = 2.0.1 =
145
  Fixed an issue where the Automatic Update would not call the import process for pre 2.0 versions.
146
 
@@ -153,20 +99,17 @@ Overhauled the entire plugin. Redirects are stored in their own table. Gracefull
153
  = 1.3.5 =
154
  * Fixed a bug with spaces in the url. Added ease of use visual aids.
155
 
156
-
157
  = 1.3.4 =
158
  * Fixed nonce validation problem which would prevent saving of new redirects. Special Thanks to Bruce Zlotowitz for all his testing!
159
 
160
  = 1.3.3 =
161
  * Fixed major problem when switching from 1.2 to 1.3+
162
 
163
-
164
  = 1.3.1 =
165
  * Added hierarchy to heirarchical post type selects.
166
 
167
-
168
  = 1.3 =
169
- * Fixed a bug where duplicate urls were being overwritten, fixed a bug where you could not completely remove all redirects.
170
 
171
  = 1.2 =
172
  * Fixed some little bugs.
@@ -177,60 +120,36 @@ Overhauled the entire plugin. Redirects are stored in their own table. Gracefull
177
  = 1.0 =
178
  * Release.
179
 
180
- == Upgrade Notice ==
181
-
182
- = 2.3.0 =
183
- Added sorting. Fixed a bug when upgrading from V1 to V2, and the infamous "Invalid Destination" url.
184
-
185
-
186
- = 2.2.7 =
187
- That silly bug with the database tables not being created has been squashed. Improved query performance.
188
-
189
- = 2.2.6 =
190
- Added support for custom plugin directories.
191
-
192
- = 2.2.4 =
193
- Support for older versions of PHP.
194
 
195
- = 2.2.0 =
196
- Minor bug fixes. Greatly improved import feature, added Export feature plus many other updates. A Pro Version is now available with 404 Management!
197
 
198
- = 2.1.2 =
199
- Minor bug fixes.
200
 
201
- = 2.1.1 =
202
- Fixed an issue where users with a lot of redirects were being limited, this fix also changed up the admin area. Redirects are now editable via AJAX, and the ‘add new’ form was moved to the top.
203
 
 
204
 
205
- = 2.0.1 =
206
- Fixed an issue where the Automatic Update would not call the import process for pre 2.0 versions.
207
 
208
- = 2.0.0 =
209
- Overhauled the entire plugin. Redirects are stored in their own table. Gracefully migrates older versions.
 
210
 
211
- = 1.4.0 =
212
- * Performance updates, added a new 'Settings' page.
213
 
214
- = 1.3.5 =
215
- Fixed a bug with spaces in urls. Also added a test for both the request and destination urls to verify that they're working as intended.
216
 
217
- = 1.3.4 =
218
- Fixed a bug when saving new redirects.
219
 
220
- = 1.3.3 =
221
- Compatibility update for users upgrading from 1.2 to 1.3+ - Update ASAP.
222
 
223
- = 1.3.1 =
224
- Functionality update, Cosmetic.
225
 
226
- = 1.3 =
227
- Bug fixes; Update ASAP.
228
 
229
- = 1.2 =
230
- Cosmetic updates.
231
 
232
- = 1.1 =
233
- Cosmetic updates.
234
 
235
- = 1.0 =
236
- Released May, 2013.
1
+ === 301 Redirects ===
2
+ Contributors: WebFactory, wpreset, googlemapswidget, securityninja, underconstructionpage
3
+ Tags: 301 redirects, redirects, redirect, 301, 404, seo, redirection, 302
4
+ Requires at least: 4.0
5
+ Tested up to: 5.1
6
+ Stable tag: 2.3.5
7
+ Requires PHP: 5.2
 
 
 
 
 
 
 
8
  License: GPLv2 or later
 
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Easily manage and create 301 & 302 redirects. Simple to use and validate redirects. Includes redirect stats.
12
 
13
  == Description ==
14
 
15
+ **301 Redirects** helps you manage and create 301 & 302 redirects for your WordPress site to **improve SEO and visitor experience**. With a user-friendly interface, 301 Redirects is easy to install and configure. Perfect for new sites or repairing links after re-organizing your existing WordPress content, or when your site has content that expires and you wish to avoid sending visitors to a 404 page.
16
 
17
+ 301 Redirects GUI is located in WP Admin Dashboard - Settings - 301 Redirects
18
 
19
  **Features**
20
 
21
+ * Choose from Pages, Posts, Custom Post types, Archives, and Term Archives from dropdown menu
22
+ * Or, set a custom destination URL!
23
+ * Retain query strings across redirects
24
+ * Super-fast redirection
25
+ * Import/Export feature for bulk redirects management
26
+ * Simple redirect stats so you know how much a redirection is used
 
 
 
 
27
 
 
 
 
 
28
 
29
+ **What is a 301 Redirect?**
30
+ A redirect is a simple way to re-route traffic coming to a *Requested URL* to different *Destination URL*.
 
 
31
 
32
  A 301 redirect indicates that the page requested has been permanently moved to the *Destination URL*, and helps pass on the *Requested URLs* traffic in a search engine friendly manner. Creating a 301 redirect tells search engines that the *Requested URL* has moved permanently, and that the content can now be found on the *Destination URL*. An important feature is that search engines will pass along any clout the *Requested URL* used to have to the *Destination URL*.
33
 
34
 
35
+ **When Should I use 301 Redirects?**
 
 
 
 
36
 
37
+ * Replacing an old site design with a new site design
38
+ * Overhauling or re-organizing your existing WordPress content
39
+ * You have content that expires (or is otherwise no longer available) and you wish to redirect users elsewhere
40
 
 
41
 
 
 
 
42
 
43
  == Installation ==
44
 
 
 
45
  1. Upload the `eps-301-redirects` folder to the `/wp-content/plugins/` directory
46
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
47
+ 3. Begin adding redirects in the Settings -> 301 Redirects menu item
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
 
50
 
51
  == Screenshots ==
52
 
53
+ 1. 301 Redirects admin area
54
+ 2. 301 Redirects import/export options
55
+
56
 
57
  == Changelog ==
58
 
59
+ = 2.3.5 =
60
+ * 2019/03/11
61
+ * WebFactory took over development
62
+ * 50,000 installations; 151,500 downloads
63
+ * bug fixes
64
+ * compatibility fixes for new versions of PHP and WP
65
+
66
  = 2.3.0 =
67
  Added sorting. Fixed a bug when upgrading from V1 to V2, and the infamous "Invalid Destination" url.
68
 
87
  = 2.1.1 =
88
  Fixed an issue where users with a lot of redirects were being limited, this fix also changed up the admin area. Redirects are now editable via AJAX, and the ‘add new’ form was moved to the top.
89
 
 
90
  = 2.0.1 =
91
  Fixed an issue where the Automatic Update would not call the import process for pre 2.0 versions.
92
 
99
  = 1.3.5 =
100
  * Fixed a bug with spaces in the url. Added ease of use visual aids.
101
 
 
102
  = 1.3.4 =
103
  * Fixed nonce validation problem which would prevent saving of new redirects. Special Thanks to Bruce Zlotowitz for all his testing!
104
 
105
  = 1.3.3 =
106
  * Fixed major problem when switching from 1.2 to 1.3+
107
 
 
108
  = 1.3.1 =
109
  * Added hierarchy to heirarchical post type selects.
110
 
 
111
  = 1.3 =
112
+ * Fixed a bug where duplicate URLs were being overwritten, fixed a bug where you could not completely remove all redirects.
113
 
114
  = 1.2 =
115
  * Fixed some little bugs.
120
  = 1.0 =
121
  * Release.
122
 
123
+ == Frequently Asked Questions ==
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
+ =What is a 301 Redirect?=
126
+ A redirect is a simple way to re-route traffic coming to a Requested URL to different Destination URL.
127
 
128
+ A 301 redirect indicates that the page requested has been permanently moved to the Destination URL, and helps pass on the Requested URLs traffic in a search engine friendly manner. Creating a 301 redirect tells search engines that the Requested URL has moved permanently, and that the content can now be found on the Destination URL. An important feature is that search engines will pass along any clout the Requested URL used to have to the Destination URL.
 
129
 
130
+ =I'm getting an error about the default permalink structure?=
 
131
 
132
+ 301 Redirects requires that you use anything but the default permalink structure.
133
 
134
+ =My redirects aren't working=
 
135
 
136
+ This could be caused by many things, but please ensure that you are supplying valid URLs. Most common are extra spaces, extra slashes, spelling mistakes and invalid characters. If you're sure they're right, chances are your browser has cached the 301 redirect (in an attempt to make the redirection faster for you), but sometimes it doesn't refresh as fast as we would like. Clear your browser cache, or wait a few minutes to fix this problem.
137
+ My redirects aren't working - the old .html page still shows
138
+ For this plugin to work, the page must be within the WordPress environment. If you are redirecting older .html or .php files, you must first delete them. The plugin can’t redirect if the file still exists, sorry! You should look into .htaccess redirects if you want to keep these files on your server.
139
 
140
+ =My redirects aren't getting the 301 status code=
 
141
 
142
+ Your Request or Redirect URLS may be incorrect; please ensure that you are supplying valid URLs. Check slashes. Try Viewing the page by clicking the Request URL - does it load correctly?
 
143
 
144
+ =How do I delete a redirect?=
 
145
 
146
+ Click the small X beside the redirect you wish to remove.
 
147
 
148
+ =How do I add wildcards. or folder redirects?=
 
149
 
150
+ Unfortunately this is not supported. You should look into .htaccess redirects for these advanced features.
 
151
 
 
 
152
 
153
+ =What about query strings?=
 
154
 
155
+ By default, any URL with a query string is considered unique, and will redirect to a unique page (if you so wish). The query string will be added to the Destination URL, which allows you to keep your tracking codes, affiliate codes, and other important data!
 
templates/admin-panel-cache.php CHANGED
@@ -6,14 +6,14 @@
6
  * The cache panel widget.
7
  *
8
  * @package EPS 301 Redirects
9
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
  ?>
12
 
13
  <div class="eps-panel eps-margin-top">
14
  <form method="post" action="">
15
  <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
16
- <input type="submit" name="eps_redirect_refresh" id="submit" class="button button-secondary" value="Refresh Cache"/>
17
  <br><small class="eps-grey-text">Refresh the cache if the dropdowns are out of date.</small>
18
  </form>
19
- </div>
6
  * The cache panel widget.
7
  *
8
  * @package EPS 301 Redirects
9
+ * @author WebFactory Ltd
10
  */
11
  ?>
12
 
13
  <div class="eps-panel eps-margin-top">
14
  <form method="post" action="">
15
  <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
16
+ <input type="submit" name="eps_redirect_refresh" id="submit" class="button button-secondary" value="Refresh Cache" />
17
  <br><small class="eps-grey-text">Refresh the cache if the dropdowns are out of date.</small>
18
  </form>
19
+ </div>
templates/admin-panel-donate.php CHANGED
@@ -6,23 +6,11 @@
6
  * The donate panel widget.
7
  *
8
  * @package EPS 301 Redirects
9
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
  ?>
12
 
13
-
14
  <div id="donate-box" class="eps-panel">
15
- <div class="eps-padding">
16
- <p>Comments, questions, bugs and feature requests can be sent to: <a href="mailto:plugins@eggplantstudios.ca">plugins@eggplantstudios.ca</a>. Please quote the plugin version: <?php echo get_option( 'eps_redirects_version' ); ?></p>
17
- <hr>
18
- <h3>Please consider donating</h3>
19
- <p>Your donations help support future versions EPS 301 Redirects.</p>
20
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
21
- <p>
22
- <input type="hidden" name="cmd" value="_s-xclick">
23
- <input type="hidden" name="hosted_button_id" value="2WC9XYFX49CSQ">
24
- <input class="button button-secondary" type="submit" name="submit" value="Donate">
25
- </p>
26
- </form>
27
- </div>
28
- </div>
6
  * The donate panel widget.
7
  *
8
  * @package EPS 301 Redirects
9
+ * @author WebFactory Ltd
10
  */
11
  ?>
12
 
 
13
  <div id="donate-box" class="eps-panel">
14
+ <p>Please send comments, questions, bugs and feature requests to: <a
15
+ href="mailto:support@webfactoryltd.com?subject=301%20Redirects%20plugin">support@webfactoryltd.com</a>.</p>
16
+ </div>
 
 
 
 
 
 
 
 
 
 
 
templates/admin-tab-404s.php CHANGED
@@ -6,45 +6,25 @@
6
  * The main admin area for the 404 tab.
7
  *
8
  * @package EPS 301 Redirects
9
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
  ?>
12
 
13
  <div class="wrap">
14
- <?php do_action('eps_redirects_admin_head'); ?>
15
-
16
- <div class="eps-panel eps-margin-top group">
17
- <div class="eps-redirects-50 group">
18
- <h1>Take your redirects to the next level!</h1>
19
- <p class="eps-redirects-lead">The <a href="http://www.eggplantstudios.ca/cart/?add_to_cart=2974" target="_blank">Pro Version of EPS 301 Redirects</a> will add a new 404 tracking feature. Every 404 error will be logged, and you will have the power and flexibility to redirect them wherever you want them to go.</p>
20
-
21
- <ul id="eps-redirects-checklist">
22
- <li><span>See which Request URLs are causing 404 errors on your site.</span></li>
23
- <li><span>Discover which 404 errors are receiving the most traffic.</span></li>
24
- <li><span>Improve SEO by lowering your total number of 404 errors.</span></li>
25
- <li><span>Easily fix the 404 errors by turning them into redirects.</span></li>
26
- </ul>
27
- </div>
28
- <div class="eps-redirects-50 group">
29
- <div class="padding-lots">
30
- <a href="http://www.eggplantstudios.ca/cart/?add_to_cart=2974" target="_blank">
31
- <img class="eps-redirects-fit" src="<?php echo EPS_REDIRECT_URL; ?>/images/icon-eps-redirects.jpg" title="Upgrade EPS 301 Redirects">
32
- </a>
33
- <a class="eps-redirects-big-button" href="http://www.eggplantstudios.ca/cart/?add_to_cart=2974" target="_blank">BUY NOW &bull; ONLY $15.00</a>
34
-
35
- </div>
36
- </div>
37
- </div>
38
-
39
-
40
- <div class="right">
41
- <?php do_action('eps_redirects_panels_right'); ?>
42
- </div>
43
- <div class="left">
44
- <?php do_action('eps_redirects_panels_left'); ?>
45
- </div>
46
  </div>
47
-
48
-
49
-
50
-
6
  * The main admin area for the 404 tab.
7
  *
8
  * @package EPS 301 Redirects
9
+ * @author WebFactory Ltd
10
  */
11
  ?>
12
 
13
  <div class="wrap">
14
+ <?php do_action('eps_redirects_admin_head'); ?>
15
+
16
+ <div class="eps-panel eps-margin-top group">
17
+ <h1>Coming soon</h1>
18
+ <p>This feature will be available in one of the next versions.<br>
19
+ Want us to work faster? :) Give us a shout <a href="https://twitter.com/webfactoryltd" target="_blank">@webfactoryltd</a>.</p>
20
+ </div>
21
+
22
+ <div class="right">
23
+ <?php do_action('eps_redirects_panels_right'); ?>
24
+ </div>
25
+ <div class="left">
26
+ <?php
27
+ // do_action('eps_redirects_panels_left');
28
+ ?>
29
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  </div>
 
 
 
 
templates/admin-tab-error.php CHANGED
@@ -6,7 +6,7 @@
6
  * The main admin area for the redirects tab.
7
  *
8
  * @package EPS 301 Redirects
9
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
  ?>
12
 
@@ -25,8 +25,4 @@
25
  <div class="left">
26
  <?php do_action('eps_redirects_panels_left'); ?>
27
  </div>
28
- </div>
29
-
30
-
31
-
32
-
6
  * The main admin area for the redirects tab.
7
  *
8
  * @package EPS 301 Redirects
9
+ * @author WebFactory Ltd
10
  */
11
  ?>
12
 
25
  <div class="left">
26
  <?php do_action('eps_redirects_panels_left'); ?>
27
  </div>
28
+ </div>
 
 
 
 
templates/admin-tab-import-export.php CHANGED
@@ -6,42 +6,45 @@
6
  * The main admin area for the import/export tab.
7
  *
8
  * @package EPS 301 Redirects
9
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
  ?>
12
 
13
  <div class="wrap">
14
 
15
- <?php do_action('eps_redirects_admin_head'); ?>
16
 
17
- <div class="eps-panel eps-margin-top">
18
- <h3>Import:</h3>
19
- <form method="post" action="" class="eps-padding" enctype="multipart/form-data">
20
- <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
21
- <input accept="csv" type="file" name="eps_redirect_upload_file" value="">
22
- <input type="submit" name="eps_redirect_upload" id="submit" class="button button-secondary" value="Upload CSV"/>
23
- <p>
24
- <input type="radio" name="eps_redirect_upload_method" value="skip" checked="checked"> Skip Duplicates
25
- &nbsp;&nbsp;&nbsp;<input type="radio" name="eps_redirect_upload_method" value="update"> Update Duplicates
26
- </p>
27
 
28
- <br><small class="eps-grey-text">Supply Columns: <strong>Status</strong> (301,302,inactive), <strong>Request URL</strong>, <strong>Redirect To</strong> (ID or URL). <a href="<?php echo EPS_REDIRECT_URL . 'example.csv'?>" target="_blank">Download Example CSV</a></small>
29
- </form>
30
- </div>
 
31
 
32
- <div class="eps-panel eps-margin-top">
33
- <h3>Export:</h3>
34
- <form method="post" action="">
35
- <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
36
- <input type="submit" name="eps_redirect_export" id="submit" class="button button-secondary" value="Export Redirects"/>
37
- <br><small class="eps-grey-text">Export a backup copy of your redirects.</small>
38
- </form>
39
- </div>
40
 
41
- <div class="right">
42
- <?php do_action('eps_redirects_panels_right'); ?>
43
- </div>
44
- <div class="left">
45
- <?php do_action('eps_redirects_panels_left'); ?>
46
- </div>
47
- </div>
 
 
6
  * The main admin area for the import/export tab.
7
  *
8
  * @package EPS 301 Redirects
9
+ * @author WebFactory Ltd
10
  */
11
  ?>
12
 
13
  <div class="wrap">
14
 
15
+ <?php do_action('eps_redirects_admin_head'); ?>
16
 
17
+ <div class="eps-panel eps-margin-top">
18
+ <h3>Import:</h3>
19
+ <form method="post" action="" class="eps-padding" enctype="multipart/form-data">
20
+ <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
21
+ <input accept="csv" type="file" name="eps_redirect_upload_file" value="">
22
+ <input type="submit" name="eps_redirect_upload" id="submit" class="button button-secondary" value="Upload CSV" />
23
+ <p>
24
+ <input type="radio" name="eps_redirect_upload_method" value="skip" checked="checked"> Skip Duplicates
25
+ &nbsp;&nbsp;&nbsp;<input type="radio" name="eps_redirect_upload_method" value="update"> Update Duplicates
26
+ </p>
27
 
28
+ <br><small class="eps-grey-text">Supply Columns: <strong>Status</strong> (301,302,inactive), <strong>Request URL</strong>, <strong>Redirect
29
+ To</strong> (ID or URL). <a href="<?php echo EPS_REDIRECT_URL . 'example.csv' ?>" target="_blank">Download Example CSV</a></small>
30
+ </form>
31
+ </div>
32
 
33
+ <div class="eps-panel eps-margin-top">
34
+ <h3>Export:</h3>
35
+ <form method="post" action="">
36
+ <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
37
+ <input type="submit" name="eps_redirect_export" id="submit" class="button button-secondary" value="Export Redirects" />
38
+ <br><small class="eps-grey-text">Export a backup copy of your redirects.</small>
39
+ </form>
40
+ </div>
41
 
42
+ <div class="right">
43
+ <?php do_action('eps_redirects_panels_right'); ?>
44
+ </div>
45
+ <div class="left">
46
+ <?php
47
+ // do_action('eps_redirects_panels_left');
48
+ ?>
49
+ </div>
50
+ </div>
templates/admin-tab-redirects.php CHANGED
@@ -6,43 +6,39 @@
6
  * The main admin area for the redirects tab.
7
  *
8
  * @package EPS 301 Redirects
9
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
  global $EPS_Redirects_Plugin;
12
 
13
 
14
  ?>
15
 
16
-
17
  <div class="wrap">
18
- <?php do_action('eps_redirects_admin_head'); ?>
19
-
20
- <table id="eps-redirect-entries" class="eps-table eps-table-striped">
21
- <tr>
22
- <th class="redirect-small"> <?php eps_get_ordered_filter('id', 'ID'); ?> </th>
23
- <th> <?php eps_get_ordered_filter('url_from', 'Redirect From'); ?> </th>
24
- <th> <?php eps_get_ordered_filter('url_to', 'Redirect To'); ?> </th>
25
- <th class="redirect-small"> <?php eps_get_ordered_filter('count', 'Hits'); ?> </th>
26
- <th class="redirect-actions">Actions</th>
27
- </tr>
28
-
29
- <tr id="eps-redirect-add" style="display:none"><td colspan="5"><a href="#" id="eps-redirect-new"><span>+</span></a></td></tr>
30
-
31
- <?php
 
 
32
  echo EPS_Redirects::get_inline_edit_entry();
33
  echo EPS_Redirects::list_redirects();
34
  ?>
35
- </table>
36
-
37
-
38
- <div class="right">
39
- <?php do_action('eps_redirects_panels_right'); ?>
40
- </div>
41
- <div class="left">
42
- <?php do_action('eps_redirects_panels_left'); ?>
43
- </div>
44
  </div>
45
-
46
-
47
-
48
-
6
  * The main admin area for the redirects tab.
7
  *
8
  * @package EPS 301 Redirects
9
+ * @author WebFactory Ltd
10
  */
11
  global $EPS_Redirects_Plugin;
12
 
13
 
14
  ?>
15
 
 
16
  <div class="wrap">
17
+ <?php do_action('eps_redirects_admin_head'); ?>
18
+
19
+ <table id="eps-redirect-entries" class="eps-table eps-table-striped">
20
+ <tr>
21
+ <th class="redirect-small"> <?php eps_get_ordered_filter('id', 'ID'); ?> </th>
22
+ <th> <?php eps_get_ordered_filter('url_from', 'Redirect From'); ?> </th>
23
+ <th> <?php eps_get_ordered_filter('url_to', 'Redirect To'); ?> </th>
24
+ <th class="redirect-small"> <?php eps_get_ordered_filter('count', 'Hits'); ?> </th>
25
+ <th class="redirect-actions">Actions</th>
26
+ </tr>
27
+
28
+ <tr id="eps-redirect-add" style="display:none;">
29
+ <td style=" text-align: center;" colspan="5"><a href="#" class="button button-primary" id="eps-redirect-new">Add New Redirect Rule</a></td>
30
+ </tr>
31
+
32
+ <?php
33
  echo EPS_Redirects::get_inline_edit_entry();
34
  echo EPS_Redirects::list_redirects();
35
  ?>
36
+ </table>
37
+
38
+ <div class="right">
39
+ <?php do_action('eps_redirects_panels_right'); ?>
40
+ </div>
41
+ <div class="left">
42
+ <?php do_action('eps_redirects_panels_left'); ?>
43
+ </div>
 
44
  </div>
 
 
 
 
templates/template.redirect-entry-edit-inline.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /**
3
  *
4
- * Outputs the whole inline entry edit html.
5
  *
6
  *
7
  * @package EPS 301 Redirects
8
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
9
  *
10
  */
11
 
@@ -16,11 +16,12 @@
16
  <form id="eps-redirect-save" method="post" action="">
17
  <table class="eps-table">
18
  <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
19
- <?php include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit.php'); ?>
20
  <td class="redirect-actions">
21
- <?php if( $redirect_id ) { ?>
22
  <a class="button eps-redirect-cancel">Close</a>
23
- <?php } ?>
 
24
  <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
25
  <input type="submit" name="eps_redirect_submit" class="button button-primary eps-redirect-edit" value="Save">
26
  </td>
@@ -28,4 +29,4 @@
28
  </table>
29
  </form>
30
  </td>
31
- </tr>
1
  <?php
2
  /**
3
  *
4
+ * Outputs the whole inline entry edit html.
5
  *
6
  *
7
  * @package EPS 301 Redirects
8
+ * @author WebFactory Ltd
9
  *
10
  */
11
 
16
  <form id="eps-redirect-save" method="post" action="">
17
  <table class="eps-table">
18
  <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
19
+ <?php include(EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit.php'); ?>
20
  <td class="redirect-actions">
21
+ <?php if ($redirect_id) { ?>
22
  <a class="button eps-redirect-cancel">Close</a>
23
+ <?php
24
+ } ?>
25
  <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
26
  <input type="submit" name="eps_redirect_submit" class="button button-primary eps-redirect-edit" value="Save">
27
  </td>
29
  </table>
30
  </form>
31
  </td>
32
+ </tr>
templates/template.redirect-entry-edit.php CHANGED
@@ -1,30 +1,30 @@
1
  <?php
2
  /**
3
- *
4
  *
5
- * Outputs the edit form for a given $redirect_id. If $redirect_id is not set, assume this is a new redirect form.
6
- *
7
- *
 
8
  * @package EPS 301 Redirects
9
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
 
12
- $redirect = self::get_redirect( $redirect_id );
13
 
14
  ?>
15
  <td>
16
- <input type="hidden" type="text" name="redirect[id][]" value="<?php echo ($redirect_id) ? $redirect_id : ''; ?>" >
17
-
18
  <select name="redirect[status][]" class="eps-small-select">
19
- <option default value="301" <?php echo ( $redirect && $redirect->status == '301' ) ? 'selected="selected"' : null; ?>>301</option>
20
- <option value="302" <?php echo ( $redirect && $redirect->status == '302' ) ? 'selected="selected"' : null; ?>>302</option>
21
- <option value="inactive" <?php echo ( $redirect && $redirect->status == 'inactive' ) ? 'selected="selected"' : null; ?>>Off</option>
22
  </select>
23
-
24
  <div class="eps-url"><span class="eps-url-root"><?php bloginfo('url'); ?>/&nbsp;</span></div>
25
- <input class="eps-url-input" type="text" name="redirect[url_from][]" value="<?php echo ($redirect) ? $redirect->url_from : ''; ?>" >
26
-
27
  </td>
28
  <td>
29
- <?php echo eps_get_selector( $redirect ); ?>
30
- </td>
1
  <?php
2
  /**
 
3
  *
4
+ *
5
+ * Outputs the edit form for a given $redirect_id. If $redirect_id is not set, assume this is a new redirect form.
6
+ *
7
+ *
8
  * @package EPS 301 Redirects
9
+ * @author WebFactory Ltd
10
  */
11
 
12
+ $redirect = self::get_redirect($redirect_id);
13
 
14
  ?>
15
  <td>
16
+ <input type="hidden" type="text" name="redirect[id][]" value="<?php echo ($redirect_id) ? $redirect_id : ''; ?>">
17
+
18
  <select name="redirect[status][]" class="eps-small-select">
19
+ <option default value="301" <?php echo ($redirect && $redirect->status == '301') ? 'selected="selected"' : null; ?>>301</option>
20
+ <option value="302" <?php echo ($redirect && $redirect->status == '302') ? 'selected="selected"' : null; ?>>302</option>
21
+ <option value="inactive" <?php echo ($redirect && $redirect->status == 'inactive') ? 'selected="selected"' : null; ?>>Off</option>
22
  </select>
23
+
24
  <div class="eps-url"><span class="eps-url-root"><?php bloginfo('url'); ?>/&nbsp;</span></div>
25
+ <input class="eps-url-input" type="text" name="redirect[url_from][]" value="<?php echo ($redirect) ? $redirect->url_from : ''; ?>">
26
+
27
  </td>
28
  <td>
29
+ <?php echo eps_get_selector($redirect); ?>
30
+ </td>
templates/template.redirect-entry.php CHANGED
@@ -5,29 +5,33 @@
5
  *
6
  *
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 ) );
13
 
14
 
15
  ?>
16
- <tr class="redirect-entry <?php echo esc_attr( $redirect->status ); ?> id-<?php echo esc_attr( $redirect->id ); ?>" data-id="<?php echo esc_attr( $redirect->id ); ?>" data-status="<?php echo esc_attr( $redirect->status ); ?>">
17
- <td>
18
- <p class="eps-grey-text eps-text-center eps-small"><?php echo $redirect->id; ?></p>
19
- </td>
20
- <td>
21
- <a target="_blank" class="eps-url" href="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>" title="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>">
22
- <span class="eps-url-root eps-url-startcap"><?php echo ($redirect->status == 'inactive' ) ? 'OFF': esc_attr($redirect->status); ?></span><span class="eps-url-root"><?php bloginfo('url'); ?>/</span><span class="eps-url-fragment eps-url-endcap"><?php echo esc_attr($dfrom); ?></span>
23
- </a>
24
- </td>
25
- <td>
26
- <?php echo eps_get_destination( $redirect ); ?>
27
- </td>
28
- <td class="redirect-hits"><strong><?php echo esc_attr( $redirect->count ); ?></strong></td>
29
- <td class="redirect-actions">
30
- <a class="button eps-redirect-edit" href="#eps-redirect-edit" data-id="<?php echo esc_attr( $redirect->id ); ?>">Edit</a>
31
- <a class="button eps-redirect-remove" href="<?php echo add_query_arg( $query_args, admin_url( '/options-general.php' ) ); ?>" data-id="<?php echo esc_attr( $redirect->id ); ?>">&times;</a>
32
- </td>
33
- </tr>
 
 
 
 
5
  *
6
  *
7
  * @package EPS 301 Redirects
8
+ * @author WebFactory Ltd
9
  */
10
 
11
  global $EPS_Redirects_Plugin;
12
+ $query_args = array('page' => $EPS_Redirects_Plugin->config('page_slug'), 'delete_redirect' => esc_attr($redirect->id));
13
 
14
 
15
  ?>
16
+ <tr class="redirect-entry <?php echo esc_attr($redirect->status); ?> id-<?php echo esc_attr($redirect->id); ?>"
17
+ data-id="<?php echo esc_attr($redirect->id); ?>" data-status="<?php echo esc_attr($redirect->status); ?>">
18
+ <td>
19
+ <p class="eps-grey-text eps-text-center eps-small"><?php echo $redirect->id; ?></p>
20
+ </td>
21
+ <td>
22
+ <a target="_blank" class="eps-url" href="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>"
23
+ title="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>">
24
+ <span class="eps-url-root eps-url-startcap"><?php echo ($redirect->status == 'inactive') ? 'OFF' : esc_attr($redirect->status); ?></span><span
25
+ class="eps-url-root"><?php bloginfo('url'); ?>/</span><span class="eps-url-fragment eps-url-endcap"><?php echo esc_attr($dfrom); ?></span>
26
+ </a>
27
+ </td>
28
+ <td>
29
+ <?php echo eps_get_destination($redirect); ?>
30
+ </td>
31
+ <td class="redirect-hits"><strong><?php echo esc_attr(number_format($redirect->count)); ?></strong></td>
32
+ <td class="redirect-actions">
33
+ <a class="button eps-redirect-edit" href="#eps-redirect-edit" data-id="<?php echo esc_attr($redirect->id); ?>">Edit</a>
34
+ <a class="button eps-redirect-remove" href="<?php echo add_query_arg($query_args, admin_url('/options-general.php')); ?>"
35
+ data-id="<?php echo esc_attr($redirect->id); ?>">Delete</a>
36
+ </td>
37
+ </tr>