Permalink
Browse files

Merge pull request #39 from simonwheatley/feature/create-permalinks

Merge in feature/create-permalinks which returns redirect_from on get_permalink
  • Loading branch information...
2 parents 9e0c0a1 + f31b563 commit e8b347eaf2d5e6fa24bbae76e881191ea096254a @tlovett1 committed Apr 6, 2013
Showing with 21 additions and 0 deletions.
  1. +21 −0 safe-redirect-manager.php
View
@@ -69,6 +69,7 @@ public function __construct() {
add_action( 'admin_print_styles-edit.php', array( $this, 'action_print_logo_css' ), 10, 1 );
add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
add_action( 'admin_print_styles-post-new.php', array( $this, 'action_print_logo_css' ), 10, 1 );
+ add_filter( 'post_type_link', array( $this, 'filter_post_type_link' ), 10, 2 );
// Search filters
add_filter( 'posts_join', array( $this, 'filter_search_join' ) );
@@ -893,6 +894,26 @@ public function sanitize_redirect_from( $path, $allow_regex = false ) {
return $path;
}
+
+ /**
+ * Return a permalink for a redirect post, which is the "redirect from"
+ * URL for that redirect.
+ *
+ * @param string $permalink The permalink
+ * @param object $post A Post object
+ * @return string The permalink
+ */
+ public function filter_post_type_link( $permalink, $post ) {
+ if ( 'redirect_rule' != $post->post_type )
+ return $permalink;
+ // We can't do anything to provide a permalink
+ // for regex enabled redirects.
+ if ( get_post_meta( $post->ID, $this->meta_key_enable_redirect_from_regex, true ) )
+ return $permalink;
+ // Provide a permalink for the simple redirects
+ $redirect_from = get_post_meta( $post->ID, $this->meta_key_redirect_from, true );
+ return home_url( $redirect_from );
+ }
}
global $safe_redirect_manager;

0 comments on commit e8b347e

Please sign in to comment.