A common requirement for business sites is to have a client login which allow visitors to access private content for them (ie: downloads, screenshots, documents).
I did it in the past and although it worked, I think is a bit messy.
Now I need the same functionality in a new site, and want to know if anyone did it and want to share a nice way to achieve this.
My method was something like:
- Create a custom post type for the private content
- Create a custom taxonomy for Clients
- Hook
user_register
and add a Client (taxonomy) every time a new user is created - Hook
template_redirect
and check if it’s a single of my custom post type. If it is, check if the logged_in user is in the custom taxonomy for that post. If it is, cool. If not,header('HTTP/1.1 401 Unauthorized');exit;
Any comments?
Sound like a nice idea, but when i need a per user customized private section i usually code it based on page template files and create a few pages with these template files fo example, say i have a download page which will show each user the files he can download so my page template would
first check if the user is logged in (if not Unauthorized redirect)
then just pull all of the file that user can download.