5th Post Of Our Advent Calendar: Theme Uninstaller
December 5th, 2009 by Michael • WordPress Hacks • 3 Comments
Enjoy 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
Info
- Published in WordPress Hacks
- Tags: Advent Calendar, Code, PHP, Theme, WordPress, WordPress Tutorials
- Comment feed
- read: 8494 | today: 2
- leave a Comment




Great tip! i was looking for that, thanks!
Am implementing this in my Connections Reloaded theme. Have a new release scheduled for this week!