Wordpress - How can I delete options with register_uninstall_hook?

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

http://codex.wordpress.org/Function_Reference/register_uninstall_hook

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.


Inside the main plugin file:

// plugin activation
register_activation_hook( __FILE__, 'my_fn_activate' );
function my_fn_activate() {
    add_option( 'my_plugin_option', 'some-value' );
}

// plugin deactivation
register_deactivation_hook( __FILE__, 'my_fn_deactivate' );
function my_fn_deactivate() {
    // some code for deactivation...
}

// plugin uninstallation
register_uninstall_hook( __FILE__, 'my_fn_uninstall' );
function my_fn_uninstall() {
    delete_option( 'my_plugin_option' );
}