7

Is there a plugin that would restrict non-admin users to only existing tags? I could have used categories for this, but it will be difficult to display with a large population (~1000) of tags.

  • Just want to agree with Itsfishie's desire for users to be able to type tag names and be able select them, but NOT to add new ones. This same UI could basically be an alternate for hierarchical (categories) system that you enable when you have too many categories to list. – jerclarke Aug 27 '20 at 1:52
  • Note: This question, and the lack of good answers, is due to a bug in WordPress core, where the capabilities argument (which should be the answer) is ignored for hierarchical=>false taxonomies. I've written it up in detail on the core bug tracker: core.trac.wordpress.org/ticket/51181#ticket – jerclarke Aug 28 '20 at 21:32
2

If you do not already have your tags created, you can use the "Bulk Add Tags" plugin - http://wordpress.org/extend/plugins/bulk-add-tags/

Then to restrict all users except admins from adding new tags via the "New Post" screen, add this code to your theme's functions.php file:

//Hide Post Page Options from all except Administrator
if (!current_user_can('administrator')){
function hide_post_page_options() {
global $post;
$hide_post_options = "<style type=\"text/css\"> .jaxtag { display: none; }</style>";
print($hide_post_options);
}
add_action( 'admin_head', 'hide_post_page_options'  );
}

This will simply hide the box for entering new tags from all users except administrators.

I actually use this method to hide many areas of the "New Post" page. Simply find and add the element's div class or id before { display: none; } and separated by commas. If you're unfamiliar, you can use the Firebug plugin with Firefox, or simply right-click and select "Inspect Element" in Chrome.

I prefer this method over many plugins because it does not remove functionality completely from Wordpress, the functionality is simply hidden from users who do not need it.

  • Thanks for you answer. If the tag box is hidden, how would non-admin user tag the post with existing tags? – ltfishie Apr 11 '12 at 13:17
  • There are two options in the Tags meta box: 1 - Enter your own tags. 2 - "Choose from the most used tags". The code only hides the ability to enter new tags. – Travis Pflanz Apr 11 '12 at 13:39
  • 1
    Ah ok, that might work. But given 1000s of tags, that display will be a bit unwieldy. But that's not a bad way to start. I might be able to do some front-end treatment to make it look better. – ltfishie Apr 11 '12 at 13:43
  • 1
    Curious, with 1000s of tags for users to choose from, how do you envision users selecting their tags? I ask so maybe others can find a more accurate solution. – Travis Pflanz Apr 11 '12 at 13:48
  • 1
    I was thinking type-ahead where you can only select from the dropdown. – ltfishie Apr 11 '12 at 14:38
6

None of these solutions did exactly what I needed to allow non-admin users to use existing tags on a post, but not create new tags. So I created the following solution, which works great - although it does not provide any feedback to the user that their tags weren't added (it really just undoes the tag creation immediately):

add_action('create_term','undo_create_term',10, 3);

function undo_create_term ($term_id, $tt_id, $taxonomy) {
    if ( !current_user_can( 'administrator' ) )  {
        if($taxonomy == 'post_tag') {
        wp_delete_term($term_id,$taxonomy);
        }
    }
}
1

Your question has really intrigued me. I can see a huge use for this situation, so I will do whatever I can to help you find the answer.

Here is another solution, not exactly what you mentioned in your comment on the other answer, but it does make it a little easier for users to find the tags they want, as the tags are listed alphabetically.

Manage Tags Capability plugin - http://wordpress.org/extend/plugins/manage-tags-capability/

Also, should note: This method allows users to select from ALL available tags. I just realized, the other method only allows users to select from the "most used" tags.

Wordpress already does an auto-predict when typing tags, so essentially, we need to find a way to allow users to type the tag they want, but not add a new one if they cannot find it.

  • The manage tags capability seems to be a good fit, I will play with it a bit. – ltfishie Apr 11 '12 at 16:55
  • The manage tags capability seems plugins fits what I am asking for here exactly. – ltfishie Apr 11 '12 at 17:23
  • Glad it fit your needs. I will let you know if I find a predictive text option. Let me know if you find one as well. – Travis Pflanz Apr 11 '12 at 17:56
  • Sadly this plugin has been killed: This plugin has been closed as of March 10, 2020 and is not available for download. Reason: Guideline Violation. – jerclarke Aug 27 '20 at 22:30
0

This is how I solve same problem (in functions.php of your theme):

/* Removing Tags for users */
if (is_admin()) :
function my_remove_meta_boxes() {
 if(!current_user_can('publish_posts')) { 
   remove_meta_box('tagsdiv-post_tag', 'post', 'normal');
 }
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );
endif;

First we check if it's admin area, then we check if user can publish posts (usually it's admins and editors), than we do our magic with remove_meta_box.

  • By removing the meta box completely, how can users use existing tags? – shea Dec 27 '12 at 20:00
  • He just removes the MetaBox if the user cannot publish Posts. – fischi Dec 27 '12 at 20:44
  • Be very careful with this solution! I've used it before but it led to strange outcomes when the form submits and is missing the fields from this box. Definitely recommend the solution above instead, where you just hide the box with CSS. That way the form fields still get submitted. – jerclarke Aug 27 '20 at 1:56
  • More importantly, this just doesn't solve the problem. It makes it impossible for a user to add a tag, whereas the original question is about allowing users to add EXISTING tags without letting them create new ones. – jerclarke Aug 27 '20 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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