0

How do we manage the creation/deletion of custom post types and taxonomies in a plugin?

For example, if I write a plugin that creates a new custom post type and an associated custom taxonomy, what is the best practice when this plugin is removed from the system?

I would like to delete/de-register the custom post type and taxonomy and delete all the content.

How should I do this?

1 Answer 1

2

Custom post types and taxonomies can be registered using register_post_type() and register_taxonomy(). These functions do not actually create any data in the database. Data is added when users populate content (posts and taxonomies).

When a plugin is disabled, any post types and taxonomies that it registers will be unregistered, but all of their data in the database will remain in place.

If you are going to remove data from the database, you should make it abundantly clear to the user what is happening. One common pattern is to require the user to click an option that states that they want data to be deleted when deleting the plugin. The data deletion process can be run using the register_uninstall_hook() or uninstall.php file. Data should not be removed when simply deactivating a plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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