WordPress Database Reset - Version 1.0

Version Description

  • First version
Download this release

Release Info

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

Version 1.0

languages/default.mo ADDED
Binary file
languages/default.po ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: WP Reset\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2011-10-02 17:15-0500\n"
6
+ "PO-Revision-Date: 2011-10-02 17:15-0500\n"
7
+ "Last-Translator: \n"
8
+ "Language-Team: Chris Berthe <chrisberthe@gmail.com>\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n"
13
+ "X-Poedit-Basepath: /Users/chrisberthe/.ssh/wp/wp-content/plugins/wp-reset\n"
14
+ "X-Poedit-Language: English\n"
15
+ "X-Poedit-SearchPath-0: .\n"
16
+
17
+ #: wp-reset.php:106
18
+ msgid "You entered the wrong value - please try again"
19
+ msgstr "Vous avez entré une valeur incorrecte - s'il vous plaît essayez à nouveau."
20
+
21
+ #: wp-reset.php:108
22
+ msgid "The WordPress database has been reset successfully"
23
+ msgstr "La base de données WordPress a été réinitialisé avec succès"
24
+
25
+ #: wp-reset.php:113
26
+ msgid "Database Reset"
27
+ msgstr "Réinitialisation base de données"
28
+
29
+ #: wp-reset.php:119
30
+ msgid "Reset Database"
31
+ msgstr "Réinitialiser"
32
+
33
+ #: wp-reset.php:123
34
+ #, php-format
35
+ msgid "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"
36
+ msgstr "L'utilisateur <strong><u>admin</u></strong> par défaut n'a jamais été créé pour cette installation de WordPress. Alors <strong><u>%s</u></strong> sera plutôt recréé avec son mot de passe actuel."
37
+
38
+ #: wp-reset.php:125
39
+ msgid "The default user <strong><u>admin</u></strong> will be recreated with its current password upon resetting"
40
+ msgstr "L'utilisateur <strong><u>admin</u></strong> par défaut sera recréé avec son mot de passe actuel après la réinitialisation"
41
+
42
+ #: wp-reset.php:128
43
+ msgid "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"
44
+ msgstr "Notez qu'une fois la base de données soit réinitialiser, tous les utilisateurs seront supprimées à l'exception de l'utilisateur admin initial. Le plugin sera également réactiver après la réinitialisation"
45
+
46
+ #: wp-reset.php:143
47
+ msgid "Clicking OK will result in your database being reset to its initial settings. Continue?"
48
+ msgstr "Si vous cliquez sur OK, votre base de données sera supprimé. Continuer?"
49
+
50
+ #: wp-reset.php:183
51
+ msgid "Have any cool ideas for this plugin? Contact me either by <a href=\"http://twitter.com/#!/chrisberthe\">Twitter</a> or by <a href=\"https://github.com/chrisberthe\">GitHub</a>."
52
+ msgstr "Avez-vous des idées pour ce plugin? "
53
+
54
+ #: wp-reset.php:184
55
+ msgid "If this plugin becomes non-functional in any way due to WordPress upgrades, rest assured I will update it."
56
+ msgstr "Si ce plugin ne marche plus à cause de mises à jour WordPress, rassurez-vous que je vais le mettre à jour dès que possible."
57
+
58
+ #: wp-reset.php:185
59
+ msgid "Goodbye for now."
60
+ msgstr "À bientôt."
61
+
languages/fr_FR.mo ADDED
Binary file
languages/fr_FR.po ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: WP Reset\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2011-10-02 17:15-0500\n"
6
+ "PO-Revision-Date: 2011-10-02 17:15-0500\n"
7
+ "Last-Translator: \n"
8
+ "Language-Team: Chris Berthe <chrisberthe@gmail.com>\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n"
13
+ "X-Poedit-Basepath: /Users/chrisberthe/.ssh/wp/wp-content/plugins/wp-reset\n"
14
+ "X-Poedit-Language: English\n"
15
+ "X-Poedit-SearchPath-0: .\n"
16
+
17
+ #: wp-reset.php:106
18
+ msgid "You entered the wrong value - please try again"
19
+ msgstr "Vous avez entré une valeur incorrecte - s'il vous plaît essayez à nouveau."
20
+
21
+ #: wp-reset.php:108
22
+ msgid "The WordPress database has been reset successfully"
23
+ msgstr "La base de données WordPress a été réinitialisé avec succès"
24
+
25
+ #: wp-reset.php:113
26
+ msgid "Database Reset"
27
+ msgstr "Réinitialisation base de données"
28
+
29
+ #: wp-reset.php:119
30
+ msgid "Reset Database"
31
+ msgstr "Réinitialiser"
32
+
33
+ #: wp-reset.php:123
34
+ #, php-format
35
+ msgid "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"
36
+ msgstr "L'utilisateur <strong><u>admin</u></strong> par défaut n'a jamais été créé pour cette installation de WordPress. Alors <strong><u>%s</u></strong> sera plutôt recréé avec son mot de passe actuel."
37
+
38
+ #: wp-reset.php:125
39
+ msgid "The default user <strong><u>admin</u></strong> will be recreated with its current password upon resetting"
40
+ msgstr "L'utilisateur <strong><u>admin</u></strong> par défaut sera recréé avec son mot de passe actuel après la réinitialisation"
41
+
42
+ #: wp-reset.php:128
43
+ msgid "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"
44
+ msgstr "Notez qu'une fois la base de données soit réinitialiser, tous les utilisateurs seront supprimées à l'exception de l'utilisateur admin initial. Le plugin sera également réactiver après la réinitialisation"
45
+
46
+ #: wp-reset.php:143
47
+ msgid "Clicking OK will result in your database being reset to its initial settings. Continue?"
48
+ msgstr "Si vous cliquez sur OK, votre base de données sera supprimé. Continuer?"
49
+
50
+ #: wp-reset.php:183
51
+ msgid "Have any cool ideas for this plugin? Contact me either by <a href=\"http://twitter.com/#!/chrisberthe\">Twitter</a> or by <a href=\"https://github.com/chrisberthe\">GitHub</a>."
52
+ msgstr "Avez-vous des idées pour ce plugin? "
53
+
54
+ #: wp-reset.php:184
55
+ msgid "If this plugin becomes non-functional in any way due to WordPress upgrades, rest assured I will update it."
56
+ msgstr "Si ce plugin ne marche plus à cause de mises à jour WordPress, rassurez-vous que je vais le mettre à jour dès que possible."
57
+
58
+ #: wp-reset.php:185
59
+ msgid "Goodbye for now."
60
+ msgstr "À bientôt."
61
+
readme.txt ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WordPress Database Reset ===
2
+
3
+ Contributors: mousesports
4
+ Tags: wordpress, database, database-reset, default-settings, default, wp-reset, security, secure
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
+
14
+ WordPress Database Reset is a secure and easy way to reinitialize your WordPress database back to its default settings without actually having to reinstall WordPress yourself.
15
+
16
+ Theme and plugin developers tend to forget to clean up after themselves and lots of junk gets piled into the WordPress database (most likely the wp_options table).
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,
25
+ then activate the plugin. You could also use the built-in Add New Plugin
26
+ feature within WordPress. After activating, you will automatically be redirected
27
+ to the plugin page.
28
+
29
+ == Frequently Asked Questions ==
30
+
31
+ = Why reset the database? =
32
+
33
+ There are two important reasons as to why I built this plugin:
34
+
35
+ 1. I wanted a simple and painless way to obtain a fresh clean database without actually having to reinstall WordPress.
36
+ 2. 9 times out of 10 I get tons of excess junk in the wp_options table after installing plugins and themes that do not clean up after themselves.
37
+
38
+ == Screenshots ==
39
+ 1. The plugin page - a more secure way of resetting your database.
40
+
41
+ == Changelog ==
42
+ = 1.0 =
43
+ * First version
screenshot-1.png ADDED
Binary file
wp-reset.php ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP Reset
4
+ Plugin URI: https://github.com/chrisberthe/wp-reset
5
+ Description: A plugin that allows you to reset the database to WordPress's initial state.
6
+ Version: 1.0
7
+ Author: Chris Berthe ☻
8
+ 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
18
+ */
19
+ private $_nonce = 'wp-reset-nonce';
20
+
21
+ /**
22
+ * Loads default options
23
+ *
24
+ * @return void
25
+ */
26
+ function __construct()
27
+ {
28
+ add_action('init', array($this, 'init_language'));
29
+ add_action('admin_init', array($this, 'wp_reset_init'));
30
+ add_action('admin_init', array($this, '_redirect_user'));
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
+ /**
38
+ * Handles the admin page functionality
39
+ *
40
+ * @access public
41
+ * @uses wp_install Located in includes/upgrade.php (line 22)
42
+ */
43
+ function wp_reset_init()
44
+ {
45
+ global $wpdb, $current_user, $pagenow;
46
+
47
+ if ( isset($_POST['wp-random-value'], $_POST['wp-reset-input']) && $_POST['wp-random-value'] == $_POST['wp-reset-input']
48
+ && check_admin_referer('wp-nonce-submit', $this->_nonce) )
49
+ {
50
+ require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
51
+
52
+ $blog_title = get_option('blogname');
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}%'") )
60
+ {
61
+ foreach ( $db_tables as $db_table )
62
+ {
63
+ $wpdb->query("DROP TABLE {$db_table}");
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
+
78
+ /**
79
+ * Displays the admin page
80
+ *
81
+ * @access public
82
+ * @return void
83
+ */
84
+ function show_admin_page()
85
+ {
86
+ global $current_user;
87
+
88
+ // Return to see if admin object exists
89
+ $admin_user = get_userdatabylogin('admin');
90
+
91
+ // Generate a random value for the input box
92
+ $random_string = $this->_rand_string();
93
+ ?>
94
+ <?php if ( isset($_POST['wp-random-value'], $_POST['wp-reset-input']) && $_POST['wp-random-value'] != $_POST['wp-reset-input'] ) : ?>
95
+ <div class="error"><p><strong><?php _e('You entered the wrong value - please try again', 'wp-reset') ?>.</strong></p></div>
96
+ <?php elseif ( isset($_GET['reset']) && $_GET['reset'] == 'success' ) : ?>
97
+ <div class="updated"><p><strong><?php _e('The WordPress database has been reset successfully', 'wp-reset') ?>.</strong></p></div>
98
+ <?php endif ?>
99
+
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
+
121
+ /**
122
+ * Add JavaScript to the bottom of the plugin page
123
+ *
124
+ * @access public
125
+ * @return bool TRUE on reset confirmation
126
+ */
127
+ function add_admin_javascript()
128
+ {
129
+ ?>
130
+ <script type="text/javascript">
131
+ /* <![CDATA[ */
132
+ jQuery('#wp-reset-submit').click(function() {
133
+ var message = "<?php _e('Clicking OK will result in your database being reset to its initial settings. Continue?', 'wp-reset') ?>";
134
+ var reset = confirm(message);
135
+
136
+ if ( reset ) {
137
+ jQuery('#wp-reset-form').submit();
138
+ } else {
139
+ return false;
140
+ }
141
+ });
142
+ /* ]]> */
143
+ </script>
144
+ <?php
145
+ }
146
+
147
+ /**
148
+ * Adds our submenu item to the Tools menu
149
+ *
150
+ * @access public
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
+ }
161
+ }
162
+
163
+ /**
164
+ * Adds the contextual help for our plugin page
165
+ *
166
+ * @access public
167
+ * @param $contextual_help Hook text to display
168
+ * @param $screen_id ID of the current admin screen
169
+ * @return $contextual_help String The help text
170
+ */
171
+ function add_contextual_help($contextual_help, $screen_id)
172
+ {
173
+ if ($screen_id == $this->_hook)
174
+ {
175
+ $contextual_help = '<p>' . __('Have any cool ideas for this plugin? Contact me either by <a href="http://twitter.com/#!/chrisberthe">Twitter</a> or by <a href="https://github.com/chrisberthe">GitHub</a>.', 'wp-reset') . '</p>';
176
+ $contextual_help .= '<p>' . __('If this plugin becomes non-functional in any way due to WordPress upgrades, rest assured I will update it.', 'wp-reset') . '</p>';
177
+ $contextual_help .= '<p>' . __('Goodbye for now.', 'wp-reset') . '</p>';
178
+ }
179
+
180
+ return $contextual_help;
181
+ }
182
+
183
+ /**
184
+ * Load language path
185
+ *
186
+ * @access public
187
+ * @return void
188
+ */
189
+ function init_language()
190
+ {
191
+ $language_dir = basename(dirname(__FILE__)) . '/languages';
192
+ load_plugin_textdomain('wp-reset', FALSE, $language_dir);
193
+ }
194
+
195
+ /**
196
+ * For activation hook
197
+ *
198
+ * @access public
199
+ * @return void
200
+ */
201
+ function plugin_activate()
202
+ {
203
+ add_option('wp-reset-activated', true);
204
+ }
205
+
206
+ /**
207
+ * Redirects the user after the plugin is activated
208
+ *
209
+ * @access private
210
+ * @return void
211
+ */
212
+ function _redirect_user()
213
+ {
214
+ if ( get_option('wp-reset-activated', false) )
215
+ {
216
+ delete_option('wp-reset-activated');
217
+ wp_redirect(admin_url('tools.php') . '?page=wp-reset');
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Changes the password to a sentence rather than
223
+ * an auto-generated password that is sent by email
224
+ * right after the installation is complete
225
+ *
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');
233
+ $password = __('Password: The password you chose during the install.', 'wp-reset');
234
+
235
+ if ( stristr($mail['message'], 'Your new WordPress site has been successfully set up at:') )
236
+ {
237
+ $mail['subject'] = preg_replace('/New WordPress Site/', $subject, $mail['subject']);
238
+ $mail['message'] = preg_replace('/Your new WordPress site has been successfully set up at:+/', $message, $mail['message']);
239
+ $mail['message'] = preg_replace('/Password:\s.+/', $password, $mail['message']);
240
+ }
241
+
242
+ return $mail;
243
+ }
244
+
245
+ /**
246
+ * Updates the user password and clears / sets
247
+ * the authentication cookie for the user
248
+ *
249
+ * @access private
250
+ * @param $user Current or admin user
251
+ * @param $keys Array returned by wp_install()
252
+ * @return TRUE on install success, FALSE otherwise
253
+ */
254
+ function _wp_update_user($user, $keys)
255
+ {
256
+ global $wpdb;
257
+ extract($keys, EXTR_SKIP);
258
+
259
+ // Set the old password back to the user
260
+ $query = $wpdb->prepare("UPDATE $wpdb->users SET user_pass = '%s', user_activation_key = '' WHERE ID = '%d'", $user->user_pass, $user_id);
261
+
262
+ if ( $wpdb->query($query) )
263
+ {
264
+ // Set the default_password_nag to nothing
265
+ // so it doesn't pop up with the password reminder after installing
266
+ if ( get_user_meta($user_id, 'default_password_nag') ) delete_user_meta($user_id, 'default_password_nag');
267
+
268
+ wp_clear_auth_cookie();
269
+ wp_set_auth_cookie($user_id);
270
+
271
+ return TRUE;
272
+ }
273
+
274
+ return FALSE;
275
+ }
276
+
277
+ /**
278
+ * Generates a random value for our input box
279
+ *
280
+ * @access private
281
+ * @param $length Length of the random string value
282
+ * @return $random_string
283
+ */
284
+ function _rand_string($length = 5)
285
+ {
286
+ $random_string = '';
287
+ $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
288
+ $size = strlen($chars);
289
+
290
+ for ($i = 0; $i < $length; $i++)
291
+ {
292
+ $random_string .= $chars[rand(0, $size-1)];
293
+ }
294
+
295
+ return $random_string;
296
+ }
297
+
298
+ }
299
+
300
+ $wp_reset = new WP_Reset();
301
+
302
+ register_activation_hook( __FILE__, array('WP_Reset', 'plugin_activate') );
303
+
304
+ endif;