我需要类似的东西,所以我给同一个作者添加了重写规则。php文件,我在其中添加了一个基于用户角色的重定向,以便将其放在您的用例中:
首先将编辑器重定向到主题作者。通过添加此重写规则创建php文件
function my_rewrite_rules_098( $wp_rewrite ) {
$newrules = array();
$new_rules[\'editor/(\\d*)$\'] = \'index.php?author_name=$matches[1]\';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter(\'generate_rewrite_rules\',\'my_rewrite_rules_098\');
接下来创建一个函数来检查用户角色,比如在函数中。php文件:
function user_has_role( $roles_to_check = array(), $user_id ) {
if( ! $roles_to_check ) return FALSE;
if( ! $user_id ) return FALSE;
$user = new WP_User( $user_id ); // $user->roles
return in_array( $roles_to_check, $user->roles, FALSE );
}
然后是你的作者。顶部的php主题文件添加以下内容:
if(isset($_GET[\'author_name\'])) {
$curauth = get_userdatabylogin($author_name);
}else{
$curauth = get_userdata(intval($author));
}
//check user role
$user_role_exists = user_has_role( array(\'Author\'),$curauth->ID; );
if ($user_role_exists && isset(get_query_var(\'editor\'))){
//either rediret to a different editor.php template file
//or include it here something like:
include(\'editor.php\');
exit;
}
希望这有帮助