Changeset 3379908
- Timestamp:
- 10/17/2025 07:00:32 AM (5 months ago)
- Location:
- wordpress-reset
- Files:
-
- 19 added
- 2 edited
-
tags/1.5.0 (added)
-
tags/1.5.0/LICENSE (added)
-
tags/1.5.0/assets (added)
-
tags/1.5.0/assets/css (added)
-
tags/1.5.0/assets/css/wordpress-reset-admin.css (added)
-
tags/1.5.0/assets/js (added)
-
tags/1.5.0/assets/js/wordpress-reset.js (added)
-
tags/1.5.0/includes (added)
-
tags/1.5.0/includes/class-wpre-reset.php (added)
-
tags/1.5.0/readme.txt (added)
-
tags/1.5.0/wordpress-reset.php (added)
-
trunk/LICENSE (added)
-
trunk/assets (added)
-
trunk/assets/css (added)
-
trunk/assets/css/wordpress-reset-admin.css (added)
-
trunk/assets/js (added)
-
trunk/assets/js/wordpress-reset.js (added)
-
trunk/includes (added)
-
trunk/includes/class-wpre-reset.php (added)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/wordpress-reset.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wordpress-reset/trunk/readme.txt
r3362324 r3379908 1 === W PReset ===1 === WordPress Reset === 2 2 Contributors: aristath, sivel 3 3 Donate Link: http://aristath.github.io/donate 4 4 Tags: wordpress-reset, reset, admin 5 Requires at least: 2.85 Requires at least: 6.2 6 6 Tested up to: 6.8 7 Stable tag: 1. 4.37 Stable tag: 1.5.0 8 8 License: GPLv2 or later 9 9 License URI: http://gnu.org/licenses/gpl2.html 10 10 11 11 12 Resets the WordPress database back to it 's defaults. Deletes all customizations and content. Does not modify files only resets the database.12 Resets the WordPress database back to its defaults. Deletes all customizations and content. Does not modify files only resets the database. 13 13 14 14 == Description == 15 15 16 Resets the WordPress database back to it 's defaults. Deletes all customizations and content. Does not modify files only resets the database.16 Resets the WordPress database back to its defaults. Deletes all customizations and content. Does not modify files only resets the database. 17 17 18 18 This plugin is very helpful for plugin and theme developers. … … 21 21 22 22 The plugin will add an entry to the Admin Bar under the site title and has the ability to reactivate itself and other plugins after the reset. 23 24 **Database Compatibility:** This plugin supports both MySQL/MariaDB and SQLite databases. For SQLite installations, the reset process will delete the database file and redirect you to the WordPress installation screen. 23 25 24 26 == Installation == … … 44 46 ` 45 47 48 = Does this plugin work with SQLite databases? = 49 50 Yes! For SQLite databases, the plugin will delete the database file and redirect you to the WordPress installation screen. This means you'll need to set up WordPress from scratch after the reset, unlike MySQL/MariaDB installations where your admin user is automatically recreated. 51 46 52 == Upgrade == 47 53 … … 56 62 57 63 == Upgrade Notice == 64 65 = 1.5.0 = 66 Major update with SQLite database support, improved security, code modernization, and updated minimum requirements (WordPress 6.2+, PHP 7.4+) 58 67 59 68 = 1.3.3 = … … 71 80 72 81 == Changelog == 82 83 = 1.5.0 (2025-01-17): = 84 * Added full SQLite database compatibility including support for SQLite Database Integration plugin 85 * Modernized code to meet WordPress Coding Standards 86 * Added comprehensive PHPUnit test coverage 87 * Improved input sanitization and output escaping 88 * Refactored JavaScript to vanilla JS (removed jQuery dependency) 89 * Enhanced error handling with try-catch blocks 90 * Updated minimum requirements: WordPress 6.2+, PHP 7.4+ 73 91 74 92 = 1.4 = -
wordpress-reset/trunk/wordpress-reset.php
r3357594 r3379908 5 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 6 * Author: Aristeidis Stathopoulos, Matt Martz 7 * Version: 1. 4.37 * Version: 1.5.0 8 8 * Author URI: https://aristath.github.io 9 * Requires at least: 6.2 10 * Requires PHP: 7.4 11 * License: GPL-2.0-or-later 12 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 13 * Text Domain: wordpress-reset 9 14 * 10 15 * WordPress Reset is released under the GNU General Public License (GPL) … … 14 19 */ 15 20 16 / **17 * The main WordPress_Reset class. 18 */ 19 class WordPress_Reset { 21 // Exit if accessed directly. 22 if ( ! defined( 'ABSPATH' ) ) { 23 exit; 24 } 20 25 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' ) ); 28 \add_action( 'admin_init', array( $this, 'admin_init' ) ); 29 \add_action( 'wp_before_admin_bar_render', array( $this, 'admin_bar_link' ) ); 30 \add_filter( 'wp_mail', array( $this, 'hijack_mail' ), 1 ); 31 } 26 // Define plugin file constant. 27 if ( ! defined( 'WPRE_PLUGIN_FILE' ) ) { 28 define( 'WPRE_PLUGIN_FILE', __FILE__ ); 29 } 32 30 33 /** 34 * While this plugin is active put a link to the reset page in the admin bar under the site title. 35 * 36 * @access public 37 */ 38 public function admin_bar_link() { 39 global $wp_admin_bar; 40 $wp_admin_bar->add_menu( 41 array( 42 'parent' => 'site-name', 43 'id' => 'wordpress-reset', 44 'title' => \esc_html__( 'Reset Site', 'wp-reset' ), 45 'href' => \admin_url( 'tools.php?page=wordpress-reset' ), 46 ) 47 ); 48 } 49 50 /** 51 * Checks for wordpress_reset post value and if there deletes all wp tables 52 * and performs an install, also populating the users previous password. 53 */ 54 public function admin_init() { 55 global $current_user; 56 57 $wordpress_reset = ( isset( $_POST['wordpress_reset'] ) && 'true' == $_POST['wordpress_reset'] ); 58 $wordpress_reset_confirm = ( isset( $_POST['wordpress_reset_confirm'] ) && 'reset' == $_POST['wordpress_reset_confirm'] ); 59 $valid_nonce = ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wordpress_reset' ) ); 60 61 if ( $wordpress_reset && $wordpress_reset_confirm && $valid_nonce ) { 62 require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 63 64 $blogname = \get_option( 'blogname' ); 65 $blog_public = \get_option( 'blog_public' ); 66 67 if ( 'admin' !== $current_user->user_login ) { 68 $user = \get_user_by( 'login', 'admin' ); 69 } 70 71 if ( empty( $user->user_level ) || $user->user_level < 10 ) { 72 $user = $current_user; 73 } 74 75 global $wpdb, $reactivate_wp_reset_additional; 76 77 $prefix = \str_replace( '_', '\_', $wpdb->prefix ); 78 $tables = $wpdb->get_col( "SHOW TABLES LIKE '{$prefix}%'" ); 79 foreach ( $tables as $table ) { 80 $wpdb->query( "DROP TABLE $table" ); 81 } 82 83 $result = \wp_install( $blogname, $user->user_login, $user->user_email, $blog_public ); 84 extract( $result, \EXTR_SKIP ); 85 86 $query = $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user_id ); 87 $wpdb->query( $query ); 88 89 $get_user_meta = \function_exists( 'get_user_meta' ) ? 'get_user_meta' : 'get_usermeta'; 90 $update_user_meta = \function_exists( 'update_user_meta' ) ? 'update_user_meta' : 'update_usermeta'; 91 92 if ( $get_user_meta( $user_id, 'default_password_nag' ) ) { 93 $update_user_meta( $user_id, 'default_password_nag', false ); 94 } 95 96 if ( $get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) ) { 97 $update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false ); 98 } 99 100 if ( defined( 'REACTIVATE_WP_RESET' ) && \REACTIVATE_WP_RESET === true ) { 101 \activate_plugin( \plugin_basename( __FILE__ ) ); 102 } 103 104 if ( ! empty( $reactivate_wp_reset_additional ) ) { 105 foreach ( $reactivate_wp_reset_additional as $plugin ) { 106 $plugin = \plugin_basename( $plugin ); 107 if ( ! \is_wp_error( \validate_plugin( $plugin ) ) ) { 108 \activate_plugin( $plugin ); 109 } 110 } 111 } 112 113 \wp_clear_auth_cookie(); 114 \wp_set_auth_cookie( $user_id ); 115 116 \wp_redirect( \admin_url() . '?reset' ); 117 exit(); 118 } 119 120 if ( \array_key_exists( 'reset', $_GET ) && \stristr( $_SERVER['HTTP_REFERER'], 'wordpress-reset' ) ) { 121 \add_action( 'admin_notices', array( &$this, 'reset_notice' ) ); 122 } 123 } 124 125 /** 126 * Inform the user that WordPress has been successfully reset. 127 * 128 * @access public 129 */ 130 public function reset_notice() { 131 $user = \get_user_by( 'id', 1 ); 132 printf( 133 /* translators: The username. */ 134 '<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>', 135 \esc_html( $user->user_login ) 136 ); 137 \do_action( 'wordpress_reset_post', $user ); 138 } 139 140 /** 141 * Overwrite the password, because we actually reset it after this email goes out. 142 * 143 * @access public 144 */ 145 public function hijack_mail( $args ) { 146 if ( \preg_match( '/Your new WordPress (blog|site) has been successfully set up at/i', $args['message'] ) ) { 147 $args['message'] = \str_replace( 'Your new WordPress site has been successfully set up at:', 'Your WordPress site has been successfully reset, and can be accessed at:', $args['message'] ); 148 $args['message'] = \preg_replace( '/Password:.+/', 'Password: previously specified password', $args['message'] ); 149 } 150 return $args; 151 } 152 153 /** 154 * Enqueue jQuery. 155 * 156 * @access public 157 */ 158 public function admin_js() { 159 \wp_enqueue_script( 'jquery' ); 160 } 161 162 /** 163 * Warn the user before submission. 164 * 165 * @access public 166 */ 167 public function footer_js() { ?> 168 <script type="text/javascript"> 169 /* <![CDATA[ */ 170 jQuery('#wordpress_reset_submit').click(function(){ 171 if ( 'reset' === jQuery('#wordpress_reset_confirm').val() ) { 172 var reset = confirm( '<?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' ); ?>' ); 173 if ( reset ) { 174 jQuery('#wordpress_reset_form').submit(); 175 } else { 176 jQuery('#wordpress_reset').val('false'); 177 return false; 178 } 179 } else { 180 alert( '<?php esc_html_e( 'Invalid confirmation word. Please type the word reset in the confirmation field.', 'wp-reset' ); ?>' ); 181 return false; 182 } 183 } ); 184 /* ]]> */ 185 </script> 186 <?php 187 } 188 189 /** 190 * Add the settings page. 191 * 192 * @access public 193 */ 194 public function add_page() { 195 if ( \current_user_can( 'activate_plugins' ) && \function_exists( 'add_management_page' ) ) { 196 $hook = \add_management_page( 197 \esc_html__( 'Reset', 'wp-reset' ), 198 \esc_html__( 'Reset', 'wp-reset' ), 199 'activate_plugins', 200 'wordpress-reset', 201 array( $this, 'admin_page' ) 202 ); 203 \add_action( "admin_print_scripts-{$hook}", array( $this, 'admin_js' ) ); 204 \add_action( "admin_footer-{$hook}", array( $this, 'footer_js' ) ); 205 } 206 } 207 208 /** 209 * The settings page. 210 * 211 * @access public 212 */ 213 public function admin_page() { 214 global $current_user, $reactivate_wp_reset_additional; 215 if ( isset( $_POST['wordpress_reset_confirm'] ) && 'reset' !== $_POST['wordpress_reset_confirm'] ) { 216 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>'; 217 } elseif ( isset( $_POST['_wpnonce'] ) ) { 218 echo '<div class="error fade"><p><strong>' . \esc_html__( 'Invalid nonce. Please try again.', 'wp-reset' ) . '</strong></p></div>'; 219 } 220 221 $missing = array(); 222 if ( ! empty( $reactivate_wp_reset_additional ) ) { 223 foreach ( $reactivate_wp_reset_additional as $key => $plugin ) { 224 if ( \is_wp_error( \validate_plugin( $plugin ) ) ) { 225 unset( $reactivate_wp_reset_additional[ $key ] ); 226 $missing[] = $plugin; 227 } 228 } 229 } 230 231 $will_reactivate = ( defined( 'REACTIVATE_WP_RESET' ) && \REACTIVATE_WP_RESET === true ); 232 ?> 233 <div class="wrap"> 234 <div id="icon-tools" class="icon32"><br /></div> 235 <h1><?php \esc_html_e( 'Reset', 'wp-reset' ); ?></h1> 236 <h2><?php \esc_html_e( 'Details about the reset', 'wp-reset' ); ?></h2> 237 <p><strong><?php \esc_html_e( 'After completing this reset you will be taken to the dashboard.', 'wp-reset' ); ?></strong></p> 238 <?php $admin = \get_user_by( 'login', 'admin' ); ?> 239 <?php if ( ! isset( $admin->user_login ) || $admin->user_level < 10 ) : ?> 240 <?php $user = $current_user; ?> 241 <?php /* translators: The username. */ ?> 242 <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> 243 <?php else : ?> 244 <p><?php \esc_html_e( 'The "admin" user exists and will be recreated with its current password.', 'wp-reset' ); ?></p> 245 <?php endif; ?> 246 <?php if ( $will_reactivate ) : ?> 247 <p><?php \_e( 'This plugin <strong>will be automatically reactivated</strong> after the reset.', 'wp-reset' ); // WPCS: XSS ok. ?></p> 248 <?php else : ?> 249 <p><?php \_e( 'This plugin <strong>will not be automatically reactivated</strong> after the reset.', 'wp-reset' ); // WPCS: XSS ok. ?></p> 250 <?php /* translators: %1%s: The code to add. %2$s: wp-config.php. */ ?> 251 <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> 252 <?php endif; ?> 253 <?php if ( ! empty( $reactivate_wp_reset_additional ) ) : ?> 254 <?php \esc_html_e( 'The following additional plugins will be reactivated:', 'wp-reset' ); ?> 255 <ul style="list-style-type: disc;"> 256 <?php foreach ( $reactivate_wp_reset_additional as $plugin ) : ?> 257 <?php $plugin_data = \get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); ?> 258 <li style="margin: 5px 0 0 30px;"><strong><?php echo \esc_html( $plugin_data['Name'] ); ?></strong></li> 259 <?php endforeach; ?> 260 <?php unset( $reactivate_wp_reset_additional, $plugin, $plugin_data ); ?> 261 </ul> 262 <?php endif; ?> 263 <?php if ( ! empty( $missing ) ) : ?> 264 <?php \esc_html_e( 'The following additional plugins are missing and cannot be reactivated:', 'wp-reset' ); ?> 265 <ul style="list-style-type: disc;"> 266 <?php foreach ( $missing as $plugin ) : ?> 267 <li style="margin: 5px 0 0 30px;"><strong><?php echo \esc_html( $plugin ); ?></strong></li> 268 <?php endforeach; ?> 269 <?PHP unset( $missing, $plugin ); ?> 270 </ul> 271 <?php endif; ?> 272 <h3><?php \esc_html_e( 'Reset', 'wp-reset' ); ?></h3> 273 <?php /* translators: reset. */ ?> 274 <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> 275 <form id="wordpress_reset_form" action="" method="post"> 276 <?php \wp_nonce_field( 'wordpress_reset' ); ?> 277 <input id="wordpress_reset" type="hidden" name="wordpress_reset" value="true" /> 278 <input id="wordpress_reset_confirm" type="text" name="wordpress_reset_confirm" value="" /> 279 <p class="submit"> 280 <input id="wordpress_reset_submit" style="width: 80px;" type="submit" name="Submit" class="button-primary" value="<?php \esc_html_e( 'Reset' ); ?>" /> 281 </p> 282 </form> 283 </div> 284 <?php 285 } 286 } 31 // Include the main class. 32 require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpre-reset.php'; 287 33 288 34 // Instantiate the class. 289 35 if ( \is_admin() ) { 290 $wordpress_reset = new W ordPress_Reset();36 $wordpress_reset = new WPRE_Reset(); 291 37 }
Note: See TracChangeset
for help on using the changeset viewer.