I am writing a plugin where I have custom taxonomy (category). I want to prevent
- any user from
- deleting some of
- custom categories.
Is there any way how to do so.
Let's say that category with id1-id10 nobody (admin included) can delete.
If you want to prevent deleting a single or a list of category IDs within the admin, you can prevent so by blocking all requests that delete the category.
There is no hook in wordpress you can make use of to use easily, but there's always a work-around. In my example I use the
On deletion of a blocked category, you will get either a You do not have permission to do that. message (Ajax) or a This category is blocked for deletion. message and you need to go back with your browser.
you could use
to find the categories, then search for the ones you want. Then you can use
to place them in. You'll need a post that you don't mind having all the categories assigned to, a private post would work well here.
So the final code might look something like:
This code is straight-from-the-brain, fresh and untested.
It's worth noting that this will not prevent deletion, it will just put them straight back so long as it is called on init.
To prevent deletion, you COULD look at hiding the option with CSS in the admin panel.
I do this with a workaround by using the following plugin for loading custom css in the admin panel: http://wordpress.org/extend/plugins/custom-admin-css/ And then hiding the delete option for the required posts/pages or categories.