0

I developed a theme which stores some options to the database. I want to delete the option data from the database while the user removes the theme. But I don't know there is any action hook for doing this. Or is there any alternative method to achieve this.

3
  • When the theme is actually deleted or when the theme is deactivated? Or both? Commented Jul 22, 2013 at 3:44
  • 1
    I think I would be disappointed if a theme I was using did this. I'd like to be able to switch to a different theme temporarily and know that when I switch back my options will still be there.
    – Ben Miller
    Commented Jul 22, 2013 at 3:58
  • is deleted, not deactivated. I just want to clean up the data whatever the user thinks. Also it is my person theme, and is not possible for publication.
    – geeker
    Commented Jul 22, 2013 at 4:23

2 Answers 2

0

I don't think this is possible with an action hook. You can only Delete a theme from the admin panel after it has been deactivated. Even if an action hook existed for Deleting (not Deactivating) a theme, your theme functions.php would not be running when you are able to hit the Delete link.

Since this is a personal theme for your own use, you can just delete the options whenever you want from the "options" database table using phpMyAdmin or an Options Manager plugin.

An alternative would be to include some sort of Uninstall button on an options page for your theme that would remove the options from the database and deactivate the theme, perhaps either activating TwentyTwelve or letting the user choose which theme to activate after the uninstall is complete.

0
add_action('switch_theme', 'mydeactivationfunction', 10 , 2);
function mydeactivationfunction() {
delete_option( 'option_name' ); //do this for each option your deleting
}

If this doesn't work in the themes functions.php you can put it in a small plugin and just activate / deactivate it when u want settings cleared on switch

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.