WordPress Database Reset - Version 1.2

Version Description

  • Added capability to manually select whether or not plugin should be reactivated upon reset
  • Modified class name to avoid potential conflicts with WordPress core
  • Modified wp_mail override
  • Removed deprecated user level for WordPress 3.0+
  • Fixed small bug where if admin user did not have admin capabilities, it would tell the user they did
Download this release

Release Info

Developer mousesports
Plugin Icon 128x128 WordPress Database Reset
Version 1.2
Comparing to
See all releases

Code changes from version 1.0 to 1.2

Files changed (3) hide show
  1. readme.txt +9 -4
  2. screenshot-1.png +0 -0
  3. wp-reset.php +27 -18
readme.txt CHANGED
@@ -5,9 +5,9 @@ Tags: wordpress, database, database-reset, default-settings, default, wp-reset,
5
  License: GPL2
6
  Requires at least: 3.0
7
  Tested up to: 3.2.1
8
- Stable tag: 1.0
9
 
10
- A secure easy way to reinitialize the WordPress database to its default settings.
11
 
12
  == Description ==
13
 
@@ -17,8 +17,6 @@ Theme and plugin developers tend to forget to clean up after themselves and lots
17
 
18
  This plugin allows you to securely reset the database, deleting everything except the admin user. The plugin makes sure the only access it will grant is to administrators with a user level of 10. Also, the form uses nonces (read more about them at <a href="http://codex.wordpress.org/WordPress_Nonces">WordPress nonces</a>) which adds another level of security to your application.
19
 
20
- This plugin also comes Translation ready - the default is English and it is translated into French as well.
21
-
22
  == Installation ==
23
 
24
  Copy the wp-reset folder and its contents to your wp-content/plugins directory,
@@ -39,5 +37,12 @@ There are two important reasons as to why I built this plugin:
39
  1. The plugin page - a more secure way of resetting your database.
40
 
41
  == Changelog ==
 
 
 
 
 
 
 
42
  = 1.0 =
43
  * First version
5
  License: GPL2
6
  Requires at least: 3.0
7
  Tested up to: 3.2.1
8
+ Stable tag: 1.2
9
 
10
+ A secure and easy way to reinitialize the WordPress database to its default settings.
11
 
12
  == Description ==
13
 
17
 
18
  This plugin allows you to securely reset the database, deleting everything except the admin user. The plugin makes sure the only access it will grant is to administrators with a user level of 10. Also, the form uses nonces (read more about them at <a href="http://codex.wordpress.org/WordPress_Nonces">WordPress nonces</a>) which adds another level of security to your application.
19
 
 
 
20
  == Installation ==
21
 
22
  Copy the wp-reset folder and its contents to your wp-content/plugins directory,
37
  1. The plugin page - a more secure way of resetting your database.
38
 
39
  == Changelog ==
40
+ = 1.2 =
41
+ * Added capability to manually select whether or not plugin should be reactivated upon reset
42
+ * Modified class name to avoid potential conflicts with WordPress core
43
+ * Modified wp_mail override
44
+ * Removed deprecated user level for WordPress 3.0+
45
+ * Fixed small bug where if admin user did not have admin capabilities, it would tell the user they did
46
+
47
  = 1.0 =
48
  * First version
screenshot-1.png CHANGED
Binary file
wp-reset.php CHANGED
@@ -9,9 +9,9 @@ Author URI: https://github.com/chrisberthe
9
  License: GNU General Public License
10
  */
11
 
12
- if ( ! class_exists('WP_Reset') && is_admin() ) :
13
 
14
- class WP_Reset
15
  {
16
  /**
17
  * Nonce value
@@ -31,7 +31,7 @@ if ( ! class_exists('WP_Reset') && is_admin() ) :
31
  add_action('admin_footer', array($this, 'add_admin_javascript'));
32
  add_action('admin_menu', array($this, 'add_admin_menu'));
33
  add_filter('contextual_help', array($this, 'add_contextual_help'), 10, 2);
34
- add_filter('wp_mail', array($this, '_fix_password_mail'));
35
  }
36
 
37
  /**
@@ -53,7 +53,7 @@ if ( ! class_exists('WP_Reset') && is_admin() ) :
53
  $public = get_option('blog_public');
54
 
55
  $admin_user = get_userdatabylogin('admin');
56
- $user = ( ! $admin_user || $admin_user->wp_user_level < 10 ) ? $current_user : $admin_user;
57
 
58
  // Run through the database columns and drop all the tables
59
  if ( $db_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'") )
@@ -64,14 +64,19 @@ if ( ! class_exists('WP_Reset') && is_admin() ) :
64
  }
65
 
66
  // Return user keys and import variables
67
- $keys = wp_install($blog_title, $user->user_login, $user->user_email, $public);
68
  $this->_wp_update_user($user, $keys);
69
-
70
- // Reactivate the plugin after reinstalling
 
 
 
71
  update_option('active_plugins', array(plugin_basename(__FILE__)));
72
-
73
  wp_redirect(admin_url($pagenow) . '?page=wp-reset&reset=success'); exit();
74
  }
 
 
 
75
  }
76
  }
77
 
@@ -100,21 +105,27 @@ if ( ! class_exists('WP_Reset') && is_admin() ) :
100
  <div class="wrap">
101
  <?php screen_icon() ?>
102
  <h2><?php _e('Database Reset', 'wp-reset') ?></h2>
103
- <p>Please type in (or copy/paste) the generated value into the text box:&nbsp;&nbsp;<strong><?php echo $random_string ?></strong></p>
104
  <form action="" method="POST" id="wp-reset-form">
105
  <?php wp_nonce_field('wp-nonce-submit', $this->_nonce) ?>
106
  <input type="hidden" name="wp-random-value" value="<?php echo $random_string ?>" id="wp-random-value" />
107
  <input type="text" name="wp-reset-input" value="" id="wp-reset-input" />
108
  <input type="submit" name="wp-reset-submit" value="<?php _e('Reset Database', 'wp-reset') ?>" id="wp-reset-submit" class="button-primary" />
 
 
 
 
 
 
109
  </form>
110
 
111
- <?php if ( ! $admin_user || $admin_user->wp_user_level < 10 ) : ?>
112
  <p style="margin-top: 25px"><?php printf(__('The default user <strong><u>admin</u></strong> was never created for this WordPress install. So <strong><u>%s</u></strong> will be recreated with its current password instead', 'wp-reset'), $current_user->user_login) ?>.</p>
113
  <?php else : ?>
114
  <p><?php _e('The default user <strong><u>admin</u></strong> will be recreated with its current password upon resetting', 'wp-reset') ?>.</p>
115
  <?php endif; ?>
116
 
117
- <p><?php _e('Note that once you reset the database, all users will be deleted except the initial admin user. The plugin will also reactivate itself after resetting', 'wp-reset') ?>.</p>
118
  </div>
119
  <?php }
120
 
@@ -151,10 +162,8 @@ if ( ! class_exists('WP_Reset') && is_admin() ) :
151
  * @return void
152
  */
153
  function add_admin_menu()
154
- {
155
- global $current_user;
156
-
157
- if ( current_user_can('update_core') && $current_user->wp_user_level == 10)
158
  {
159
  $this->_hook = add_submenu_page('tools.php', 'Database Reset', 'Database Reset', 'update_core', 'wp-reset', array($this, 'show_admin_page'));
160
  }
@@ -226,7 +235,7 @@ if ( ! class_exists('WP_Reset') && is_admin() ) :
226
  * @access private
227
  * @return $mail Version with password changed
228
  */
229
- function _fix_password_mail($mail)
230
  {
231
  $subject = __('WordPress Database Reset', 'wp-reset');
232
  $message = __('The WordPress database has been successfully reset to its default settings:', 'wp-reset');
@@ -297,8 +306,8 @@ if ( ! class_exists('WP_Reset') && is_admin() ) :
297
 
298
  }
299
 
300
- $wp_reset = new WP_Reset();
301
 
302
- register_activation_hook( __FILE__, array('WP_Reset', 'plugin_activate') );
303
 
304
  endif;
9
  License: GNU General Public License
10
  */
11
 
12
+ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
13
 
14
+ class cb_wp_reset
15
  {
16
  /**
17
  * Nonce value
31
  add_action('admin_footer', array($this, 'add_admin_javascript'));
32
  add_action('admin_menu', array($this, 'add_admin_menu'));
33
  add_filter('contextual_help', array($this, 'add_contextual_help'), 10, 2);
34
+ add_filter('wp_mail', array($this, '_fix_mail'));
35
  }
36
 
37
  /**
53
  $public = get_option('blog_public');
54
 
55
  $admin_user = get_userdatabylogin('admin');
56
+ $user = ( ! $admin_user || ! user_can( $admin_user->ID, 'update_core' ) ) ? $current_user : $admin_user;
57
 
58
  // Run through the database columns and drop all the tables
59
  if ( $db_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'") )
64
  }
65
 
66
  // Return user keys and import variables
67
+ $keys = wp_install($blog_title, $user->user_login, $user->user_email, $public);
68
  $this->_wp_update_user($user, $keys);
69
+ }
70
+
71
+ // Reactivate the plugin after reinstalling
72
+ if ( isset($_POST['wp-reset-check']) && $_POST['wp-reset-check'] == 'true' )
73
+ {
74
  update_option('active_plugins', array(plugin_basename(__FILE__)));
 
75
  wp_redirect(admin_url($pagenow) . '?page=wp-reset&reset=success'); exit();
76
  }
77
+
78
+ // If the wp-reset-check isn't checked just redirect user to dashboard
79
+ wp_redirect(admin_url()); exit();
80
  }
81
  }
82
 
105
  <div class="wrap">
106
  <?php screen_icon() ?>
107
  <h2><?php _e('Database Reset', 'wp-reset') ?></h2>
108
+ <p><?php _e('Please type in (or copy/paste) the generated value into the text box', 'wp-reset') ?>:&nbsp;&nbsp;<strong><?php echo $random_string ?></strong></p>
109
  <form action="" method="POST" id="wp-reset-form">
110
  <?php wp_nonce_field('wp-nonce-submit', $this->_nonce) ?>
111
  <input type="hidden" name="wp-random-value" value="<?php echo $random_string ?>" id="wp-random-value" />
112
  <input type="text" name="wp-reset-input" value="" id="wp-reset-input" />
113
  <input type="submit" name="wp-reset-submit" value="<?php _e('Reset Database', 'wp-reset') ?>" id="wp-reset-submit" class="button-primary" />
114
+ <p>
115
+ <label for="wp-reset-check">
116
+ <input type="checkbox" name="wp-reset-check" id="wp-reset-check" checked="checked" value="true" />
117
+ <?php _e('Reactivate plugin after resetting?', 'wp-reset') ?>
118
+ </label>
119
+ </p>
120
  </form>
121
 
122
+ <?php if ( ! $admin_user || ! user_can( $admin_user->ID, 'update_core' ) ) : ?>
123
  <p style="margin-top: 25px"><?php printf(__('The default user <strong><u>admin</u></strong> was never created for this WordPress install. So <strong><u>%s</u></strong> will be recreated with its current password instead', 'wp-reset'), $current_user->user_login) ?>.</p>
124
  <?php else : ?>
125
  <p><?php _e('The default user <strong><u>admin</u></strong> will be recreated with its current password upon resetting', 'wp-reset') ?>.</p>
126
  <?php endif; ?>
127
 
128
+ <p><?php _e('Note that once you reset the database, all users will be deleted except the initial admin user.', 'wp-reset') ?></p>
129
  </div>
130
  <?php }
131
 
162
  * @return void
163
  */
164
  function add_admin_menu()
165
+ {
166
+ if ( current_user_can( 'update_core' ) )
 
 
167
  {
168
  $this->_hook = add_submenu_page('tools.php', 'Database Reset', 'Database Reset', 'update_core', 'wp-reset', array($this, 'show_admin_page'));
169
  }
235
  * @access private
236
  * @return $mail Version with password changed
237
  */
238
+ function _fix_mail($mail)
239
  {
240
  $subject = __('WordPress Database Reset', 'wp-reset');
241
  $message = __('The WordPress database has been successfully reset to its default settings:', 'wp-reset');
306
 
307
  }
308
 
309
+ $cb_wp_reset = new cb_wp_reset();
310
 
311
+ register_activation_hook( __FILE__, array('cb_wp_reset', 'plugin_activate') );
312
 
313
  endif;