WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Right now, I have this code:

function mr_np_activate(){
    // hook uninstall
    if ( function_exists('register_uninstall_hook') )

 * Delete options

function mr_np_uninstall() {

But when I remove my plugin, all my options are there. (I made another plugin just to show my options).

How can I delete options when plugin is removed?


Homem Robô

share|improve this question
up vote 3 down vote accepted

You could always use an uninstall.php file for the plugin instead.


If the plugin can not be written without running code within the plugin, then the plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook.

When using 'uninstall.php' the plugin should always check for the WP_UNINSTALL_PLUGIN constant, before executing. The WP_UNINSTALL_PLUGIN constant is defined by WordPress at runtime during a plugin uninstall, it will not be present if 'uninstall.php' is requested directly.

That file would only need literally one line of code if the only intention is to remove an option.

<?php delete_option( 'your-option' ); ?>

Not actually addressing your question, just offering an alternative approach for dealing with plugin deactivation.

As to the problem, i think the issue is you're trying to add the deactivation callback during the activation hook, which just seems a little backward or incorrect to me, i'd assume deactivation hooks should be registered in the same way as the activation hook, but neither nested inside the other.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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