Restrict access by logged in author

Add this to your functions file:

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

Then you can use this in your templates:

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

Revisions

There are no revisions for this post.

No comments yet.

Leave a Reply