在模板中,如果用户是超级管理员,或者用户具有某些功能,则可以执行条件检查(如果您希望以管理员为目标,而不仅仅是超级管理员)
First case
if (is_super_admin() ) {
//your super admin logic here
}else{
//subscriber logic
}
Second case
if ( current_user_can( \'manage_options\' ) ) {
//your admin logic here
} else {
//subscriber logic
}
http://codex.wordpress.org/Function_Reference/is_super_admin
http://codex.wordpress.org/Function_Reference/current_user_can
在此,您还可以使用此功能检查用户角色
http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/
UPDATE
根据op问题更新
if(is_user_logged_in()){
if ( current_user_can( \'manage_options\' ) ) {
//your admin logic here
} else {
$current_user = wp_get_current_user();
$curauth = (get_query_var(\'author_name\')) ? get_user_by(\'slug\', get_query_var(\'author_name\')) : get_userdata(get_query_var(\'author\'));
if($current_user->user_login == $curauth->user_login){
// User is the same as author, show the panel
}else{
//different user and author, access forbidden.
}
}
}else{
echo \'Access forbidden\';
}