I created a plugin that insert a field on the customise theme options. Since I use

add_action( 'customize_register', 'myregister' );

to create the customise, should I use

 remove_action( 'customize_register', 'myregister' );

when the plugin is deactivated or uninstalled?

1 Answer 1


The Plugin API has hooks for that:

You can use register_deactivation_hook to run a function when the plugin is deactivated.

For uninstall, you have two options. Either register_uninstall_hook or add a file called uninstall.php in your plugin folder.

I would not recommend delete plugin options on plugin deactivation though, the user might not know that he is losing his saved data.

  • On the other hand, I really hate plugins which leave total mess in database after they are removed... So if plugin stores a lot of data in database, there should be a way to delete it. Jul 16, 2013 at 6:59
  • I normally use the uninstall.php method, not the deactivation hook, for deleting data. Sometimes people deactivate plugins during WP upgrades or while debugging.
    – RRikesh
    Jul 16, 2013 at 7:07
  • Just to be clear. If I use the uninstall.php file, I don't need to do remove_action( 'customize_register', 'myregister' ). Is that right?
    – Daniel
    Jul 16, 2013 at 7:18
  • 1
    you've got the add_action concept wrong. an add_action is triggered when do_action() is run. remove_action will only remove a particular function attached to an action.
    – RRikesh
    Jul 16, 2013 at 7:23

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.