All we need is an easy explanation of the problem, so here it is.
Inside of a WordPress category metabox or any custom taxonomy box for that matter there is a link with the text “+ Add New Category” is there a way this link can be removed preferably without resorting to JS or CSS hacks to hide it? A way to hide it using some kind of filter or action hook would be best.
If no action hook or filter method exists to remove it, I would be open to JS and CSS solutions as a last resort.
The reason I am doing this is because I have a WordPress installation integrated with Magento and I am creating and populating a custom taxonomy called “brands” with a list of brands from the Magento database so a post can be assigned to a brand. Obviously this means I don’t want users to be able to add in their own terms and only be able to choose the brands added in dynamically to keep it in-sync with Magento.
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
The default metaboxes are registred in the file
wp-admin/includes/meta-boxes.php. There you can find the function
post_categories_meta_box() which will generate the taxonomy metabox. Currently there is no hook available to filter the output. But you can do one of the following:
remove_meta_box()to remove the existing category metabox and register your own with
add_meta_box(). Copy&Past the existing code to your new metabox function and remove the code block from line
- The cleaner way: Remove the
edit_termscapability from your user roles with
remove_cap(). If you look in the metabox function, on line
345you can see an if-statement which checks if the user has the capability
edit_terms. If so, the
+ Add New XYwill be displayed. Problem here, the name of the capability is dynamic and could be anything. If someone registers a taxonomy with a different capability naming, this will probably not work (untested).
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂