WordPress hook after theme is deleted

I create theme in wordpress and now i create some theme options page in appearance.
Now if user remove theme from system i want to delete any data from database.

function register_my_setting() {
    register_setting( 'settings_grup', 'array_post_redirect');
} 
add_action( 'admin_init', 'register_my_setting' );

Now i want to delete options but only solution i found is hook: switch_theme and unregister_setting function. Is there any better hook to perform this ?

function un_register_my_setting() {
    unregister_setting ( 'settings_grup', 'array_post_redirect');
} 
add_action( 'switch_theme', 'un_register_my_setting' );

Related posts

Leave a Reply

1 comment

  1. There is a very good tutorial here that shows you how to create a register_deactivation_hook for your theme. WordPress does not have this feature for themes (like plugins) by default, but with a little tweaking your can duplicate the behavior for your theme.

    For reference, it used to be done like this (pre 3.1 I believe):

    if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) { 
         // do your stuff 
    }