5th Post Of Our Advent Calendar: Theme Uninstaller

WordPress-Christmas-05Enjoy our 5th post of our Advent Calendar: More and more WordPress themes, especially commercial themes, have an option page. The settings are stored in the database. Only few themes have an uninstall button to delete these settings in your database.

Here is a solution, which is easy to implement for every theme developer:

<input type="submit" name="your_preffix_uninstall" value="<?php _e('Uninstall Theme', 'your_textdomain'); ?>" class="button-secondary" />

Now we have to add some code and the entries in your database are gone.

if (isset($_POST['your_preffix_uninstall'])) {
        delete_option('your_theme_options');
        update_option('template', 'default');
        update_option('stylesheet', 'default');
        delete_option('current_theme');
        $theme = get_current_theme();
        do_action('switch_theme', $theme);
        $redirect = 'themes.php';
}

Everyone who is still saving every option seperately have to expand this line of code of course delete_option('your_theme_options') . 😉 Therefore it is better to save the settings in an array or object. More details are available at Working With Options

Comments are closed.

3 comments

  1. rzepak

    Great tip! i was looking for that, thanks! 🙂

  2. Ajay

    Am implementing this in my Connections Reloaded theme. Have a new release scheduled for this week!

One pingback

  1. Правильное удаление тем Wordpress: статьи, плагины, темы