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 have a situation where I need to hide a specific category and it's children from users who are logged in as Contributors. I don't want them to see this category and it's children in the categories meta-box on the add new post screen.

I can't find a plugin (that works) to do this, wondering if someone else knows of one, or even better if there is a function I can use to do this?

share|improve this question
    
First question, are you using any kind of plugin that easily let's you add "capabilities" to user "roles", such as the Members plugin? –  MikeSchinkel Jan 31 '11 at 14:13
add comment

2 Answers

up vote 4 down vote accepted

Hi @davemac:

Well, I wrote this before I saw that you answered your own question so I might as well post it anyway:

add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);
function yoursite_list_terms_exclusions( $exclusions, $args ) {
  global $pagenow;
  if (in_array($pagenow,array('post.php','post-new.php')) && 
     !current_user_can('see_special_cats')) {
    $exclusions = " {$exclusions} AND t.slug NOT IN ('slug-one','slug-two')";
  }
  return $exclusions;
}

This code presumes that you've used a plugin like the Members plugin to create a capability called 'see_special_cats' and that you've assigned it to every role that you want to have access to the categories except of course 'Contributors'.

Since you found the plugin you may not need this, but maybe it will help someone else.

share|improve this answer
    
Thanks Mike, that is actually VERY helpful and opens up a lot of possibilities for me. –  davemac Jan 31 '11 at 14:40
    
@davemac - Glad I could help. –  MikeSchinkel Jan 31 '11 at 14:43
add comment

Looks like I have answered my own question, I found a plugin called Restrict Categories that does exactly this.

share|improve this answer
    
No I'm not, but after taking a look at it I probably should be ... –  davemac Jan 31 '11 at 14:30
    
Looks like you haven't put much effort into your own research before asking. No offense. –  Michal Mau Jan 31 '11 at 14:30
    
Point taken. In my own defence it's 1:30am here and my Google Fu was slipping. –  davemac Jan 31 '11 at 14:39
    
Yup, I know this only too well. Hope you're sound asleep now .) Greetings from the other side of globe! –  Michal Mau Jan 31 '11 at 19:11
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.