anonymized-13749270
(@anonymized-13749270)
Hi Guido,
You can query those options from options table (settings) through PHPMYADMIN, just select options table o your current installation, click search tab, and in option name type the theme prefix for example “twenty_twelve” followed by % and it should return all options with that name in the beginning..
This code perform that action without the need to go to your db manager:
global $wpdb;
$options = $wpdb->prefix."options";
$query = $wpdb->get_results( "SELECT * FROM $options WHERE option_name LIKE 'theme_prefix_%'");
foreach( $query as $meta ) {
delete_option( $meta->option_name );
}
or simply delete_option( 'option_name' ) if you know the option names.
You you can apply all of this in an switch_theme action hook: (which gets called when the theme is being deactivated)
add_action('switch_theme', function() {
global $wpdb;
$options = $wpdb->prefix."options";
$query = $wpdb->get_results( "SELECT * FROM $options WHERE option_name LIKE 'theme_prefix_%'");
foreach( $query as $meta ) {
delete_option( $meta->option_name );
}
});
Have a nice day!
Thread Starter
Guido
(@guido07111975)
Hi,
This is exactly what I was looking for, I knew about the delete_option (use it in my plugins too) but did not know about the switch_theme hook.
Great, thanks!
Guido