【问题标题】:Restrict other users to access author page wordpress限制其他用户访问作者页面 wordpress
【发布时间】:2012-07-01 16:08:07
【问题描述】:

我在 wordpress 中有自定义作者模板:mysite.com/author/john/ 并且我想限制对此页面的访问,因此只有 john 在登录时才能访问此页面,而其他用户无论是否登录都不能访问。

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: wordpress limit restrict author


    【解决方案1】:

    试试下面的代码..

    $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
    }
    

    【讨论】:

    • 这个要直接加到author.php文件吗?我也对此感兴趣,因为它与我需要做的完全一样。
    猜你喜欢
    • 2012-09-14
    • 2014-08-11
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    相关资源
    最近更新 更多