Safe Redirect Manager - Version 1.9

Version Description

  • Add redirect notes feature.
  • Fix PHP 7.2 errors
  • Instantiate classes in main file instead of individual files for improved testability.
  • Add filters for request path and redirect path
  • Add filter to only apply redirects on 404
Download this release

Release Info

Developer tlovett1
Plugin Icon 128x128 Safe Redirect Manager
Version 1.9
Comparing to
See all releases

Code changes from version 1.8 to 1.9

README.md CHANGED
@@ -1,8 +1,12 @@
1
- Safe Redirect Manager [![Build Status](https://travis-ci.org/tlovett1/safe-redirect-manager.svg?branch=master)](https://travis-ci.org/tlovett1/safe-redirect-manager)
2
  ==============
3
 
4
  A WordPress plugin to safely and easily manage your website's HTTP redirects.
5
 
 
 
 
 
6
  ## Purpose
7
 
8
  Easily and safely manage your site's redirects the WordPress way. There are many redirect plugins available. Most of
@@ -15,7 +19,7 @@ WordPress mantra, decisions not options. Actions in filters make the plugin very
15
  ## Installation
16
 
17
  Install the plugin in WordPress. You can download a
18
- [zip via Github](https://github.com/tlovett1/safe-redirect-manager/archive/master.zip) and upload it using the WP
19
  plugin uploader.
20
 
21
  ## Non-English Usage
@@ -73,10 +77,6 @@ add_filter( 'my_srm_redirect_loop_filter', '__return_true' );
73
  Follow the configuration instructions above to setup the plugin. I recommend developing the plugin locally in an
74
  environment such as [WP Local Docker](https://github.com/10up/wp-local-docker).
75
 
76
- #### Translation
77
- Safe Redirect Manager has a [.pot file](https://github.com/tlovett1/Safe-Redirect-Manager/blob/master/lang/safe-redirect-manager.pot)
78
- containing strings ready for translation.
79
-
80
  #### Testing
81
  Within the terminal change directories to the plugin folder. Initialize your unit testing environment by running the
82
  following command:
@@ -92,4 +92,4 @@ phpunit
92
 
93
  #### Issues
94
  If you identify any errors or have an idea for improving the plugin, please
95
- [open an issue](https://github.com/tlovett1/safe-redirect-manager/issues?state=open).
1
+ Safe Redirect Manager [![Build Status](https://travis-ci.org/10up/safe-redirect-manager.svg?branch=master)](https://travis-ci.org/10up/safe-redirect-manager)
2
  ==============
3
 
4
  A WordPress plugin to safely and easily manage your website's HTTP redirects.
5
 
6
+ <p align="center">
7
+ <a href="http://10up.com/contact/"><img src="https://10updotcom-wpengine.s3.amazonaws.com/uploads/2016/10/10up-Github-Banner.png" width="850"></a>
8
+ </p>
9
+
10
  ## Purpose
11
 
12
  Easily and safely manage your site's redirects the WordPress way. There are many redirect plugins available. Most of
19
  ## Installation
20
 
21
  Install the plugin in WordPress. You can download a
22
+ [zip via Github](https://github.com/10up/safe-redirect-manager/archive/master.zip) and upload it using the WP
23
  plugin uploader.
24
 
25
  ## Non-English Usage
77
  Follow the configuration instructions above to setup the plugin. I recommend developing the plugin locally in an
78
  environment such as [WP Local Docker](https://github.com/10up/wp-local-docker).
79
 
 
 
 
 
80
  #### Testing
81
  Within the terminal change directories to the plugin folder. Initialize your unit testing environment by running the
82
  following command:
92
 
93
  #### Issues
94
  If you identify any errors or have an idea for improving the plugin, please
95
+ [open an issue](https://github.com/10up/safe-redirect-manager/issues?state=open).
assets/banner-772x250.png DELETED
Binary file
assets/icon-256x256.png DELETED
Binary file
inc/classes/class-srm-post-type.php CHANGED
@@ -27,6 +27,7 @@ class SRM_Post_Type {
27
  add_action( 'init', array( $this, 'action_register_post_types' ) );
28
  add_action( 'save_post', array( $this, 'action_save_post' ) );
29
  add_filter( 'manage_redirect_rule_posts_columns', array( $this, 'filter_redirect_columns' ) );
 
30
  add_action( 'manage_redirect_rule_posts_custom_column', array( $this, 'action_custom_redirect_columns' ), 10, 2 );
31
  add_action( 'transition_post_status', array( $this, 'action_transition_post_status' ), 10, 3 );
32
  add_filter( 'post_updated_messages', array( $this, 'filter_redirect_updated_messages' ) );
@@ -37,6 +38,7 @@ class SRM_Post_Type {
37
  add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
38
  add_action( 'admin_print_styles-post-new.php', array( $this, 'action_print_logo_css' ), 10, 1 );
39
  add_filter( 'post_type_link', array( $this, 'filter_post_type_link' ), 10, 2 );
 
40
 
41
  // Search filters
42
  add_filter( 'posts_join', array( $this, 'filter_search_join' ) );
@@ -45,6 +47,24 @@ class SRM_Post_Type {
45
  add_filter( 'post_row_actions', array( $this, 'filter_disable_quick_edit' ), 10, 2 );
46
  }
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  /**
49
  * Remove quick edit
50
  *
@@ -160,11 +180,15 @@ class SRM_Post_Type {
160
 
161
  if ( ! empty( $s ) ) {
162
  preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', stripslashes( $s ), $matches );
163
- $search_terms = array_map( create_function( '$a', 'return trim( $a, "\\"\'\\n\\r " );' ), $matches[0] );
164
  }
165
  return $search_terms;
166
  }
167
 
 
 
 
 
168
  /**
169
  * Swap tools logo for plugin logo
170
  *
@@ -235,12 +259,15 @@ class SRM_Post_Type {
235
  </div>
236
  <?php
237
  }
238
- } if ( srm_max_redirects_reached() ) {
 
 
 
 
 
 
 
239
  ?>
240
- <?php
241
- if ( 'post-new.php' === $hook_suffix ) :
242
- ?>
243
- <style type="text/css">#post { display: none; }</style><?php endif; ?>
244
  <div class="error">
245
  <p><?php esc_html_e( 'Safe Redirect Manager Error: You have reached the maximum allowable number of redirects', 'safe-redirect-manager' ); ?></p>
246
  </div>
@@ -347,6 +374,9 @@ class SRM_Post_Type {
347
  echo esc_html( get_post_meta( $post_id, '_redirect_rule_to', true ) );
348
  } elseif ( 'srm_redirect_rule_status_code' === $column ) {
349
  echo absint( get_post_meta( $post_id, '_redirect_rule_status_code', true ) );
 
 
 
350
  }
351
  }
352
 
@@ -360,6 +390,7 @@ class SRM_Post_Type {
360
  public function filter_redirect_columns( $columns ) {
361
  $columns['srm_redirect_rule_to'] = esc_html__( 'Redirect To', 'safe-redirect-manager' );
362
  $columns['srm_redirect_rule_status_code'] = esc_html__( 'HTTP Status Code', 'safe-redirect-manager' );
 
363
 
364
  // Change the title column
365
  $columns['title'] = esc_html__( 'Redirect From', 'safe-redirect-manager' );
@@ -371,6 +402,18 @@ class SRM_Post_Type {
371
  return $columns;
372
  }
373
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  /**
375
  * Saves meta info for redirect rules
376
  *
@@ -413,6 +456,12 @@ class SRM_Post_Type {
413
  delete_post_meta( $post_id, '_redirect_rule_status_code' );
414
  }
415
 
 
 
 
 
 
 
416
  /**
417
  * This fixes an important bug where the redirect cache was not up-to-date. Previously the cache was only being
418
  * updated on transition_post_status which gets called BEFORE save post. But since save_post is where all the important
@@ -430,7 +479,7 @@ class SRM_Post_Type {
430
  * @return void
431
  */
432
  public function action_register_post_types() {
433
- $redirect_labels = array(
434
  'name' => esc_html_x( 'Safe Redirect Manager', 'post type general name', 'safe-redirect-manager' ),
435
  'singular_name' => esc_html_x( 'Redirect', 'post type singular name', 'safe-redirect-manager' ),
436
  'add_new' => _x( 'Create Redirect Rule', 'redirect rule', 'safe-redirect-manager' ),
@@ -448,21 +497,21 @@ class SRM_Post_Type {
448
 
449
  $redirect_capability = 'srm_manage_redirects';
450
 
451
- $roles = array( 'administrator' );
452
 
453
- foreach ( $roles as $role ) {
454
  $role = get_role( $role );
455
 
456
  if ( empty( $role ) || $role->has_cap( $redirect_capability ) ) {
457
  continue;
458
  }
459
 
460
- $role->add_cap( $redirect_capability );
461
- }
462
 
463
  $redirect_capability = apply_filters( 'srm_restrict_to_capability', $redirect_capability );
464
 
465
- $capabilities = array(
466
  'edit_post' => $redirect_capability,
467
  'read_post' => $redirect_capability,
468
  'delete_post' => $redirect_capability,
@@ -487,7 +536,7 @@ class SRM_Post_Type {
487
  'hierarchical' => false,
488
  'register_meta_box_cb' => array( $this, 'action_redirect_rule_metabox' ),
489
  'menu_position' => 80,
490
- 'supports' => array( '' ),
491
  );
492
  register_post_type( 'redirect_rule', $redirect_args );
493
  }
@@ -514,17 +563,18 @@ class SRM_Post_Type {
514
  public function redirect_rule_metabox( $post ) {
515
  wp_nonce_field( 'srm-save-redirect-meta', 'srm_redirect_nonce' );
516
 
517
- $redirect_from = get_post_meta( $post->ID, '_redirect_rule_from', true );
518
- $redirect_to = get_post_meta( $post->ID, '_redirect_rule_to', true );
519
- $status_code = get_post_meta( $post->ID, '_redirect_rule_status_code', true );
520
- $enable_regex = get_post_meta( $post->ID, '_redirect_rule_from_regex', true );
 
521
 
522
  if ( empty( $status_code ) ) {
523
  $status_code = apply_filters( 'srm_default_direct_status', 302 );
524
  }
525
  ?>
526
  <p>
527
- <label for="srm_redirect_rule_from"><?php esc_html_e( 'Redirect From:', 'safe-redirect-manager' ); ?></label><br />
528
  <input type="text" name="srm_redirect_rule_from" id="srm_redirect_rule_from" value="<?php echo esc_attr( $redirect_from ); ?>" />
529
  <input type="checkbox" name="srm_redirect_rule_from_regex" id="srm_redirect_rule_from_regex" <?php checked( true, (bool) $enable_regex ); ?> value="1" />
530
  <label for="srm_redirect_rule_from_regex"><?php esc_html_e( 'Enable Regular Expressions (advanced)', 'safe-redirect-manager' ); ?></label>
@@ -532,13 +582,13 @@ class SRM_Post_Type {
532
  <p class="description"><?php esc_html_e( 'This path should be relative to the root of this WordPress installation (or the sub-site, if you are running a multi-site). Appending a (*) wildcard character will match all requests with the base. Warning: Enabling regular expressions will disable wildcards and completely change the way the * symbol is interpretted.', 'safe-redirect-manager' ); ?></p>
533
 
534
  <p>
535
- <label for="srm_redirect_rule_to"><?php esc_html_e( 'Redirect To:', 'safe-redirect-manager' ); ?></label><br />
536
  <input class="widefat" type="text" name="srm_redirect_rule_to" id="srm_redirect_rule_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
537
  </p>
538
  <p class="description"><?php esc_html_e( 'This can be a URL or a path relative to the root of your website (not your WordPress installation). Ending with a (*) wildcard character will append the request match to the redirect.', 'safe-redirect-manager' ); ?></p>
539
 
540
  <p>
541
- <label for="srm_redirect_rule_status_code"><?php esc_html_e( 'HTTP Status Code:', 'safe-redirect-manager' ); ?></label>
542
  <select name="srm_redirect_rule_status_code" id="srm_redirect_rule_status_code">
543
  <?php foreach ( srm_get_valid_status_codes() as $code ) : ?>
544
  <option value="<?php echo esc_attr( $code ); ?>" <?php selected( $status_code, $code ); ?>><?php echo esc_html( $code . ' ' . $this->status_code_labels[ $code ] ); ?></option>
@@ -546,6 +596,12 @@ class SRM_Post_Type {
546
  </select>
547
  <em><?php esc_html_e( "If you don't know what this is, leave it as is.", 'safe-redirect-manager' ); ?></em>
548
  </p>
 
 
 
 
 
 
549
  <?php
550
  }
551
 
@@ -602,4 +658,3 @@ class SRM_Post_Type {
602
  }
603
  }
604
 
605
- SRM_Post_Type::factory();
27
  add_action( 'init', array( $this, 'action_register_post_types' ) );
28
  add_action( 'save_post', array( $this, 'action_save_post' ) );
29
  add_filter( 'manage_redirect_rule_posts_columns', array( $this, 'filter_redirect_columns' ) );
30
+ add_filter( 'manage_edit-redirect_rule_sortable_columns', array( $this, 'filter_redirect_sortable_columns' ) );
31
  add_action( 'manage_redirect_rule_posts_custom_column', array( $this, 'action_custom_redirect_columns' ), 10, 2 );
32
  add_action( 'transition_post_status', array( $this, 'action_transition_post_status' ), 10, 3 );
33
  add_filter( 'post_updated_messages', array( $this, 'filter_redirect_updated_messages' ) );
38
  add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
39
  add_action( 'admin_print_styles-post-new.php', array( $this, 'action_print_logo_css' ), 10, 1 );
40
  add_filter( 'post_type_link', array( $this, 'filter_post_type_link' ), 10, 2 );
41
+ add_filter( 'default_hidden_columns', array( $this, 'filter_hidden_columns' ), 10, 1 );
42
 
43
  // Search filters
44
  add_filter( 'posts_join', array( $this, 'filter_search_join' ) );
47
  add_filter( 'post_row_actions', array( $this, 'filter_disable_quick_edit' ), 10, 2 );
48
  }
49
 
50
+ /**
51
+ * Hide order column by default
52
+ *
53
+ * @param array $hidden
54
+ * @since 1.9
55
+ * @return array
56
+ */
57
+ public function filter_hidden_columns( $hidden ) {
58
+
59
+ if ( empty( $_GET['post_type'] ) || 'redirect_rule' !== $_GET['post_type'] ) {
60
+ return $hidden;
61
+ }
62
+
63
+ $hidden[] = 'menu_order';
64
+
65
+ return $hidden;
66
+ }
67
+
68
  /**
69
  * Remove quick edit
70
  *
180
 
181
  if ( ! empty( $s ) ) {
182
  preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', stripslashes( $s ), $matches );
183
+ $search_terms = array_map( array( 'SRM_Post_Type', 'clean_search_term' ), $matches[0] );
184
  }
185
  return $search_terms;
186
  }
187
 
188
+ public static function clean_search_term( $a ) {
189
+ return trim( $a, "\\\"'\\n\\r " );
190
+ }
191
+
192
  /**
193
  * Swap tools logo for plugin logo
194
  *
259
  </div>
260
  <?php
261
  }
262
+ }
263
+ if ( srm_max_redirects_reached() ) {
264
+
265
+ if ( 'post-new.php' === $hook_suffix ) {
266
+ ?>
267
+ <style type="text/css">#post { display: none; }</style>
268
+ <?php
269
+ }
270
  ?>
 
 
 
 
271
  <div class="error">
272
  <p><?php esc_html_e( 'Safe Redirect Manager Error: You have reached the maximum allowable number of redirects', 'safe-redirect-manager' ); ?></p>
273
  </div>
374
  echo esc_html( get_post_meta( $post_id, '_redirect_rule_to', true ) );
375
  } elseif ( 'srm_redirect_rule_status_code' === $column ) {
376
  echo absint( get_post_meta( $post_id, '_redirect_rule_status_code', true ) );
377
+ } elseif ( 'menu_order' == $column ) {
378
+ global $post;
379
+ echo $post->menu_order;
380
  }
381
  }
382
 
390
  public function filter_redirect_columns( $columns ) {
391
  $columns['srm_redirect_rule_to'] = esc_html__( 'Redirect To', 'safe-redirect-manager' );
392
  $columns['srm_redirect_rule_status_code'] = esc_html__( 'HTTP Status Code', 'safe-redirect-manager' );
393
+ $columns['menu_order'] = esc_html__( 'Order', 'safe-redirect-manager' );
394
 
395
  // Change the title column
396
  $columns['title'] = esc_html__( 'Redirect From', 'safe-redirect-manager' );
402
  return $columns;
403
  }
404
 
405
+ /**
406
+ * Allow menu_order column to be sortable.
407
+ *
408
+ * @param $columns
409
+ * @since 1.9
410
+ * @return mixed
411
+ */
412
+ public function filter_redirect_sortable_columns( $columns ) {
413
+ $columns['menu_order'] = 'menu_order';
414
+ return $columns;
415
+ }
416
+
417
  /**
418
  * Saves meta info for redirect rules
419
  *
456
  delete_post_meta( $post_id, '_redirect_rule_status_code' );
457
  }
458
 
459
+ if ( ! empty( $_POST['srm_redirect_rule_status_code'] ) ) {
460
+ update_post_meta( $post_id, '_redirect_rule_notes', sanitize_text_field( $_POST['srm_redirect_rule_notes'] ) );
461
+ } else {
462
+ delete_post_meta( $post_id, '_redirect_rule_notes' );
463
+ }
464
+
465
  /**
466
  * This fixes an important bug where the redirect cache was not up-to-date. Previously the cache was only being
467
  * updated on transition_post_status which gets called BEFORE save post. But since save_post is where all the important
479
  * @return void
480
  */
481
  public function action_register_post_types() {
482
+ $redirect_labels = array(
483
  'name' => esc_html_x( 'Safe Redirect Manager', 'post type general name', 'safe-redirect-manager' ),
484
  'singular_name' => esc_html_x( 'Redirect', 'post type singular name', 'safe-redirect-manager' ),
485
  'add_new' => _x( 'Create Redirect Rule', 'redirect rule', 'safe-redirect-manager' ),
497
 
498
  $redirect_capability = 'srm_manage_redirects';
499
 
500
+ $roles = array( 'administrator' );
501
 
502
+ foreach ( $roles as $role ) {
503
  $role = get_role( $role );
504
 
505
  if ( empty( $role ) || $role->has_cap( $redirect_capability ) ) {
506
  continue;
507
  }
508
 
509
+ $role->add_cap( $redirect_capability );
510
+ }
511
 
512
  $redirect_capability = apply_filters( 'srm_restrict_to_capability', $redirect_capability );
513
 
514
+ $capabilities = array(
515
  'edit_post' => $redirect_capability,
516
  'read_post' => $redirect_capability,
517
  'delete_post' => $redirect_capability,
536
  'hierarchical' => false,
537
  'register_meta_box_cb' => array( $this, 'action_redirect_rule_metabox' ),
538
  'menu_position' => 80,
539
+ 'supports' => array( 'page-attributes' ),
540
  );
541
  register_post_type( 'redirect_rule', $redirect_args );
542
  }
563
  public function redirect_rule_metabox( $post ) {
564
  wp_nonce_field( 'srm-save-redirect-meta', 'srm_redirect_nonce' );
565
 
566
+ $redirect_from = get_post_meta( $post->ID, '_redirect_rule_from', true );
567
+ $redirect_to = get_post_meta( $post->ID, '_redirect_rule_to', true );
568
+ $redirect_notes = get_post_meta( $post->ID, '_redirect_rule_notes', true );
569
+ $status_code = get_post_meta( $post->ID, '_redirect_rule_status_code', true );
570
+ $enable_regex = get_post_meta( $post->ID, '_redirect_rule_from_regex', true );
571
 
572
  if ( empty( $status_code ) ) {
573
  $status_code = apply_filters( 'srm_default_direct_status', 302 );
574
  }
575
  ?>
576
  <p>
577
+ <label for="srm_redirect_rule_from"><strong><?php esc_html_e( '* Redirect From:', 'safe-redirect-manager' ); ?></strong></label><br />
578
  <input type="text" name="srm_redirect_rule_from" id="srm_redirect_rule_from" value="<?php echo esc_attr( $redirect_from ); ?>" />
579
  <input type="checkbox" name="srm_redirect_rule_from_regex" id="srm_redirect_rule_from_regex" <?php checked( true, (bool) $enable_regex ); ?> value="1" />
580
  <label for="srm_redirect_rule_from_regex"><?php esc_html_e( 'Enable Regular Expressions (advanced)', 'safe-redirect-manager' ); ?></label>
582
  <p class="description"><?php esc_html_e( 'This path should be relative to the root of this WordPress installation (or the sub-site, if you are running a multi-site). Appending a (*) wildcard character will match all requests with the base. Warning: Enabling regular expressions will disable wildcards and completely change the way the * symbol is interpretted.', 'safe-redirect-manager' ); ?></p>
583
 
584
  <p>
585
+ <label for="srm_redirect_rule_to"><strong><?php esc_html_e( '* Redirect To:', 'safe-redirect-manager' ); ?></strong></label><br />
586
  <input class="widefat" type="text" name="srm_redirect_rule_to" id="srm_redirect_rule_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
587
  </p>
588
  <p class="description"><?php esc_html_e( 'This can be a URL or a path relative to the root of your website (not your WordPress installation). Ending with a (*) wildcard character will append the request match to the redirect.', 'safe-redirect-manager' ); ?></p>
589
 
590
  <p>
591
+ <label for="srm_redirect_rule_status_code"><strong><?php esc_html_e( '* HTTP Status Code:', 'safe-redirect-manager' ); ?></strong></label>
592
  <select name="srm_redirect_rule_status_code" id="srm_redirect_rule_status_code">
593
  <?php foreach ( srm_get_valid_status_codes() as $code ) : ?>
594
  <option value="<?php echo esc_attr( $code ); ?>" <?php selected( $status_code, $code ); ?>><?php echo esc_html( $code . ' ' . $this->status_code_labels[ $code ] ); ?></option>
596
  </select>
597
  <em><?php esc_html_e( "If you don't know what this is, leave it as is.", 'safe-redirect-manager' ); ?></em>
598
  </p>
599
+
600
+ <p>
601
+ <label for="srm_redirect_rule_notes"><strong><?php esc_html_e( 'Notes:', 'safe-redirect-manager' ); ?></strong></label>
602
+ <textarea name="srm_redirect_rule_notes" id="srm_redirect_rule_notes" class="widefat"><?php echo esc_attr( $redirect_notes ); ?></textarea>
603
+ <em><?php esc_html_e( 'Optionally leave notes on this redirect e.g. why was it created.', 'safe-redirect-manager' ); ?></em>
604
+ </p>
605
  <?php
606
  }
607
 
658
  }
659
  }
660
 
 
inc/classes/class-srm-redirect.php CHANGED
@@ -17,7 +17,15 @@ class SRM_Redirect {
17
  * @since 1.8
18
  */
19
  public function setup() {
20
- add_action( 'parse_request', array( $this, 'maybe_redirect' ), 0 );
 
 
 
 
 
 
 
 
21
  }
22
 
23
  /**
@@ -44,8 +52,8 @@ class SRM_Redirect {
44
  */
45
  public function maybe_redirect() {
46
 
47
- // Don't redirect from wp-admin
48
- if ( is_admin() ) {
49
  return;
50
  }
51
 
@@ -57,7 +65,7 @@ class SRM_Redirect {
57
  }
58
 
59
  // get requested path and add a / before it
60
- $requested_path = esc_url_raw( $_SERVER['REQUEST_URI'] );
61
  $requested_path = untrailingslashit( stripslashes( $requested_path ) );
62
 
63
  /**
@@ -151,7 +159,7 @@ class SRM_Redirect {
151
  $redirect_to = preg_replace( '@' . $redirect_from . '@' . $regex_flag, $redirect_to, $requested_path );
152
  }
153
 
154
- $sanitized_redirect_to = esc_url_raw( $redirect_to );
155
 
156
  do_action( 'srm_do_redirect', $requested_path, $sanitized_redirect_to, $status_code );
157
 
@@ -192,4 +200,3 @@ class SRM_Redirect {
192
  }
193
  }
194
 
195
- SRM_Redirect::factory();
17
  * @since 1.8
18
  */
19
  public function setup() {
20
+ /**
21
+ * To only redirect on 404 pages, use:
22
+ * add_filter( 'srm_redirect_only_on_404', '__return_true' );
23
+ */
24
+ if ( apply_filters( 'srm_redirect_only_on_404', false ) ) {
25
+ add_action( 'template_redirect', array( $this, 'maybe_redirect' ), 0 );
26
+ } else {
27
+ add_action( 'parse_request', array( $this, 'maybe_redirect' ), 0 );
28
+ }
29
  }
30
 
31
  /**
52
  */
53
  public function maybe_redirect() {
54
 
55
+ // Don't redirect unless not on admin. If 404 filter enabled, require query is a 404.
56
+ if ( is_admin() || ( apply_filters( 'srm_redirect_only_on_404', false ) && ! is_404() ) ) {
57
  return;
58
  }
59
 
65
  }
66
 
67
  // get requested path and add a / before it
68
+ $requested_path = esc_url_raw( apply_filters( 'srm_requested_path', $_SERVER['REQUEST_URI'] ) );
69
  $requested_path = untrailingslashit( stripslashes( $requested_path ) );
70
 
71
  /**
159
  $redirect_to = preg_replace( '@' . $redirect_from . '@' . $regex_flag, $redirect_to, $requested_path );
160
  }
161
 
162
+ $sanitized_redirect_to = esc_url_raw( apply_filters( 'srm_redirect_to', $redirect_to ) );
163
 
164
  do_action( 'srm_do_redirect', $requested_path, $sanitized_redirect_to, $status_code );
165
 
200
  }
201
  }
202
 
 
inc/classes/class-srm-wp-cli.php CHANGED
@@ -189,12 +189,12 @@ class SRM_WP_CLI extends WP_CLI_Command {
189
  * redirection from and to URLs, regex flag and HTTP redirection code. Here
190
  * is example table:
191
  *
192
- * | source | target | regex | code |
193
- * |----------------------------|--------------------|-------|------|
194
- * | /legacy-url | /new-url | 0 | 301 |
195
- * | /category-1 | /new-category-slug | 0 | 302 |
196
- * | /tes?t/[0-9]+/path/[^/]+/? | /go/here | 1 | 302 |
197
- * | ... | ... | ... | ... |
198
  *
199
  * You can also use exported redirects from "Redirection" plugin, which you
200
  * can download here: /wp-admin/tools.php?page=redirection.php&sub=modules
@@ -211,11 +211,15 @@ class SRM_WP_CLI extends WP_CLI_Command {
211
  * <code-column>
212
  * : Header title for code column mapping.
213
  *
 
 
 
 
214
  * ## EXAMPLE
215
  *
216
  * wp safe-redirect-manager import redirections.csv
217
  *
218
- * @synopsis <file> [--source=<source-column>] [--target=<target-column>] [--regex=<regex-column>] [--code=<code-column>]
219
  *
220
  * @since 1.7.6
221
  *
@@ -248,5 +252,3 @@ class SRM_WP_CLI extends WP_CLI_Command {
248
  WP_CLI::success( "All done! {$created} redirects were imported, {$skipped} were skipped" );
249
  }
250
  }
251
-
252
- WP_CLI::add_command( 'safe-redirect-manager', 'SRM_WP_CLI' );
189
  * redirection from and to URLs, regex flag and HTTP redirection code. Here
190
  * is example table:
191
  *
192
+ * | source | target | regex | code | order |
193
+ * |----------------------------|--------------------|-------|------|-------|
194
+ * | /legacy-url | /new-url | 0 | 301 | 0 |
195
+ * | /category-1 | /new-category-slug | 0 | 302 | 1 |
196
+ * | /tes?t/[0-9]+/path/[^/]+/? | /go/here | 1 | 302 | 3 |
197
+ * | ... | ... | ... | ... | ... |
198
  *
199
  * You can also use exported redirects from "Redirection" plugin, which you
200
  * can download here: /wp-admin/tools.php?page=redirection.php&sub=modules
211
  * <code-column>
212
  * : Header title for code column mapping.
213
  *
214
+ * <order-column>
215
+ * : Header title for order column mapping.
216
+ *
217
+ *
218
  * ## EXAMPLE
219
  *
220
  * wp safe-redirect-manager import redirections.csv
221
  *
222
+ * @synopsis <file> [--source=<source-column>] [--target=<target-column>] [--regex=<regex-column>] [--code=<code-column>] [--order=<order-column>]
223
  *
224
  * @since 1.7.6
225
  *
252
  WP_CLI::success( "All done! {$created} redirects were imported, {$skipped} were skipped" );
253
  }
254
  }
 
 
inc/functions.php CHANGED
@@ -30,6 +30,8 @@ function srm_get_redirects( $args = array(), $hard = false ) {
30
  'post_status' => 'publish',
31
  'paged' => $i,
32
  'fields' => 'ids',
 
 
33
  );
34
 
35
  $query_args = array_merge( $defaults, $args );
@@ -154,11 +156,12 @@ function srm_check_for_possible_redirect_loops() {
154
  * @param int $status_code
155
  * @param bool $enable_regex
156
  * @param string $post_status
 
157
  * @since 1.8
158
  * @uses wp_insert_post, update_post_meta
159
  * @return int|WP_Error
160
  */
161
- function srm_create_redirect( $redirect_from, $redirect_to, $status_code = 302, $enable_regex = false, $post_status = 'publish' ) {
162
  global $wpdb;
163
 
164
  $sanitized_redirect_from = srm_sanitize_redirect_from( $redirect_from );
@@ -166,6 +169,7 @@ function srm_create_redirect( $redirect_from, $redirect_to, $status_code = 302,
166
  $sanitized_status_code = absint( $status_code );
167
  $sanitized_enable_regex = (bool) $enable_regex;
168
  $sanitized_post_status = sanitize_key( $post_status );
 
169
 
170
  // check and make sure no parameters are empty or invalid after sanitation
171
  if ( empty( $sanitized_redirect_from ) || empty( $sanitized_redirect_to ) ) {
@@ -186,6 +190,7 @@ function srm_create_redirect( $redirect_from, $redirect_to, $status_code = 302,
186
  'post_type' => 'redirect_rule',
187
  'post_status' => $sanitized_post_status,
188
  'post_author' => 1,
 
189
  );
190
 
191
  $post_id = wp_insert_post( $post_args );
@@ -318,9 +323,10 @@ function srm_import_file( $file, $args ) {
318
  $redirect_to = srm_sanitize_redirect_to( $rule[ $args['target'] ] );
319
  $status_code = ! empty( $rule[ $args['code'] ] ) ? $rule[ $args['code'] ] : 302;
320
  $regex = ! empty( $rule[ $args['regex'] ] ) ? filter_var( $rule[ $args['regex'] ], FILTER_VALIDATE_BOOLEAN ) : false;
 
321
 
322
  // import
323
- $id = srm_create_redirect( $redirect_from, $redirect_to, $status_code, $regex );
324
 
325
  if ( is_wp_error( $id ) ) {
326
  $doing_wp_cli && WP_CLI::warning( $id );
30
  'post_status' => 'publish',
31
  'paged' => $i,
32
  'fields' => 'ids',
33
+ 'orderby' => 'menu_order ID',
34
+ 'order' => 'ASC',
35
  );
36
 
37
  $query_args = array_merge( $defaults, $args );
156
  * @param int $status_code
157
  * @param bool $enable_regex
158
  * @param string $post_status
159
+ * @param int $menu_order
160
  * @since 1.8
161
  * @uses wp_insert_post, update_post_meta
162
  * @return int|WP_Error
163
  */
164
+ function srm_create_redirect( $redirect_from, $redirect_to, $status_code = 302, $enable_regex = false, $post_status = 'publish', $menu_order = 0 ) {
165
  global $wpdb;
166
 
167
  $sanitized_redirect_from = srm_sanitize_redirect_from( $redirect_from );
169
  $sanitized_status_code = absint( $status_code );
170
  $sanitized_enable_regex = (bool) $enable_regex;
171
  $sanitized_post_status = sanitize_key( $post_status );
172
+ $sanitized_menu_order = absint( $menu_order );
173
 
174
  // check and make sure no parameters are empty or invalid after sanitation
175
  if ( empty( $sanitized_redirect_from ) || empty( $sanitized_redirect_to ) ) {
190
  'post_type' => 'redirect_rule',
191
  'post_status' => $sanitized_post_status,
192
  'post_author' => 1,
193
+ 'menu_order' => $sanitized_menu_order,
194
  );
195
 
196
  $post_id = wp_insert_post( $post_args );
323
  $redirect_to = srm_sanitize_redirect_to( $rule[ $args['target'] ] );
324
  $status_code = ! empty( $rule[ $args['code'] ] ) ? $rule[ $args['code'] ] : 302;
325
  $regex = ! empty( $rule[ $args['regex'] ] ) ? filter_var( $rule[ $args['regex'] ], FILTER_VALIDATE_BOOLEAN ) : false;
326
+ $menu_order = ! empty( $rule[ $args['order'] ] ) ? $rule[ $args['order'] ] : 0;
327
 
328
  // import
329
+ $id = srm_create_redirect( $redirect_from, $redirect_to, $status_code, $regex, 'publish', $menu_order );
330
 
331
  if ( is_wp_error( $id ) ) {
332
  $doing_wp_cli && WP_CLI::warning( $id );
inc/wp-cli.php DELETED
@@ -1,248 +0,0 @@
1
- <?php
2
- /**
3
- * wp-cli integration
4
- */
5
-
6
- WP_CLI::add_command( 'safe-redirect-manager', 'Safe_Redirect_Manager_CLI' );
7
-
8
- class Safe_Redirect_Manager_CLI extends WP_CLI_Command {
9
-
10
-
11
- /**
12
- * List all of the currently configured redirects
13
- *
14
- * @subcommand list
15
- */
16
- public function _list() {
17
- global $safe_redirect_manager;
18
-
19
- $fields = array(
20
- 'ID',
21
- 'redirect_from',
22
- 'redirect_to',
23
- 'status_code',
24
- 'enable_regex',
25
- 'post_status',
26
- );
27
-
28
- $table = new \cli\Table();
29
- $table->setHeaders( $fields );
30
-
31
- $redirects = $safe_redirect_manager->get_redirects( array( 'post_status' => 'any' ) );
32
- foreach( $redirects as $redirect ) {
33
- $line = array();
34
- foreach( $fields as $field ) {
35
- if ( 'enable_regex' == $field )
36
- $line[] = ( $redirect[$field] ) ? 'true' : 'false';
37
- else
38
- $line[] = $redirect[$field];
39
- }
40
- $table->addRow( $line );
41
- }
42
- $table->display();
43
-
44
- WP_CLI::line( "Total of " . count( $redirects ) . " redirects" );
45
- }
46
-
47
- /**
48
- * Create a redirect
49
- *
50
- * @subcommand create
51
- * @synopsis <from> <to> [<status-code>] [<enable-regex>] [<post-status>]
52
- */
53
- public function create( $args ) {
54
- global $safe_redirect_manager;
55
-
56
- $defaults = array(
57
- '',
58
- '',
59
- 302,
60
- false,
61
- 'publish',
62
- );
63
- // array_merge() doesn't work here because our keys are numeric
64
- foreach( $defaults as $key => $value ) {
65
- if ( ! isset( $args[$key] ) )
66
- $args[$key] = $defaults[$key];
67
- }
68
- list( $from, $to, $status_code, $enable_regex, $post_status ) = $args;
69
-
70
- // User might've passed as string.
71
- if ( 'false' == $enable_regex )
72
- $enable_regex = false;
73
-
74
- if ( empty( $from ) || empty( $to ) )
75
- WP_CLI::error( "<from> and <to> are required arguments." );
76
-
77
- $ret = $safe_redirect_manager->create_redirect( $from, $to, $status_code, $enable_regex, $post_status );
78
- if ( is_wp_error( $ret ) )
79
- WP_CLI::error( $ret->get_error_message() );
80
- else
81
- WP_CLI::success( "Created redirect as #{$ret}" );
82
- }
83
-
84
- /**
85
- * Delete a redirect
86
- *
87
- * @subcommand delete
88
- * @synopsis <id>
89
- */
90
- public function delete( $args ) {
91
- global $safe_redirect_manager;
92
-
93
- $id = ( ! empty( $args[0] ) ) ? (int)$args[0] : 0;
94
-
95
- $redirect = get_post( $id );
96
- if ( ! $redirect || $safe_redirect_manager->redirect_post_type != $redirect->post_type )
97
- WP_CLI::error( "{$id} isn't a valid redirect." );
98
-
99
- wp_delete_post( $id );
100
- $safe_redirect_manager->update_redirect_cache();
101
- WP_CLI::success( "Redirect #{$id} has been deleted." );
102
- }
103
-
104
- /**
105
- * Update the redirect cache
106
- *
107
- * @subcommand update-cache
108
- */
109
- public function update_cache() {
110
- global $safe_redirect_manager;
111
-
112
- $safe_redirect_manager->update_redirect_cache();
113
- WP_CLI::success( "Redirect cache has been updated." );
114
- }
115
-
116
- /**
117
- * Import .htaccess file redirects
118
- *
119
- * @subcommand import-htaccess
120
- * @synopsis <file>
121
- */
122
- public function import_htaccess( $args, $assoc_args ) {
123
- global $safe_redirect_manager;
124
-
125
- list( $file ) = $args;
126
-
127
- $contents = file_get_contents( $file );
128
- if ( ! $contents )
129
- WP_CLI::error( "Error retrieving .htaccess file" );
130
-
131
- $pieces = explode( PHP_EOL, $contents );
132
- $created = 0;
133
- $skipped = 0;
134
- foreach( $pieces as $piece ) {
135
-
136
- // Ignore if this line isn't a redirect
137
- if ( ! preg_match( '/^Redirect( permanent)?/i', $piece ) )
138
- continue;
139
-
140
- // Parse the redirect
141
- $redirect = preg_replace( '/\s{2,}/', ' ', $piece );
142
- $redirect = preg_replace( '/^Redirect( permanent)? (.*)$/i', '$2', trim( $redirect ) );
143
- $redirect = explode( ' ', $redirect );
144
-
145
- // if there are three parts to the redirect, we assume the first part is a status code
146
- if ( 2 == count( $redirect ) ) {
147
- $from = $redirect[0];
148
- $to = $redirect[1];
149
- $http_status = 301;
150
- } elseif ( 3 == count( $redirect ) ) {
151
- $http_status = $redirect[0];
152
- $from = $redirect[1];
153
- $to = $redirect[2];
154
- } else {
155
- continue;
156
- }
157
-
158
- // Validate
159
- if ( ! $from || ! $to ) {
160
- WP_CLI::warning( "Skipping - '{$piece}' is formatted improperly." );
161
- continue;
162
- }
163
-
164
- $sanitized_redirect_from = $safe_redirect_manager->sanitize_redirect_from( $from );
165
- $sanitized_redirect_to = $safe_redirect_manager->sanitize_redirect_to( $to );
166
-
167
- $id = $safe_redirect_manager->create_redirect( $sanitized_redirect_from, $sanitized_redirect_to, $http_status );
168
- if ( is_wp_error( $id ) ) {
169
- WP_CLI::warning( "Error - " . $id->get_error_message() );
170
- $skipped++;
171
- } else {
172
- WP_CLI::line( "Success - Created redirect from '{$sanitized_redirect_from}' to '{$sanitized_redirect_to}'" );
173
- $created++;
174
- }
175
- }
176
- WP_CLI::success( "All done! {$created} redirects were created, {$skipped} were skipped" );
177
- }
178
-
179
- /**
180
- * Imports redirects from CSV file.
181
- *
182
- * ## OPTIONS
183
- *
184
- * <file>
185
- * : Path to one or more valid CSV file for import. This file should contain
186
- * redirection from and to URLs, regex flag and HTTP redirection code. Here
187
- * is example table:
188
- *
189
- * | source | target | regex | code |
190
- * |----------------------------|--------------------|-------|------|
191
- * | /legacy-url | /new-url | 0 | 301 |
192
- * | /category-1 | /new-category-slug | 0 | 302 |
193
- * | /tes?t/[0-9]+/path/[^/]+/? | /go/here | 1 | 302 |
194
- * | ... | ... | ... | ... |
195
- *
196
- * You can also use exported redirects from "Redirection" plugin, which you
197
- * can download here: /wp-admin/tools.php?page=redirection.php&sub=modules
198
- *
199
- * <source-column>
200
- * : Header title for sources column mapping.
201
- *
202
- * <target-column>
203
- * : Header title for target column mapping.
204
- *
205
- * <regex-column>
206
- * : Header title for regex column mapping.
207
- *
208
- * <code-column>
209
- * : Header title for code column mapping.
210
- *
211
- * ## EXAMPLE
212
- *
213
- * wp safe-redirect-manager import redirections.csv
214
- *
215
- * @synopsis <file> [--source=<source-column>] [--target=<target-column>] [--regex=<regex-column>] [--code=<code-column>]
216
- *
217
- * @since 1.7.6
218
- *
219
- * @access public
220
- * @global SRM_Safe_Redirect_Manager $safe_redirect_manager The plugin instance.
221
- * @param array $args The array of input files.
222
- * @param array $assoc_args The array of column mappings.
223
- */
224
- public function import( $args, $assoc_args ) {
225
- global $safe_redirect_manager;
226
-
227
- $mapping = wp_parse_args( $assoc_args, array(
228
- 'source' => 'source',
229
- 'target' => 'target',
230
- 'regex' => 'regex',
231
- 'code' => 'code',
232
- ) );
233
-
234
- $created = $skipped = 0;
235
- foreach ( $args as $file ) {
236
- $processed = $safe_redirect_manager->import_file( $file, $mapping );
237
- if ( ! empty( $processed ) ) {
238
- $created += $processed['created'];
239
- $skipped += $processed['skipped'];
240
-
241
- WP_CLI::success( basename( $file ) . ' file processed successfully.' );
242
- }
243
- }
244
-
245
- WP_CLI::success( "All done! {$created} redirects were imported, {$skipped} were skipped" );
246
- }
247
-
248
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lang/safe-redirect-manager.pot CHANGED
@@ -1,18 +1,18 @@
1
- # Copyright (C) 2017 Taylor Lovett (10up)
2
  # This file is distributed under the GPLv2 or later.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Safe Redirect Manager 1.8\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/safe-redirect-manager\n"
8
- "POT-Creation-Date: 2017-12-08 06:00:17+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "X-Generator: node-wp-i18n 1.0.4\n"
16
 
17
  #: inc/classes/class-srm-post-type.php:19
18
  msgid "Moved Permanently"
@@ -38,74 +38,78 @@ msgstr ""
38
  msgid "Not Found"
39
  msgstr ""
40
 
41
- #: inc/classes/class-srm-post-type.php:234
42
  msgid ""
43
  "Safe Redirect Manager Warning: Possible redirect loops and/or chains have "
44
  "been created."
45
  msgstr ""
46
 
47
- #: inc/classes/class-srm-post-type.php:245
48
  msgid ""
49
  "Safe Redirect Manager Error: You have reached the maximum allowable number "
50
  "of redirects"
51
  msgstr ""
52
 
53
- #: inc/classes/class-srm-post-type.php:296
54
- #: inc/classes/class-srm-post-type.php:299
55
  msgid "Redirect rule updated."
56
  msgstr ""
57
 
58
- #: inc/classes/class-srm-post-type.php:297
59
  msgid "Custom field updated."
60
  msgstr ""
61
 
62
- #: inc/classes/class-srm-post-type.php:298
63
  msgid "Custom field deleted."
64
  msgstr ""
65
 
66
- #: inc/classes/class-srm-post-type.php:301
67
  #. translators: %s: date and time of the revision
68
  msgid "Redirect rule restored to revision from %s"
69
  msgstr ""
70
 
71
- #: inc/classes/class-srm-post-type.php:302
72
  msgid "Redirect rule published."
73
  msgstr ""
74
 
75
- #: inc/classes/class-srm-post-type.php:303
76
  msgid "Redirect rule saved."
77
  msgstr ""
78
 
79
- #: inc/classes/class-srm-post-type.php:304
80
  msgid "Redirect rule submitted."
81
  msgstr ""
82
 
83
- #: inc/classes/class-srm-post-type.php:306
84
  msgid "Redirect rule scheduled for: %1$s."
85
  msgstr ""
86
 
87
- #: inc/classes/class-srm-post-type.php:308
88
  #. translators: Publish box date format, see http:php.net/date
89
  msgid "M j, Y @ G:i"
90
  msgstr ""
91
 
92
- #: inc/classes/class-srm-post-type.php:310
93
  msgid "Redirect rule draft updated."
94
  msgstr ""
95
 
96
- #: inc/classes/class-srm-post-type.php:361
97
  msgid "Redirect To"
98
  msgstr ""
99
 
100
- #: inc/classes/class-srm-post-type.php:362
101
  msgid "HTTP Status Code"
102
  msgstr ""
103
 
104
- #: inc/classes/class-srm-post-type.php:365
 
 
 
 
105
  msgid "Redirect From"
106
  msgstr ""
107
 
108
- #: inc/classes/class-srm-post-type.php:369
109
  msgid "Date"
110
  msgstr ""
111
 
@@ -113,43 +117,43 @@ msgstr ""
113
  msgid "Safe Redirect Manager"
114
  msgstr ""
115
 
116
- #: inc/classes/class-srm-post-type.php:438
117
  msgid "Edit Redirect Rule"
118
  msgstr ""
119
 
120
- #: inc/classes/class-srm-post-type.php:439
121
  msgid "New Redirect Rule"
122
  msgstr ""
123
 
124
- #: inc/classes/class-srm-post-type.php:441
125
  msgid "View Redirect Rule"
126
  msgstr ""
127
 
128
- #: inc/classes/class-srm-post-type.php:442
129
  msgid "Search Redirects"
130
  msgstr ""
131
 
132
- #: inc/classes/class-srm-post-type.php:443
133
  msgid "No redirect rules found."
134
  msgstr ""
135
 
136
- #: inc/classes/class-srm-post-type.php:444
137
  msgid "No redirect rules found in trash."
138
  msgstr ""
139
 
140
- #: inc/classes/class-srm-post-type.php:488
141
  msgid "Redirect Settings"
142
  msgstr ""
143
 
144
- #: inc/classes/class-srm-post-type.php:512
145
- msgid "Redirect From:"
146
  msgstr ""
147
 
148
- #: inc/classes/class-srm-post-type.php:515
149
  msgid "Enable Regular Expressions (advanced)"
150
  msgstr ""
151
 
152
- #: inc/classes/class-srm-post-type.php:517
153
  msgid ""
154
  "This path should be relative to the root of this WordPress installation (or "
155
  "the sub-site, if you are running a multi-site). Appending a (*) wildcard "
@@ -158,38 +162,46 @@ msgid ""
158
  "symbol is interpretted."
159
  msgstr ""
160
 
161
- #: inc/classes/class-srm-post-type.php:520
162
- msgid "Redirect To:"
163
  msgstr ""
164
 
165
- #: inc/classes/class-srm-post-type.php:523
166
  msgid ""
167
  "This can be a URL or a path relative to the root of your website (not your "
168
  "WordPress installation). Ending with a (*) wildcard character will append "
169
  "the request match to the redirect."
170
  msgstr ""
171
 
172
- #: inc/classes/class-srm-post-type.php:526
173
- msgid "HTTP Status Code:"
174
  msgstr ""
175
 
176
- #: inc/classes/class-srm-post-type.php:532
177
  msgid "If you don't know what this is, leave it as is."
178
  msgstr ""
179
 
180
- #: inc/functions.php:172
181
- msgid "Redirect from and/or redirect to arguments are invalid."
 
 
 
 
182
  msgstr ""
183
 
184
  #: inc/functions.php:176
 
 
 
 
185
  msgid "Invalid status code."
186
  msgstr ""
187
 
188
- #: inc/functions.php:181
189
  msgid "Redirect already exists for %s"
190
  msgstr ""
191
 
192
- #: inc/functions.php:194
193
  msgid "An error occurred creating the redirect."
194
  msgstr ""
195
 
@@ -202,20 +214,20 @@ msgid "Easily and safely manage HTTP redirects."
202
  msgstr ""
203
 
204
  #. Author of the plugin/theme
205
- msgid "Taylor Lovett (10up)"
206
  msgstr ""
207
 
208
- #: inc/classes/class-srm-post-type.php:434
209
  msgctxt "post type general name"
210
  msgid "Safe Redirect Manager"
211
  msgstr ""
212
 
213
- #: inc/classes/class-srm-post-type.php:435
214
  msgctxt "post type singular name"
215
  msgid "Redirect"
216
  msgstr ""
217
 
218
- #: inc/classes/class-srm-post-type.php:436
219
  msgctxt "redirect rule"
220
  msgid "Create Redirect Rule"
221
  msgstr ""
1
+ # Copyright (C) 2018 10up
2
  # This file is distributed under the GPLv2 or later.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Safe Redirect Manager 1.9\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/safe-redirect-manager\n"
8
+ "POT-Creation-Date: 2018-04-04 03:26:38+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "X-Generator: node-wp-i18n 1.0.5\n"
16
 
17
  #: inc/classes/class-srm-post-type.php:19
18
  msgid "Moved Permanently"
38
  msgid "Not Found"
39
  msgstr ""
40
 
41
+ #: inc/classes/class-srm-post-type.php:258
42
  msgid ""
43
  "Safe Redirect Manager Warning: Possible redirect loops and/or chains have "
44
  "been created."
45
  msgstr ""
46
 
47
+ #: inc/classes/class-srm-post-type.php:270
48
  msgid ""
49
  "Safe Redirect Manager Error: You have reached the maximum allowable number "
50
  "of redirects"
51
  msgstr ""
52
 
53
+ #: inc/classes/class-srm-post-type.php:321
54
+ #: inc/classes/class-srm-post-type.php:324
55
  msgid "Redirect rule updated."
56
  msgstr ""
57
 
58
+ #: inc/classes/class-srm-post-type.php:322
59
  msgid "Custom field updated."
60
  msgstr ""
61
 
62
+ #: inc/classes/class-srm-post-type.php:323
63
  msgid "Custom field deleted."
64
  msgstr ""
65
 
66
+ #: inc/classes/class-srm-post-type.php:326
67
  #. translators: %s: date and time of the revision
68
  msgid "Redirect rule restored to revision from %s"
69
  msgstr ""
70
 
71
+ #: inc/classes/class-srm-post-type.php:327
72
  msgid "Redirect rule published."
73
  msgstr ""
74
 
75
+ #: inc/classes/class-srm-post-type.php:328
76
  msgid "Redirect rule saved."
77
  msgstr ""
78
 
79
+ #: inc/classes/class-srm-post-type.php:329
80
  msgid "Redirect rule submitted."
81
  msgstr ""
82
 
83
+ #: inc/classes/class-srm-post-type.php:331
84
  msgid "Redirect rule scheduled for: %1$s."
85
  msgstr ""
86
 
87
+ #: inc/classes/class-srm-post-type.php:333
88
  #. translators: Publish box date format, see http:php.net/date
89
  msgid "M j, Y @ G:i"
90
  msgstr ""
91
 
92
+ #: inc/classes/class-srm-post-type.php:335
93
  msgid "Redirect rule draft updated."
94
  msgstr ""
95
 
96
+ #: inc/classes/class-srm-post-type.php:389
97
  msgid "Redirect To"
98
  msgstr ""
99
 
100
+ #: inc/classes/class-srm-post-type.php:390
101
  msgid "HTTP Status Code"
102
  msgstr ""
103
 
104
+ #: inc/classes/class-srm-post-type.php:391
105
+ msgid "Order"
106
+ msgstr ""
107
+
108
+ #: inc/classes/class-srm-post-type.php:394
109
  msgid "Redirect From"
110
  msgstr ""
111
 
112
+ #: inc/classes/class-srm-post-type.php:398
113
  msgid "Date"
114
  msgstr ""
115
 
117
  msgid "Safe Redirect Manager"
118
  msgstr ""
119
 
120
+ #: inc/classes/class-srm-post-type.php:485
121
  msgid "Edit Redirect Rule"
122
  msgstr ""
123
 
124
+ #: inc/classes/class-srm-post-type.php:486
125
  msgid "New Redirect Rule"
126
  msgstr ""
127
 
128
+ #: inc/classes/class-srm-post-type.php:488
129
  msgid "View Redirect Rule"
130
  msgstr ""
131
 
132
+ #: inc/classes/class-srm-post-type.php:489
133
  msgid "Search Redirects"
134
  msgstr ""
135
 
136
+ #: inc/classes/class-srm-post-type.php:490
137
  msgid "No redirect rules found."
138
  msgstr ""
139
 
140
+ #: inc/classes/class-srm-post-type.php:491
141
  msgid "No redirect rules found in trash."
142
  msgstr ""
143
 
144
+ #: inc/classes/class-srm-post-type.php:550
145
  msgid "Redirect Settings"
146
  msgstr ""
147
 
148
+ #: inc/classes/class-srm-post-type.php:575
149
+ msgid "* Redirect From:"
150
  msgstr ""
151
 
152
+ #: inc/classes/class-srm-post-type.php:578
153
  msgid "Enable Regular Expressions (advanced)"
154
  msgstr ""
155
 
156
+ #: inc/classes/class-srm-post-type.php:580
157
  msgid ""
158
  "This path should be relative to the root of this WordPress installation (or "
159
  "the sub-site, if you are running a multi-site). Appending a (*) wildcard "
162
  "symbol is interpretted."
163
  msgstr ""
164
 
165
+ #: inc/classes/class-srm-post-type.php:583
166
+ msgid "* Redirect To:"
167
  msgstr ""
168
 
169
+ #: inc/classes/class-srm-post-type.php:586
170
  msgid ""
171
  "This can be a URL or a path relative to the root of your website (not your "
172
  "WordPress installation). Ending with a (*) wildcard character will append "
173
  "the request match to the redirect."
174
  msgstr ""
175
 
176
+ #: inc/classes/class-srm-post-type.php:589
177
+ msgid "* HTTP Status Code:"
178
  msgstr ""
179
 
180
+ #: inc/classes/class-srm-post-type.php:595
181
  msgid "If you don't know what this is, leave it as is."
182
  msgstr ""
183
 
184
+ #: inc/classes/class-srm-post-type.php:599
185
+ msgid "Notes:"
186
+ msgstr ""
187
+
188
+ #: inc/classes/class-srm-post-type.php:601
189
+ msgid "Optionally leave notes on this redirect e.g. why was it created."
190
  msgstr ""
191
 
192
  #: inc/functions.php:176
193
+ msgid "Redirect from and/or redirect to arguments are invalid."
194
+ msgstr ""
195
+
196
+ #: inc/functions.php:180
197
  msgid "Invalid status code."
198
  msgstr ""
199
 
200
+ #: inc/functions.php:185
201
  msgid "Redirect already exists for %s"
202
  msgstr ""
203
 
204
+ #: inc/functions.php:199
205
  msgid "An error occurred creating the redirect."
206
  msgstr ""
207
 
214
  msgstr ""
215
 
216
  #. Author of the plugin/theme
217
+ msgid "10up"
218
  msgstr ""
219
 
220
+ #: inc/classes/class-srm-post-type.php:481
221
  msgctxt "post type general name"
222
  msgid "Safe Redirect Manager"
223
  msgstr ""
224
 
225
+ #: inc/classes/class-srm-post-type.php:482
226
  msgctxt "post type singular name"
227
  msgid "Redirect"
228
  msgstr ""
229
 
230
+ #: inc/classes/class-srm-post-type.php:483
231
  msgctxt "redirect rule"
232
  msgid "Create Redirect Rule"
233
  msgstr ""
readme.txt CHANGED
@@ -11,7 +11,7 @@ Safely and easily manage your website's HTTP redirects.
11
 
12
  Safe Redirect Manager is a HTTP redirect manager for WordPress. An easy-to-use UI allows you to redirect locations to new URL's with the HTTP status codes of your choosing. This plugin works great with multisite.
13
 
14
- [Fork the plugin on GitHub.](https://github.com/tlovett1/safe-redirect-manager)
15
 
16
  == Installation ==
17
 
@@ -19,6 +19,13 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc
19
 
20
  == Changelog ==
21
 
 
 
 
 
 
 
 
22
  = 1.8 =
23
  * Improved escaping
24
  * Custom redirect capability
11
 
12
  Safe Redirect Manager is a HTTP redirect manager for WordPress. An easy-to-use UI allows you to redirect locations to new URL's with the HTTP status codes of your choosing. This plugin works great with multisite.
13
 
14
+ [Fork the plugin on GitHub.](https://github.com/10up/safe-redirect-manager)
15
 
16
  == Installation ==
17
 
19
 
20
  == Changelog ==
21
 
22
+ = 1.9 =
23
+ * Add redirect notes feature.
24
+ * Fix PHP 7.2 errors
25
+ * Instantiate classes in main file instead of individual files for improved testability.
26
+ * Add filters for request path and redirect path
27
+ * Add filter to only apply redirects on 404
28
+
29
  = 1.8 =
30
  * Improved escaping
31
  * Custom redirect capability
safe-redirect-manager.php CHANGED
@@ -3,8 +3,8 @@
3
  * Plugin Name: Safe Redirect Manager
4
  * Plugin URI: https://10up.com
5
  * Description: Easily and safely manage HTTP redirects.
6
- * Author: Taylor Lovett (10up)
7
- * Version: 1.8
8
  * Text Domain: safe-redirect-manager
9
  * Domain Path: /lang/
10
  * Author URI: https://10up.com
@@ -29,4 +29,8 @@ require_once( dirname( __FILE__ ) . '/inc/classes/class-srm-redirect.php' );
29
 
30
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
31
  require_once( dirname( __FILE__ ) . '/inc/classes/class-srm-wp-cli.php' );
 
32
  }
 
 
 
3
  * Plugin Name: Safe Redirect Manager
4
  * Plugin URI: https://10up.com
5
  * Description: Easily and safely manage HTTP redirects.
6
+ * Author: 10up
7
+ * Version: 1.9
8
  * Text Domain: safe-redirect-manager
9
  * Domain Path: /lang/
10
  * Author URI: https://10up.com
29
 
30
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
31
  require_once( dirname( __FILE__ ) . '/inc/classes/class-srm-wp-cli.php' );
32
+ WP_CLI::add_command( 'safe-redirect-manager', 'SRM_WP_CLI' );
33
  }
34
+
35
+ SRM_Post_Type::factory();
36
+ SRM_Redirect::factory();