Wordpress database resetter.
I have found that while developing for wordpress it is often very useful to be able to quickly and easily drop all the working tables and start from scratch, so i whipped up a plugin to do just that. It will drop every table from the database defined in your wp-config.php that starts with the defined prefix, when you tell it to of course. It will then direct you to the last step of the install, where you will need to define your blog title, and your admin email address.
download DB Reset
here is the code:
<?php /* Plugin Name: DB Reset Plugin URI: http://trickeries.com/16/wordpress-database-resetter/ Description: terribly simple plugin to basically drop all of your wordpress tables. Author: atom smith Version: 1.0 Author URI: http://trickeries.com/ */ add_action('init','db_reset_delete_tables'); add_action('admin_menu', 'add_db_reset_sub_menu'); function add_db_reset_sub_menu(){ add_submenu_page('plugins.php', 'DB Reset', 'DB Reset', 9, __FILE__, 'db_reset_output'); } function db_reset_output(){ ?> <div class="wrap"> <h2>DB Reset</h2> <?php if(!isSet($_POST['db_reset'])): ?> <?php db_reset_get_tables() ?> <?php endif; ?> </div> <?php } function db_reset_get_tables(){ global $wpdb; $prefixed_tables = $wpdb->prefix . '%'; $tables = $wpdb->get_results("show tables LIKE '$prefixed_tables'", ARRAY_A); ?> <div class="updated"><strong>Please make sure that you understand what you are doing before using this. The following tables will be deleted and replaced:</strong> <ul> <?php foreach($tables as $k => $v): ?> <li> <?php echo $tables_to_delete[] = pos($v) ?> </li> <?php endforeach; ?> </ul> </div> <form action="#" method="post"> <?php foreach($tables_to_delete as $table): ?> <input type="hidden" name="delete[]" value="<?php echo $table ?>" /> <?php endforeach; ?> <input style="font-size:100px; width:100%; padding: 20px;" type="submit" name="db_reset" value="Reset DB" /> </form> <?php } function db_reset_delete_tables(){ if(isSet($_POST['db_reset']) && $_POST['db_reset'] == 'Reset DB'){ global $wpdb; if($wpdb->prefix != ''){ foreach($_POST['delete'] as $table){ $wpdb->query("DROP TABLE $table"); } $location = ".."; } header("Location: $location"); } }








June 2nd, 2009 at 5:36 pm
It worked! Thanks!
August 20th, 2009 at 8:11 pm
Hi, do you happen to know how I can reset the categories within Wordpress? For some reason mine are just going crazy and I need to start from scratch. But I don’t want to delete anything else…