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.

I've created a taxonomy (let's call it tax). I need to limit what a user can see. The users can't edit anything, just read the blog. If it was just setting what they could see once, I'd probably just create a new user role, but what they will be viewing will change frequently.

So for an example:

   user1 can view tax1, tax4
   user2 can view tax3
   user3 can view tax1, tax2

Then next week that all changes (kinda like checking out a movie or a book then returning it).

How can a make sure that the users can't view any other taxonomies than the ones they're assigned?

I'm hoping there is a function that I just haven't found that is something like:

if(!get_taxonomy(ID)){
    echo "You're not permitted to view this";
}else{
    //Continue with showing page...
}



I already have things set up so that in their user profiles I can assign them their taxonomies. So on the frontend when the page pulls up I can check which taxonomies they can see. But they can still navigate to other taxonomies. If they see that they're on http://website/tax1/ then they could just type in http://website/tax2/ and see the other taxonomies.

This has to be done on an individual user basis and not assigned to a role since there will be so many different users and so many different taxonomies.

Sorry I can't provide a live example; it's being developed locally and it contains some sensitive info.

If I need to clarify anything I'm more than happy to.

Thanks for the help!

share|improve this question
    
How are you storing what users can view what taxonomies? Usermeta? –  m0r7if3r Jan 28 '12 at 23:35
    
Yes, through usermeta. –  john Jan 29 '12 at 0:01

1 Answer 1

up vote 1 down vote accepted

How about something like if( in_array( $current_tax, get_user_meta( $user, 'legal_taxonomies', true ) ) ) You can get the current taxonomy information using get_term_by(). This operates on the assumption that you're storing the available taxonomies as an array, but is easily changed for any storage method.

share|improve this answer
    
Dude! You are my hero! I've been battling this for hours. I had to modify things just a bit to get it working, but it's your answer that got me going down the correct path. Here's what I went with: $slug = $wp_query->query_vars['taxonomy']; $value = get_term_by('slug', $slug, 'taxonomy')->term_id; $a_terr = get_user_meta( $user, 'user-meta', true ); and then the check: if(!in_array($value,$a_terr)){//kick them out<br/>}else{}. Again, thank you! –  john Jan 29 '12 at 1:05

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.