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.
3 Answers
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 check_admin_referer
and check_ajax_referer
hooks (note the typo in the hook name) combined with a check if the request is actually one to delete a category (delete something within the category
taxnonomy).
Example Must-Use Plugin: WordPress Block Category Deletion Example
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.