I have a site that displays the content only to registered users.
Most of the content is available to all the users, but some of it is user specific (i.e. all users have that page, but each sees a it’s own content which no one else can see).
Any idea as to how I can restrict(and display) specific content per specific user ?
Leave a Reply
You must be logged in to post a comment.
I had coded something like this a while back and i remember wanting to upload it to the plugin repository but never had the time, Basically it adds a meta box to the post or page edit screen and lets the user select specific users by name or roles and then it check using
the_content
filter, so here you go:Update:
It just got approved in to WordPress plugin repository so you can download it User specific content form there or from your dashboard and i wrote a little about it here.
Assuming this content is the usual post loop:
I think this only works inside the loop.
If you need it outside the loop then just query posts from
$current_user->ID
:In addidtion to what One Trick Pony wrote, if the site owner needs the ability to restrict the content to each user, you can develop a small custom meta box that will appear inside each post and will display checkboxes with the site’s users and then you will have in your dayabse the needed post_meta of the users that have permission to the content and you could make the condition.
If you need another way of controlling the content, it’s better you provide some more specific details on how this should and needed to be handled, so it will be easier to think for appropriate solutions…
Good luck 🙂
1st approach:
2nd approach:
You can also use 2nd approach with 1st for additional security though its optional.