0

I've been searching for days now without success... Here's my goal: - assign a top level category by user (this I've made it) - let each user create child categories only in his assigned category (this I need to do)

For example: - category-1 > user-1 - category-2 > user-2 SO user-2 can only create sub-category in category-2...

At the end it's like leaving to users the "manage_categories" capability but having it modified so that the user only create categories in its own assigned parent category.

And by the way not seeing the other top level categories on the list categories page (edit-tag.php). Here I'd like to custom the edit-tags.php?taxonomy=category page depending on the user seeing it...

Thanks for your time and advice. David

0

1 Answer 1

0

This is how I did it :

function if_restrict_categories($categories) {
  global $current_user;
  $a = get_cat_if_user($current_user->ID);
  $onPostPage = (strpos($_SERVER['PHP_SELF'], 'edit-tags.php'));

  if (is_admin() && $onPostPage && !current_user_can('level_10')) {
  $size = count($categories);
  for ($i = 0; $i < $size; $i++) {
      if($categories[$i]->parent != $a && $categories[$i]->term_id != $a){
     unset($categories[$i]);
      }         
  }
   }

   return $categories;
}
add_filter('get_terms', 'if_restrict_categories');

And where get_cat_if_user() is a custom function where I get the category I've assigned to my user.

Hopes it helps others. Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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