Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature/create permalinks #39

Merged
merged 6 commits into from

3 participants

@simonwheatley

See tlovett1/Safe-Redirect-Manager#30

This pull request implements a permalink creation for the "from" URL for simple redirects, so that static page caching plugins will be triggered to clear their caches.

Note that regex redirects cannot have permalinks created for them.

@danielbachhuber

Will this manifest itself in the UI anywhere?

@simonwheatley

I don't think this needs to be visible in the UI, but I'm happy for someone to argue the other side if there's a good case I'm not seeing.

@tlovett1
Owner

This shouldn't manifest itself anywhere in the UI. It is my understanding that this is only affecting the permalink of the redirect post type. We aren't using the permalink anywhere.

@tlovett1 tlovett1 merged commit e8b347e into tlovett1:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 13, 2012
  1. @simonwheatley

    Any single quotes, at least, in `$_SERVER['REQUEST_URI']` are slashed…

    simonwheatley authored
    …, unlash them before matching
    
    This means you can redirect from a URL like http://example.com/because-he's-worth-it/ to the WordPress escaped version which would be http://example.com/because-he%27s-worth-it/
  2. @simonwheatley
Commits on Apr 4, 2013
  1. Merge branch 'master' of https://github.com/tlovett1/Safe-Redirect-Ma…

    Simon Wheatley authored
    …nager
    
    Conflicts:
    	safe-redirect-manager.php
  2. @simonwheatley

    Implement a permalink equivalent to the "from" URL where possible

    simonwheatley authored Simon Wheatley committed
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +21 −0 safe-redirect-manager.php
View
21 safe-redirect-manager.php
@@ -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' ) );
@@ -888,6 +889,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;
Something went wrong with that request. Please try again.