WordPress Reset - Version 1.4.1

Version Description

= 1.3.3 = Fix an issue where a user does not have a user_level

= 1.3.2 = Support PHP versions below 5.3.0, by not using lambda function creation in add_action for admin_notices

= 1.3.1 = Fix sql query, so that _ isn't being used as a single character match

= 1.3 =

Fixes a deprecated notice in WordPress 3.3, removed the $auto_reactivate variable, and look for REACTIVATE_WP_RESET to be defined in wp-config.php, as well as the ability to activate additional plugins using a global $reactivate_wp_reset_additional array defined in wp-config.php

Download this release

Release Info

Developer aristath
Plugin Icon WordPress Reset
Version 1.4.1
Comparing to
See all releases

Code changes from version 1.4 to 1.4.1

Files changed (2) hide show
  1. readme.txt +4 -4
  2. wordpress-reset.php +93 -65
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === WordPress Reset ===
2
- Contributors: sivel, aristath
3
- Donate Link: http://sivel.net/donate
4
  Tags: wordpress-reset, wordpress, reset, admin
5
  Requires at least: 2.8
6
- Tested up to: 4.5
7
- Stable tag: 1.4
8
 
9
  Resets the WordPress database back to it's defaults. Deletes all customizations and content. Does not modify files only resets the database.
10
 
1
  === WordPress Reset ===
2
+ Contributors: aristath, sivel
3
+ Donate Link: http://aristath.github.io/donate
4
  Tags: wordpress-reset, wordpress, reset, admin
5
  Requires at least: 2.8
6
+ Tested up to: 4.9
7
+ Stable tag: 1.4.1
8
 
9
  Resets the WordPress database back to it's defaults. Deletes all customizations and content. Does not modify files only resets the database.
10
 
wordpress-reset.php CHANGED
@@ -1,24 +1,27 @@
1
  <?php
2
- /*
3
- Plugin Name: WordPress Reset
4
- Plugin URI: http://sivel.net/wordpress/wordpress-reset/
5
- Description: Resets the WordPress database back to it's defaults. Deletes all customizations and content. Does not modify files only resets the database.
6
- Author: Matt Martz
7
- Version: 1.4
8
- Author URI: http://sivel.net/
9
-
10
- Copyright (c) 2009-2012 Matt Martz (http://sivel.net)
11
- WordPress Reset is released under the GNU General Public License (GPL)
12
- http://www.gnu.org/licenses/gpl-2.0.txt
13
- */
14
-
15
- // Only run the code if we are in the admin
16
- if ( is_admin() && ! class_exists( 'WordPress_Reset' ) ) :
17
-
 
18
  class WordPress_Reset {
 
19
  /**
20
- * The class constructor.
21
- * contains Action/Filter Hooks
 
22
  */
23
  public function __construct() {
24
  add_action( 'admin_menu', array( $this, 'add_page' ) );
@@ -29,8 +32,11 @@ class WordPress_Reset {
29
  }
30
 
31
  /**
32
- * favorite_actions filter hook operations
33
  * While this plugin is active put a link to the reset page in the favorites drop down.
 
 
 
 
34
  */
35
  public function favorites( $actions ) {
36
  $reset['tools.php?page=wordpress-reset'] = array( esc_html__( 'WordPress Reset' ), 'level_10' );
@@ -38,8 +44,9 @@ class WordPress_Reset {
38
  }
39
 
40
  /**
41
- * wp_before_admin_bar_render action hook operations
42
- * While this plugin is active put a link to the reset page in the admin bar under the site title
 
43
  */
44
  public function admin_bar_link() {
45
  global $wp_admin_bar;
@@ -48,31 +55,30 @@ class WordPress_Reset {
48
  'parent' => 'site-name',
49
  'id' => 'wordpress-reset',
50
  'title' => 'Reset Site',
51
- 'href' => admin_url( 'tools.php?page=wordpress-reset' )
52
  )
53
  );
54
  }
55
 
56
  /**
57
- * admin_init action hook operations
58
  * Checks for wordpress_reset post value and if there deletes all wp tables
59
- * and performs an install, populating the users previous password also
60
  */
61
  public function admin_init() {
62
  global $current_user;
63
 
64
- $wordpress_reset = ( isset( $_POST['wordpress_reset'] ) && $_POST['wordpress_reset'] == 'true' ) ? true : false;
65
- $wordpress_reset_confirm = ( isset( $_POST['wordpress_reset_confirm'] ) && $_POST['wordpress_reset_confirm'] == 'reset' ) ? true : false;
66
- $valid_nonce = ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wordpress_reset' ) ) ? true : false;
67
 
68
  if ( $wordpress_reset && $wordpress_reset_confirm && $valid_nonce ) {
69
- require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
70
 
71
  $blogname = get_option( 'blogname' );
72
  $admin_email = get_option( 'admin_email' );
73
  $blog_public = get_option( 'blog_public' );
74
 
75
- if ( $current_user->user_login != 'admin' ) {
76
  $user = get_user_by( 'login', 'admin' );
77
  }
78
 
@@ -131,17 +137,24 @@ class WordPress_Reset {
131
  }
132
 
133
  /**
134
- * admin_notices action hook operations
135
- * Inform the user that WordPress has been successfully reset
 
136
  */
137
  public function reset_notice() {
138
  $user = get_user_by( 'id', 1 );
139
- echo '<div id="message" class="updated fade"><p><strong>WordPress has been reset back to defaults. The user "' . $user->user_login . '" was recreated with its previous password.</strong></p></div>';
 
 
 
 
140
  do_action( 'wordpress_reset_post', $user );
141
  }
142
 
143
  /**
144
- * Overwrite the password, because we actually reset it after this email goes out
 
 
145
  */
146
  public function hijack_mail( $args ) {
147
  if ( preg_match( '/Your new WordPress (blog|site) has been successfully set up at/i', $args['message'] ) ) {
@@ -152,24 +165,26 @@ class WordPress_Reset {
152
  }
153
 
154
  /**
155
- * admin_print_scripts action hook operations
156
- * Enqueue jQuery to the head
 
157
  */
158
  public function admin_js() {
159
  wp_enqueue_script( 'jquery' );
160
  }
161
 
162
  /**
163
- * admin_footer action hook operations
164
- * Do some jQuery stuff to warn the user before submission
 
165
  */
166
  public function footer_js() { ?>
167
  <script type="text/javascript">
168
  /* <![CDATA[ */
169
  jQuery('#wordpress_reset_submit').click(function(){
170
- if ( jQuery('#wordpress_reset_confirm').val() == 'reset' ) {
171
- var message = 'This action is not reversable.\n\nClicking "OK" will reset your database back to it\'s defaults. Click "Cancel" to abort.'
172
- var reset = confirm(message);
173
  if ( reset ) {
174
  jQuery('#wordpress_reset_form').submit();
175
  } else {
@@ -177,49 +192,59 @@ class WordPress_Reset {
177
  return false;
178
  }
179
  } else {
180
- alert('Invalid confirmation word. Please type the word \'reset\' in the confirmation field.');
181
  return false;
182
  }
183
- });
184
  /* ]]> */
185
  </script>
186
  <?php
187
  }
188
 
189
  /**
190
- * admin_menu action hook operations
191
- * Add the settings page
 
192
  */
193
  public function add_page() {
194
- if ( current_user_can( 'level_10' ) && function_exists( 'add_management_page' ) )
195
- $hook = add_management_page( 'Reset', 'Reset', 'level_10', 'wordpress-reset', array( &$this, 'admin_page' ) );
196
- add_action( "admin_print_scripts-{$hook}", array( &$this, 'admin_js' ) );
197
- add_action( "admin_footer-{$hook}", array( &$this, 'footer_js' ) );
 
 
 
 
 
 
 
 
198
  }
199
 
200
  /**
201
- * add_option_page callback operations
202
- * The settings page
 
203
  */
204
- function admin_page() {
205
  global $current_user, $reactivate_wp_reset_additional;
206
- if ( isset( $_POST['wordpress_reset_confirm'] ) && $_POST['wordpress_reset_confirm'] != 'reset' ) {
207
- echo '<div class="error fade"><p><strong>Invalid confirmation word. Please type the word \'reset\' in the confirmation field.</strong></p></div>';
208
  } elseif ( isset( $_POST['_wpnonce'] ) ) {
209
- echo '<div class="error fade"><p><strong>Invalid nonce. Please try again.</strong></p></div>';
210
  }
211
 
212
  $missing = array();
213
  if ( ! empty( $reactivate_wp_reset_additional ) ) {
214
  foreach ( $reactivate_wp_reset_additional as $key => $plugin ) {
215
  if ( is_wp_error( validate_plugin( $plugin ) ) ) {
216
- unset( $reactivate_wp_reset_additional[$key] );
217
  $missing[] = $plugin;
218
  }
219
  }
220
  }
221
 
222
- $will_reactivate = ( defined( 'REACTIVATE_WP_RESET') && REACTIVATE_WP_RESET === true ) ? true : false;
223
  ?>
224
  <div class="wrap">
225
  <div id="icon-tools" class="icon32"><br /></div>
@@ -227,16 +252,19 @@ class WordPress_Reset {
227
  <h2><?php esc_html_e( 'Details about the reset', 'wp-reset' ); ?></h2>
228
  <p><strong><?php esc_html_e( 'After completing this reset you will be taken to the dashboard.', 'wp-reset' ); ?></strong></p>
229
  <?php $admin = get_user_by( 'login', 'admin' ); ?>
230
- <?php if ( ! isset( $admin->user_login ) || $admin->user_level < 10 ) : $user = $current_user; ?>
 
 
231
  <p><?php printf( esc_html__( 'The "admin" user does not exist. The user %s will be recreated using its current password with user level 10.', 'wp-reset' ), '<strong>' . esc_html( $user->user_login ) . '</strong>' ); ?></p>
232
  <?php else : ?>
233
  <p><?php esc_html_e( 'The "admin" user exists and will be recreated with its current password.', 'wp-reset' ); ?></p>
234
  <?php endif; ?>
235
  <?php if ( $will_reactivate ) : ?>
236
- <p><?php _e( 'This plugin <strong>will be automatically reactivated</strong> after the reset.', 'wp-reset' ); ?></p>
237
  <?php else : ?>
238
- <p><?php _e( 'This plugin <strong>will not be automatically reactivated</strong> after the reset.', 'wp-reset' ); ?></p>
239
- <p><?php printf( esc_html__( 'To have this plugin auto-reactivate, add %1s to your %2s file.', 'wp-reset' ), '<span class="code"><code>define( \'REACTIVATE_WP_RESET\', true );</code></span>', '<span class="code">wp-config.php</span>' ); ?></p>
 
240
  <?php endif; ?>
241
  <?php if ( ! empty( $reactivate_wp_reset_additional ) ) : ?>
242
  <?php esc_html_e( 'The following additional plugins will be reactivated:', 'wp-reset' ); ?>
@@ -258,6 +286,7 @@ class WordPress_Reset {
258
  </ul>
259
  <?php endif; ?>
260
  <h3><?php esc_html_e( 'Reset', 'wp-reset' ); ?></h3>
 
261
  <p><?php printf( esc_html__( 'Type %s in the confirmation field to confirm the reset and then click the reset button:', 'wp-reset' ), '<strong>reset</strong>' ); ?></p>
262
  <form id="wordpress_reset_form" action="" method="post">
263
  <?php wp_nonce_field( 'wordpress_reset' ); ?>
@@ -272,8 +301,7 @@ class WordPress_Reset {
272
  }
273
  }
274
 
275
- // Instantiate the class
276
- $WordPress_Reset = new WordPress_Reset();
277
-
278
- // End if for is_admin
279
- endif;
1
  <?php
2
+ /**
3
+ * Plugin Name: WordPress Reset
4
+ * Plugin URI: http://sivel.net/wordpress/wordpress-reset/
5
+ * Description: Resets the WordPress database back to it's defaults. Deletes all customizations and content. Does not modify files only resets the database.
6
+ * Author: Aristeides Stathopoulos, Matt Martz
7
+ * Version: 1.4.1
8
+ * Author URI: https://aristeides.com
9
+ *
10
+ * WordPress Reset is released under the GNU General Public License (GPL)
11
+ * http://www.gnu.org/licenses/gpl-2.0.txt
12
+ *
13
+ * @package wordpress-reset
14
+ */
15
+
16
+ /**
17
+ * The main WordPress_Reset class.
18
+ */
19
  class WordPress_Reset {
20
+
21
  /**
22
+ * Constructor. Contains Action/Filter Hooks.
23
+ *
24
+ * @access public
25
  */
26
  public function __construct() {
27
  add_action( 'admin_menu', array( $this, 'add_page' ) );
32
  }
33
 
34
  /**
 
35
  * While this plugin is active put a link to the reset page in the favorites drop down.
36
+ *
37
+ * @access public
38
+ * @param array $actions An array of actions for the favorites.
39
+ * @return array
40
  */
41
  public function favorites( $actions ) {
42
  $reset['tools.php?page=wordpress-reset'] = array( esc_html__( 'WordPress Reset' ), 'level_10' );
44
  }
45
 
46
  /**
47
+ * While this plugin is active put a link to the reset page in the admin bar under the site title.
48
+ *
49
+ * @access public
50
  */
51
  public function admin_bar_link() {
52
  global $wp_admin_bar;
55
  'parent' => 'site-name',
56
  'id' => 'wordpress-reset',
57
  'title' => 'Reset Site',
58
+ 'href' => admin_url( 'tools.php?page=wordpress-reset' ),
59
  )
60
  );
61
  }
62
 
63
  /**
 
64
  * Checks for wordpress_reset post value and if there deletes all wp tables
65
+ * and performs an install, also populating the users previous password.
66
  */
67
  public function admin_init() {
68
  global $current_user;
69
 
70
+ $wordpress_reset = ( isset( $_POST['wordpress_reset'] ) && 'true' == $_POST['wordpress_reset'] );
71
+ $wordpress_reset_confirm = ( isset( $_POST['wordpress_reset_confirm'] ) && 'reset' == $_POST['wordpress_reset_confirm'] );
72
+ $valid_nonce = ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wordpress_reset' ) );
73
 
74
  if ( $wordpress_reset && $wordpress_reset_confirm && $valid_nonce ) {
75
+ require_once ABSPATH . '/wp-admin/includes/upgrade.php';
76
 
77
  $blogname = get_option( 'blogname' );
78
  $admin_email = get_option( 'admin_email' );
79
  $blog_public = get_option( 'blog_public' );
80
 
81
+ if ( 'admin' !== $current_user->user_login ) {
82
  $user = get_user_by( 'login', 'admin' );
83
  }
84
 
137
  }
138
 
139
  /**
140
+ * Inform the user that WordPress has been successfully reset.
141
+ *
142
+ * @access public
143
  */
144
  public function reset_notice() {
145
  $user = get_user_by( 'id', 1 );
146
+ printf(
147
+ /* translators: The username. */
148
+ '<div id="message" class="updated fade"><p><strong>' . esc_html__( 'WordPress has been reset back to defaults. The user "%s" was recreated with its previous password.', 'wp-reset' ) . '</strong></p></div>',
149
+ esc_html( $user->user_login )
150
+ );
151
  do_action( 'wordpress_reset_post', $user );
152
  }
153
 
154
  /**
155
+ * Overwrite the password, because we actually reset it after this email goes out.
156
+ *
157
+ * @access public
158
  */
159
  public function hijack_mail( $args ) {
160
  if ( preg_match( '/Your new WordPress (blog|site) has been successfully set up at/i', $args['message'] ) ) {
165
  }
166
 
167
  /**
168
+ * Enqueue jQuery.
169
+ *
170
+ * @access public
171
  */
172
  public function admin_js() {
173
  wp_enqueue_script( 'jquery' );
174
  }
175
 
176
  /**
177
+ * Warn the user before submission.
178
+ *
179
+ * @access public
180
  */
181
  public function footer_js() { ?>
182
  <script type="text/javascript">
183
  /* <![CDATA[ */
184
  jQuery('#wordpress_reset_submit').click(function(){
185
+ if ( 'reset' === jQuery('#wordpress_reset_confirm').val() ) {
186
+ var message = '<?php esc_html_e( 'This action is not reversable. Clicking OK will reset your database back to the defaults. Click Cancel to abort.', 'wp-reset' ); ?>',
187
+ reset = confirm( message );
188
  if ( reset ) {
189
  jQuery('#wordpress_reset_form').submit();
190
  } else {
192
  return false;
193
  }
194
  } else {
195
+ alert( '<?php esc_html_e( 'Invalid confirmation word. Please type the word reset in the confirmation field.', 'wp-reset' ); ?>' );
196
  return false;
197
  }
198
+ } );
199
  /* ]]> */
200
  </script>
201
  <?php
202
  }
203
 
204
  /**
205
+ * Add the settings page.
206
+ *
207
+ * @access public
208
  */
209
  public function add_page() {
210
+
211
+ if ( current_user_can( 'activate_plugins' ) && function_exists( 'add_management_page' ) ) {
212
+ $hook = add_management_page(
213
+ esc_html__( 'Reset', 'wp-reset' ),
214
+ esc_html__( 'Reset', 'wp-reset' ),
215
+ 'activate_plugins',
216
+ 'wordpress-reset',
217
+ array( $this, 'admin_page' )
218
+ );
219
+ add_action( "admin_print_scripts-{$hook}", array( $this, 'admin_js' ) );
220
+ add_action( "admin_footer-{$hook}", array( $this, 'footer_js' ) );
221
+ }
222
  }
223
 
224
  /**
225
+ * The settings page.
226
+ *
227
+ * @access public
228
  */
229
+ public function admin_page() {
230
  global $current_user, $reactivate_wp_reset_additional;
231
+ if ( isset( $_POST['wordpress_reset_confirm'] ) && 'reset' !== $_POST['wordpress_reset_confirm'] ) {
232
+ echo '<div class="error fade"><p><strong>' . esc_html__( 'Invalid confirmation word. Please type the word "reset" in the confirmation field.', 'wp-reset' ) . '</strong></p></div>';
233
  } elseif ( isset( $_POST['_wpnonce'] ) ) {
234
+ echo '<div class="error fade"><p><strong>' . esc_html__( 'Invalid nonce. Please try again.', 'wp-reset' ) . '</strong></p></div>';
235
  }
236
 
237
  $missing = array();
238
  if ( ! empty( $reactivate_wp_reset_additional ) ) {
239
  foreach ( $reactivate_wp_reset_additional as $key => $plugin ) {
240
  if ( is_wp_error( validate_plugin( $plugin ) ) ) {
241
+ unset( $reactivate_wp_reset_additional[ $key ] );
242
  $missing[] = $plugin;
243
  }
244
  }
245
  }
246
 
247
+ $will_reactivate = ( defined( 'REACTIVATE_WP_RESET' ) && REACTIVATE_WP_RESET === true );
248
  ?>
249
  <div class="wrap">
250
  <div id="icon-tools" class="icon32"><br /></div>
252
  <h2><?php esc_html_e( 'Details about the reset', 'wp-reset' ); ?></h2>
253
  <p><strong><?php esc_html_e( 'After completing this reset you will be taken to the dashboard.', 'wp-reset' ); ?></strong></p>
254
  <?php $admin = get_user_by( 'login', 'admin' ); ?>
255
+ <?php if ( ! isset( $admin->user_login ) || $admin->user_level < 10 ) : ?>
256
+ <?php $user = $current_user; ?>
257
+ <?php /* translators: The username. */ ?>
258
  <p><?php printf( esc_html__( 'The "admin" user does not exist. The user %s will be recreated using its current password with user level 10.', 'wp-reset' ), '<strong>' . esc_html( $user->user_login ) . '</strong>' ); ?></p>
259
  <?php else : ?>
260
  <p><?php esc_html_e( 'The "admin" user exists and will be recreated with its current password.', 'wp-reset' ); ?></p>
261
  <?php endif; ?>
262
  <?php if ( $will_reactivate ) : ?>
263
+ <p><?php _e( 'This plugin <strong>will be automatically reactivated</strong> after the reset.', 'wp-reset' ); // WPCS: XSS ok. ?></p>
264
  <?php else : ?>
265
+ <p><?php _e( 'This plugin <strong>will not be automatically reactivated</strong> after the reset.', 'wp-reset' ); // WPCS: XSS ok. ?></p>
266
+ <?php /* translators: %1%s: The code to add. %2$s: wp-config.php. */ ?>
267
+ <p><?php printf( esc_html__( 'To have this plugin auto-reactivate, add %1$s to your %2$s file.', 'wp-reset' ), '<span class="code"><code>define( \'REACTIVATE_WP_RESET\', true );</code></span>', '<span class="code">wp-config.php</span>' ); ?></p>
268
  <?php endif; ?>
269
  <?php if ( ! empty( $reactivate_wp_reset_additional ) ) : ?>
270
  <?php esc_html_e( 'The following additional plugins will be reactivated:', 'wp-reset' ); ?>
286
  </ul>
287
  <?php endif; ?>
288
  <h3><?php esc_html_e( 'Reset', 'wp-reset' ); ?></h3>
289
+ <?php /* translators: reset. */ ?>
290
  <p><?php printf( esc_html__( 'Type %s in the confirmation field to confirm the reset and then click the reset button:', 'wp-reset' ), '<strong>reset</strong>' ); ?></p>
291
  <form id="wordpress_reset_form" action="" method="post">
292
  <?php wp_nonce_field( 'wordpress_reset' ); ?>
301
  }
302
  }
303
 
304
+ // Instantiate the class.
305
+ if ( is_admin() ) {
306
+ $wordpress_reset = new WordPress_Reset();
307
+ }