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:
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"); } }













Leave a Reply
ok to use:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
bonus!
If you want to post code, you can use:
<pre lang="[language]">[code]</pre>
Where [language] is a valid geshi language type, and where [code] is your code.