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.

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.

share|improve this question

4 Answers 4

up vote 2 down vote accepted

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.

share|improve this answer
    
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
    
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
    
I was thinking type-ahead where you can only select from the dropdown. –  ltfishie Apr 11 '12 at 14:38

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);
        }
    }
}
share|improve this answer

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.

share|improve this answer
    
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

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.

share|improve this answer
    
By removing the meta box completely, how can users use existing tags? –  bungeshea Dec 27 '12 at 20:00
    
He just removes the MetaBox if the user cannot publish Posts. –  fischi Dec 27 '12 at 20:44

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.