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 was searching through the forums, but I can only find slightly related issues.

This is my problem:

I'd like to assign some editors the capability to only add posts in a predefined term of a custom taxonomy.

I have made a taxonomy called events, which holds a list with events that are added by an admin. Certain users are only allowed to add posts using a single event, e.g. "Japan" or "Haiti".

Anyone with a hint on how to tackle this? are there user management-plugins that have this kind of capabilities?

Regards, Joost.

share|improve this question
add comment

3 Answers

First hook the save_post action: http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

Then check capabilities: You have docs on that right?

Then get_the_terms for the $post_id provided by save_post and the taxonomy you want to check. http://codex.wordpress.org/Function_Reference/get_the_terms

Then if they are using a term (see note below) they are not allowed to use either stop/delete the post, set a warning, or remove the term.

Note: a taxonomy is a list of terms that can be applied to a post. Example: the taxonomy "Nation" would contain terms like "Mexico", "France", and "India"

share|improve this answer
    
Seems like this would work. But what do you mean by see note below? Is that the note in the second URL: It uses get_object_term_cache() or wp_get_object_terms() to retrieve results? Is that the term that you refer to in your second to last paragraph? –  Feral Oink Mar 1 '12 at 9:58
    
The "note below" was at the end of my comment - describing the difference between a taxonomy and a term. I tried to keep the comment short but can provide any other details needed. –  Luke Gedeon Mar 1 '12 at 14:18
    
Ahhh, okay! Thank you. –  Feral Oink Mar 1 '12 at 18:11
add comment

Great article here on user roles and user role management, for your case maybe look up adding a custom role to each user using WP_User_class or maybe even a new role with same capabilities as editor but + 1 of event_poster or something similar, the article is full of good stuff that you can reference.

share|improve this answer
    
Thanks! I will look into that :-) –  Joost May 4 '11 at 7:41
    
Further more it is possible to register a taxonomy with capability restrictions in place again a link but you may as well read it as is as bits copied and pasted. justintadlock.com/archives/2010/06/10/… –  MartinJJ May 4 '11 at 7:58
    
Links are appreciated! There is so much written about access restriction that it is difficult to find the right information. –  Joost May 4 '11 at 8:42
    
Still, I can't find any info on how to restrict access to a specific term within a taxonomy. Restricting access to a taxonomy as a whole is no problem. –  Joost May 4 '11 at 9:02
    
I use Role Scoper plugin for this, lets you limit specific terms –  Milo May 4 '11 at 14:01
show 1 more comment

Wherever you're displaying the taxonomies for selection by the user when he's logged in (you're assigning caps, so I guess the user should log in), just do a check like this...

if(current_user_can('your_custom_capability'))
    { 
      //display only those taxonomies that he should be allowed to post into
    }

If you're displaying the default categories/taxonomies list in the dashboard, then you need to look around for a filter that is applied while the categories/taxonomies are listed. I'll check on that filter and see if I can find one.

share|improve this answer
add comment

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.