我在wordpress中有自定义作者模板:mysite.com/author/john/我希望限制对此页面的访问,因此只有john在登录时才能访问此页面而不是其他用户是否登录。
有人可以帮我这个吗?
答案 0 :(得分:0)
尝试以下代码..
$logged_in_user_id = 0;
// get author info
$user_info = get_userdata($post->post_author);
$author_id = $user_info->ID;
// get logged in user info
$user_logged_in = is_user_logged_in();
$user_data = array();
if($user_logged_in){
global $current_user;
get_currentuserinfo();
$logged_in_user_id = $current_user->ID;
}
// check the logged in user id is same as author id
if($logged_in_user_id == $author_id ){
// Show blog information...
}else{
// Show blog access denied message
}