Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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

This comment has been minimized.

Copy link
Owner Author

@WerdsWords WerdsWords commented Jul 22, 2013

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