WordPress Database Reset - Version 3.0.2

Version Description

  • Fix for plugin page not showing up in tools menu (on some hosting providers)
  • Update how session tokens were being restored
  • Remove unnecessary nonce
  • Bump 'requires at least' to version 4.2
  • Change 'theme_data' to 'theme_plugin_data'
Download this release

Release Info

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

Code changes from version 3.0.1 to 3.0.2

class-db-reset-admin.php CHANGED
@@ -5,7 +5,6 @@ if ( ! class_exists( 'DB_Reset_Admin' ) ) :
5
  class DB_Reset_Admin {
6
 
7
  private $code;
8
- private $nonce;
9
  private $notice_error;
10
  private $notice_success;
11
  private $request;
@@ -28,7 +27,6 @@ if ( ! class_exists( 'DB_Reset_Admin' ) ) :
28
 
29
  private function set_view_variables() {
30
  $this->set_code();
31
- $this->set_nonce();
32
  $this->set_user();
33
  $this->set_wp_tables();
34
  }
@@ -37,10 +35,6 @@ if ( ! class_exists( 'DB_Reset_Admin' ) ) :
37
  $this->code = $this->generate_code();
38
  }
39
 
40
- private function set_nonce() {
41
- $this->nonce = strtolower( str_replace( '_', '-', __CLASS__ ) );
42
- }
43
-
44
  private function set_user() {
45
  $this->user = $this->resetter->get_user();
46
  }
@@ -112,7 +106,7 @@ if ( ! class_exists( 'DB_Reset_Admin' ) ) :
112
  $plugin_page = add_management_page(
113
  __( 'Database Reset', 'wordpress-database-reset' ),
114
  __( 'Database Reset', 'wordpress-database-reset' ),
115
- 'update_core',
116
  'database-reset',
117
  array( $this, 'render' )
118
  );
5
  class DB_Reset_Admin {
6
 
7
  private $code;
 
8
  private $notice_error;
9
  private $notice_success;
10
  private $request;
27
 
28
  private function set_view_variables() {
29
  $this->set_code();
 
30
  $this->set_user();
31
  $this->set_wp_tables();
32
  }
35
  $this->code = $this->generate_code();
36
  }
37
 
 
 
 
 
38
  private function set_user() {
39
  $this->user = $this->resetter->get_user();
40
  }
106
  $plugin_page = add_management_page(
107
  __( 'Database Reset', 'wordpress-database-reset' ),
108
  __( 'Database Reset', 'wordpress-database-reset' ),
109
+ 'manage_options',
110
  'database-reset',
111
  array( $this, 'render' )
112
  );
class-db-reset-command.php CHANGED
@@ -41,7 +41,7 @@ class DB_Reset_Command extends WP_CLI_Command {
41
  * @subcommand list
42
  */
43
  public function _list() {
44
- $tables = $this->resetter->get_wp_tables();
45
 
46
  foreach( $tables as $key => $value ) {
47
  WP_CLI::line( $key );
41
  * @subcommand list
42
  */
43
  public function _list() {
44
+ $tables = $this->get_wp_tables();
45
 
46
  foreach( $tables as $key => $value ) {
47
  WP_CLI::line( $key );
class-db-resetter.php CHANGED
@@ -6,7 +6,8 @@ if ( ! class_exists( 'DB_Resetter' ) ) :
6
 
7
  private $backup;
8
  private $blog_data;
9
- private $theme_data;
 
10
  private $preserved;
11
  private $selected;
12
  private $reactivate;
@@ -37,10 +38,11 @@ if ( ! class_exists( 'DB_Resetter' ) ) :
37
  private function set_backup() {
38
  $this->set_tables_to_preserve( $this->selected );
39
  $this->back_up_tables( $this->preserved );
 
40
  $this->set_blog_data();
41
 
42
- if ( $this->should_restore_theme_data() ) {
43
- $this->set_theme_data();
44
  }
45
  }
46
 
@@ -57,6 +59,14 @@ if ( ! class_exists( 'DB_Resetter' ) ) :
57
  }
58
  }
59
 
 
 
 
 
 
 
 
 
60
  private function set_blog_data() {
61
  $this->blog_data = array(
62
  'name' => get_option( 'blogname' ),
@@ -65,12 +75,12 @@ if ( ! class_exists( 'DB_Resetter' ) ) :
65
  );
66
  }
67
 
68
- private function should_restore_theme_data() {
69
  return ( 'true' === $this->reactivate );
70
  }
71
 
72
- private function set_theme_data() {
73
- $this->theme_data = array(
74
  'active-plugins' => get_option( 'active_plugins' ),
75
  'current-theme' => get_option( 'current_theme' ),
76
  'stylesheet' => get_option( 'stylesheet' ),
@@ -113,22 +123,13 @@ if ( ! class_exists( 'DB_Resetter' ) ) :
113
  $this->user->user_pass, $this->user->ID
114
  )
115
  );
116
-
117
- $this->remove_password_nag( $this->user->ID );
118
- }
119
-
120
- private function remove_password_nag( $user_id ) {
121
- if ( get_user_meta( $user_id, 'default_password_nag' ) ) {
122
- delete_user_meta( $user_id, 'default_password_nag' );
123
- }
124
  }
125
 
126
  private function restore_backup() {
127
  $this->delete_backup_table_rows( $this->preserved );
128
  $this->restore_backup_tables( $this->backup );
129
- $this->remove_user_session_tokens();
130
- $this->reset_user_auth_cookie();
131
- $this->assert_theme_data_needs_reset();
132
  }
133
 
134
  private function delete_backup_table_rows( array $tables ) {
@@ -156,37 +157,28 @@ if ( ! class_exists( 'DB_Resetter' ) ) :
156
  }
157
  }
158
 
159
- private function remove_user_session_tokens() {
160
- if ( get_user_meta( $this->user->ID, 'session_tokens' ) ) {
161
- delete_user_meta( $this->user->ID, 'session_tokens' );
162
- }
163
- }
164
-
165
- private function reset_user_auth_cookie() {
166
- if ( ! is_command_line() ) {
167
- wp_clear_auth_cookie();
168
- wp_set_auth_cookie( $this->user->ID );
169
- }
170
  }
171
 
172
- private function assert_theme_data_needs_reset() {
173
- if ( $this->should_restore_theme_data() ) {
174
- $this->restore_theme_data();
175
  }
176
  }
177
 
178
- private function restore_theme_data() {
179
- update_option( 'active_plugins', $this->theme_data['active-plugins'] );
180
- update_option( 'template', $this->theme_data['template'] );
181
- update_option( 'stylesheet', $this->theme_data['stylesheet'] );
182
 
183
- if ( ! empty( $this->theme_data['current-theme'] ) ) {
184
- update_option( 'current_theme', $this->theme_data['current-theme'] );
185
  }
186
  }
187
 
188
- public function set_reactivate( $with_theme_data ) {
189
- $this->reactivate = $with_theme_data;
190
  }
191
 
192
  private function set_wp_tables() {
6
 
7
  private $backup;
8
  private $blog_data;
9
+ private $theme_plugin_data;
10
+ private $user_data;
11
  private $preserved;
12
  private $selected;
13
  private $reactivate;
38
  private function set_backup() {
39
  $this->set_tables_to_preserve( $this->selected );
40
  $this->back_up_tables( $this->preserved );
41
+ $this->set_user_session_tokens();
42
  $this->set_blog_data();
43
 
44
+ if ( $this->should_restore_theme_plugin_data() ) {
45
+ $this->set_theme_plugin_data();
46
  }
47
  }
48
 
59
  }
60
  }
61
 
62
+ private function set_user_session_tokens() {
63
+ if ( get_user_meta( $this->user->ID, 'session_tokens' ) ) {
64
+ $this->user_data = array(
65
+ 'session_tokens' => get_user_meta( $this->user->ID, 'session_tokens', true )
66
+ );
67
+ }
68
+ }
69
+
70
  private function set_blog_data() {
71
  $this->blog_data = array(
72
  'name' => get_option( 'blogname' ),
75
  );
76
  }
77
 
78
+ private function should_restore_theme_plugin_data() {
79
  return ( 'true' === $this->reactivate );
80
  }
81
 
82
+ private function set_theme_plugin_data() {
83
+ $this->theme_plugin_data = array(
84
  'active-plugins' => get_option( 'active_plugins' ),
85
  'current-theme' => get_option( 'current_theme' ),
86
  'stylesheet' => get_option( 'stylesheet' ),
123
  $this->user->user_pass, $this->user->ID
124
  )
125
  );
 
 
 
 
 
 
 
 
126
  }
127
 
128
  private function restore_backup() {
129
  $this->delete_backup_table_rows( $this->preserved );
130
  $this->restore_backup_tables( $this->backup );
131
+ $this->restore_user_session_tokens();
132
+ $this->assert_theme_plugin_data_needs_reset();
 
133
  }
134
 
135
  private function delete_backup_table_rows( array $tables ) {
157
  }
158
  }
159
 
160
+ private function restore_user_session_tokens() {
161
+ add_user_meta( $this->user->ID, 'session_tokens', $this->user_data['session_tokens'] );
 
 
 
 
 
 
 
 
 
162
  }
163
 
164
+ private function assert_theme_plugin_data_needs_reset() {
165
+ if ( $this->should_restore_theme_plugin_data() ) {
166
+ $this->restore_theme_plugin_data();
167
  }
168
  }
169
 
170
+ private function restore_theme_plugin_data() {
171
+ update_option( 'active_plugins', $this->theme_plugin_data['active-plugins'] );
172
+ update_option( 'template', $this->theme_plugin_data['template'] );
173
+ update_option( 'stylesheet', $this->theme_plugin_data['stylesheet'] );
174
 
175
+ if ( ! empty( $this->theme_plugin_data['current-theme'] ) ) {
176
+ update_option( 'current_theme', $this->theme_plugin_data['current-theme'] );
177
  }
178
  }
179
 
180
+ public function set_reactivate( $with_theme_plugin_data ) {
181
+ $this->reactivate = $with_theme_plugin_data;
182
  }
183
 
184
  private function set_wp_tables() {
lib/helpers.php CHANGED
@@ -110,7 +110,6 @@ function db_reset_install( $blog_title, $user_name, $user_email, $public, $site_
110
  $user_password = wp_generate_password( 12, false );
111
  $message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
112
  $user_id = wp_create_user( $user_name, $user_password, $user_email );
113
- update_user_option( $user_id, 'default_password_nag', true, true );
114
  $email_password = true;
115
  } elseif ( ! $user_id ) {
116
  // Password has been provided
110
  $user_password = wp_generate_password( 12, false );
111
  $message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
112
  $user_id = wp_create_user( $user_name, $user_password, $user_email );
 
113
  $email_password = true;
114
  } elseif ( ! $user_id ) {
115
  // Password has been provided
readme.txt CHANGED
@@ -3,9 +3,9 @@
3
  Contributors: mousesports
4
  Tags: wordpress, database, reset, restore, setup, developer, theme, default, secure
5
  License: GPL2
6
- Requires at least: 3.0
7
  Tested up to: 4.3.1
8
- Stable tag: 3.0.1
9
 
10
  A plugin that allows you to skip the 5 minute installation and reset WordPress's database back to its original state.
11
 
@@ -43,6 +43,13 @@ Create a new post in the [WordPress Database Reset support forum](https://wordpr
43
  1. The WordPress Database Reset plugin page
44
 
45
  == Changelog ==
 
 
 
 
 
 
 
46
  = 3.0.1 =
47
  * Fix plugin disabled after update, thanks to Ulrich Pogson
48
  * Update the pot file
3
  Contributors: mousesports
4
  Tags: wordpress, database, reset, restore, setup, developer, theme, default, secure
5
  License: GPL2
6
+ Requires at least: 4.2
7
  Tested up to: 4.3.1
8
+ Stable tag: 3.0.2
9
 
10
  A plugin that allows you to skip the 5 minute installation and reset WordPress's database back to its original state.
11
 
43
  1. The WordPress Database Reset plugin page
44
 
45
  == Changelog ==
46
+ = 3.0.2 =
47
+ * Fix for plugin page not showing up in tools menu (on some hosting providers)
48
+ * Update how session tokens were being restored
49
+ * Remove unnecessary nonce
50
+ * Bump 'requires at least' to version 4.2
51
+ * Change 'theme_data' to 'theme_plugin_data'
52
+
53
  = 3.0.1 =
54
  * Fix plugin disabled after update, thanks to Ulrich Pogson
55
  * Update the pot file
wp-reset.php CHANGED
@@ -3,14 +3,14 @@
3
  Plugin Name: WordPress Database Reset
4
  Plugin URI: https://github.com/chrisberthe/wordpress-database-reset
5
  Description: A plugin that allows you to skip the 5 minute installation and reset WordPress's database back to its original state.
6
- Version: 3.0.1
7
  Author: Chris Berthe
8
  Author URI: https://github.com/chrisberthe
9
  License: GNU General Public License
10
  Text-domain: wp-reset
11
  */
12
 
13
- define( 'DB_RESET_VERSION', '3.0.1' );
14
  define( 'DB_RESET_PATH', dirname( __FILE__ ) );
15
  define( 'DB_RESET_NAME', basename( DB_RESET_PATH ) );
16
  define( 'AUTOLOADER', DB_RESET_PATH . '/lib/class-plugin-autoloader.php' );
3
  Plugin Name: WordPress Database Reset
4
  Plugin URI: https://github.com/chrisberthe/wordpress-database-reset
5
  Description: A plugin that allows you to skip the 5 minute installation and reset WordPress's database back to its original state.
6
+ Version: 3.0.2
7
  Author: Chris Berthe
8
  Author URI: https://github.com/chrisberthe
9
  License: GNU General Public License
10
  Text-domain: wp-reset
11
  */
12
 
13
+ define( 'DB_RESET_VERSION', '3.0.2' );
14
  define( 'DB_RESET_PATH', dirname( __FILE__ ) );
15
  define( 'DB_RESET_NAME', basename( DB_RESET_PATH ) );
16
  define( 'AUTOLOADER', DB_RESET_PATH . '/lib/class-plugin-autoloader.php' );