Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

At the moment I have the following code for changing the author_base slug.

/** ADD REWRITE RULES **/
function change_author_permalinks() {
   global $wp_rewrite;

   $wp_rewrite->author_base = 'profile';
   $wp_rewrite->flush_rules();
}
add_action('init','change_author_permalinks');

How can I add, for example, a extra "edit" page on to this, i.e., /profile/my-user-name/edit ???

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The author rewrite rules are filtered through author_rewrite_rules. You can add a rule there for the pattern author/([^/]+)/edit/?$, but the substitution will depend on how you want to create the edit page. A simple example that will set a custom query variable and load a specific template if this variable is set:

add_action( 'author_rewrite_rules', 'wpse18547_author_rewrite_rules' );
function wpse18547_author_rewrite_rules( $author_rules )
{
    $author_rules['author/([^/]+)/edit/?$'] = 'index.php?author_name=$matches[1]&wpse18547_author_edit=1';
    return $author_rules;
}

add_filter( 'query_vars', 'wpse18547_query_vars' );
function wpse18547_query_vars( $query_vars )
{
    $query_vars[] = 'wpse18547_author_edit';
    return $query_vars;
}

add_filter( 'author_template', 'wpse18547_author_template' );
function wpse18547_author_template( $author_template )
{
    if ( get_query_var( 'wpse18547_author_edit' ) ) {
        return locate_template( array( 'edit-author.php', $author_template ) );
    }
    return $author_template;
}

Small tip: Don't call flush_rules() on every init, it's an expensive operation. You only need to do it when the rewrite rules change. You can manually flush the rules by just visiting the Permalinks settings page. And if you are going to play with the rewrite rules, I recommend you install my Rewrite analyzer plugin.

share|improve this answer
    
Basically I'm going to create the page by reading the slug (that is - I'm NOT going to create a extra page and call a template file). The page itself is for subscribers to update their personal info and only they have access to it. –  EddyR May 28 '11 at 10:18
    
@EddyR: I updated my answer with some code that will load a specific template file, but you can of course do whatever you want when you detect the extra query variable. –  Jan Fabry May 28 '11 at 10:36
    
hmmm, that seems to almost be working. I'm having a problem with get_query_var() it doesn't return anything. Do you know what would be causing that? –  EddyR May 28 '11 at 12:34
    
@EddyR: Do you have a custom query somewhere? query_posts()? That would override the global $wp_query variable, which is where get_query_var() looks. –  Jan Fabry May 28 '11 at 13:47
    
Ahhh, perfect, thank you very much. I found my mistake this morning - I just forgot to change 'author/([^/]+)/edit/?$' to 'profile/([^/]+)/edit/?$' –  EddyR May 29 '11 at 4:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.