Skip to content

Instantly share code, notes, and snippets.

@WerdsWords
Created July 22, 2013 05:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WerdsWords/6051555 to your computer and use it in GitHub Desktop.
Save WerdsWords/6051555 to your computer and use it in GitHub Desktop.
#13: author_rewrite_rules bonus functions
<?php
/**
* Add 'redirect' query var
*
* @see WP::parse_request()
*
* @param array $query_vars The query vars array.
*
* @return array The filtered query vars array.
*/
function wpdocs_add_redirect_var( $query_vars ) {
$query_vars[] = 'redirect';
return $query_vars;
}
add_filter( 'query_vars', 'wpdocs_add_redirect_var' );
/**
* Redirect old 'author' links
*
* @see WP::parse_request()
*
* @param object $request The request object.
*
* @return object The request object.
*/
function wpdocs_redirect_old_author_links( $request ) {
if ( isset( $request->public_query_vars['redirect'] )
&& $request->public_query_vars['redirect']
&& isset( $request->public_query_vars['author_name'] ) ) {
wp_redirect( get_author_posts_url( 0, $request->public_query_vars['author_name'] ) );
exit;
}
return $request;
}
add_action( 'parse_request', 'wpdocs_redirect_old_author_links' );
@WerdsWords
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment