I have the following code to modify the author base on WP:
add_action('init', 'modify_author_slug');
function modify_author_slug() {
global $wp_rewrite;
$wp_rewrite->author_base = 'user';
$wp_rewrite->author_structure = '/' . $wp_rewrite->author_base . '/%author%';
}
add_filter('query_vars', 'user_query_vars');
function user_query_vars($vars) {
$new_vars = array('user');
$vars = $new_vars + $vars;
return $vars;
}
function user_rewrite_rules( $wp_rewrite ) {
$newrules = array();
$new_rules['user/(\d*)$'] = 'index.php?author=$matches[1]';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules','user_rewrite_rules');
The profile works great when I go to mysite/user/whatever. But, when using the get_author_posts_url(get_current_user_id())
function it returns mysite/author/whatever
I saved the permalink structure multiple times, flushed cache and tried using other browsers. Always happens the same.
Any idea?
EDIT
I am using the following function as I can not redirect with the get_author_posts_url(), it is still the problem, but the below code gives more context and can be used as a workaround.
// Remove access to administration to users
function blockusers_init() {
if ( is_admin() && !current_user_can('administrator') && !( defined('DOING_AJAX') && DOING_AJAX ) ) {
$url = home_url() . '/user/' . get_the_author_meta( 'user_nicename', get_current_user_id() );
wp_redirect($url);
exit;
}
}
add_action( 'init', 'blockusers_init' );