Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Any ideas to restrict viewing of posts to post author only? The twist: Restrict both back AND frontend. I'd like to avoid the role scoper plugin.

Example: The author creates a post, and can now view live on the site, as well as in the admin panel. They can edit, trash, whatever. But only admins and the author can see the post. (Looking for task/project/helpdesk/use.

share|improve this question

1 Answer 1

to restrict on the back-end you can use the default author role.

and on the front-end you ca use something like:

function check_rights_8876(){
    global $post,$current_user;
    $author_id=$post->post_author;
    get_currentuserinfo();
    if ( is_user_logged_in() ) {
        if ( current_user_can('manage_options') ){// admin
            return true;
        }
        if ($author_id = $current_user->ID ){// curent post author
            return true;
        }
    }
    return false;
}

Once you have this function defined you can check before displaying the post like this:

if (check_rights_8876()){
    //display the post
}
else{
    //Sorry but you don't have rights to access this post massage here
}

Hope this helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.