10

I'm creating a custom taxonomy whose terms must remain fixed by all users. Once I've set up the starting set of terms, I want them to be immutable. I also don't want to clutter up the Admin UI with additional links and metaboxes where they're not needed.

However, setting public => 'false', or show_ui => 'false' not only hides the manage tax link, but also prevents the user from assigning the term to a new post.

I need a way to hide the "manage" link within the post type pulldown, show the term selector metabox on the post page, but (hopefully) disable the "Add Term" option at the bottom of this metabox.

Does such a feature exist? Or are taxonomies always supposed to be user editable?

Custom taxonomy capabilities get me most of the way there, since you can independently set CRUD rights based on capability. But how to disable even admins from modification? (I know this sounds like a bad idea but it's viable.)

6
  • Have you thought about disabling/hiding the those features in the admin theme with JS/CSS as a quick fix? Commented Sep 13, 2011 at 12:56
  • 1
    You talking categories (hierarchical) or tags? You just need a hidden taxonomy + custom widget. If it's categories, it easier to do, if tags... depends if the number of items is decent. And you can hide them from public view only for non-Administrators. That way you can manage them easily while the others can't touch them. Commented Oct 23, 2011 at 4:43
  • @EarnestoDev sounds like the only option. Post your comment as an answer and I'll accept it.
    – Tom Auger
    Commented Oct 24, 2011 at 16:46
  • @TomAuger You want to create something similar to Post Formats right? I mean metabox in post edit screen and not editable from wp-admin UI
    – Mamaduka
    Commented Oct 24, 2011 at 20:01
  • @Mamaduka, yeah, not the same role, but exactly that kind of implementation.
    – Tom Auger
    Commented Oct 26, 2011 at 13:01

2 Answers 2

19

A bit late but thought this could use updating.

Create your custom taxonomy and add the terms you need, then go back to your register_taxonomy() function and set the capabilities argument (which itself accepts an array of capabilities). You can see how I setup sex for dogs which can only ever have two values–"Male" or "Female", which I input. Now admins can only assign a dog to a sex but cannot add, delete, or edit the sexes.

register_taxonomy('sex', 'dog', array(
  'capabilities' => array(
    'manage_terms' => '',
    'edit_terms' => '',
    'delete_terms' => '',
    'assign_terms' => 'edit_posts'
  ),
  'label' => 'Sex',
  'labels' => array(
    'name' => 'Sex',
    'add_new_item' => 'Add New Sex',
    'new_item_name' => "Add New Sex"
  ),
  'public' => true,
  'show_admin_column' => true,
  'show_in_nav_menus' => false,
  'show_tagcloud' => false,
  'show_ui' => true,
  'hierarchical' => true
));

Works on hierarchical taxonomies; I did not try non-hierarchical but it should work there too.

5
  • 3
    This is awesome, cfx, and given the OP's distaste for workarounds, seems like the better answer to me.
    – Nathan
    Commented Sep 2, 2016 at 2:18
  • 1
    Thank you. Helped for me. I also think this is the better answer Commented Feb 19, 2019 at 21:54
  • 1
    The OP does indeed have a distaste for workarounds ;) Thank you for this answer.
    – Tom Auger
    Commented May 15, 2019 at 15:46
  • Note: It WON'T work on hierarchical=>false taxonomies. It seems there's no way to stop users from creating new terms in "tag-type" taxonomies! Writing up a bug report for core.
    – jerclarke
    Commented Aug 28, 2020 at 19:01
  • Agreed it's better not to let something happen instead of telling user off for doing it. HOWEVER one improvement: Immediately after the register_taxonomy(...), use wp_insert_term('Male', 'sex'); wp_insert_term('Female','sex'); so you don't have to separately go in, create options, then block this. This way your plugin/theme can insert them already. Commented Feb 10, 2023 at 15:04
-2

You talking categories (hierarchical) or tags? You just need a hidden taxonomy + custom widget. If it's categories, it easier to do, if tags... depends if the number of items is decent. And you can hide them from public view only for non-Administrators. That way you can manage them easily while the others can't touch them.

Thanks.

2
  • 1
    It would be hidden taxonomy + custom meta box actually, not widget. But - sigh - I think you're right that there's no other option.
    – Tom Auger
    Commented Oct 26, 2011 at 13:01
  • True. Widget, Meta-Box, same collapsible thingy :) Commented Oct 26, 2011 at 16:55

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.