Tried to find an or some hook to fire a function when theme is being delited, but didn’t find any hook..
May be someone can tell if there’s a way to fire my function on themes delete event?
I need it to delete options and drop tables on theme delete. ( for example )
Plugins do have uninstall.php
or register_uninstall_hook()
.
Need same for themes! any help ?
My thoughts so far:
-
create
new WP_Filesystem_$module
class and force WP to use myWP_Filesystem_$module
class for deleting themes, where i can insert custom actions atc. -
insert custom action in
deleted_site_transient
action, checking if it wasupdate_themes
transient and check if theme was delited, wich theme was deleted etc..
Both methods has different questions like how to force my class or how to check wich theme was deleted in deleted_site_transient
…
What’s your thoughts on these ?
1 Answer
As long as you don’t delete your theme by ftp, but use the regular way of switching to another theme in the admin, there is a hook to use, switch_theme
. It works like this:
add_action('switch_theme', 'mytheme_setup_options');
function mytheme_setup_options () {
delete_option('mytheme_option1');
delete_option('mytheme_option2');
}
There’s a sister hook called after_switch_theme
, which you could use, for instance, to load default options when a theme is switched on.