admin管理员组文章数量:1418335
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' );
本文标签:
版权声明:本文标题:rewrite rules - get_author_posts_url() doesn't return the author URL, because of wrong author_structure 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745287858a2651607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论