PluginProbe
WP Reset / 1.1
WP Reset v1.1
trunk 1.0 1.1 1.11 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.77 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.90 All 42 releases
wp-reset / wp-reset.php

wp-reset.php in WP Reset 1.1, at wp-reset.php

303 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Reset
4 Plugin URI: https://wordpress.org/plugins/wp-reset/
5 Description: Reset the site to default installation values without modifying any files. Deletes all customizations and content.
6 Version: 1.11
7 Author: WebFactory Ltd
8 Author URI: https://www.webfactoryltd.com/
9 Text Domain: wp-reset
10
11 Copyright 2015 - 2018 Web factory Ltd (email: wpreset@webfactoryltd.com)
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License, version 2, as
15 published by the Free Software Foundation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27
28 if ( ! defined( 'ABSPATH' ) ){
29 exit;
30 }
31
32
33 define( 'REACTIVATE_THE_WP_RESET', true );
34
35
36 if ( is_admin() ) {
37
38 class WPReset {
39 static $version = 1.11;
40
41
42 function __construct() {
43 add_action( 'admin_menu', array( &$this, 'add_tools_page' ) );
44 add_action( 'admin_init', array( &$this, 'admin_init' ) );
45 add_action( 'wp_before_admin_bar_render', array( &$this, 'link_admin_bar' ) );
46 add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text') );
47 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'plugin_action_links') );
48 } // WPReset
49
50
51 // Checks wp_reset post value and performs an installation.
52 function admin_init() {
53 global $current_user, $wpdb;
54
55 if ( !current_user_can('administrator') ) {
56 return;
57 }
58
59 $wp_reset_confirm = ( isset( $_POST['wp_reset_confirm'] ) && $_POST['wp_reset_confirm'] == 'reset' ) ? true : false;
60 $valid_nonce = ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wp_reset' ) ) ? true : false;
61
62 if ( $wp_reset_confirm && $valid_nonce ) {
63 @require_once ABSPATH . '/wp-admin/includes/upgrade.php';
64
65 $blogname = get_option( 'blogname' );
66 $blog_public = get_option( 'blog_public' );
67 $wplang = get_option( 'wplang' );
68 $siteurl = get_option ( 'siteurl' );
69 $home = get_option ( 'home' );
70
71 $prefix = str_replace( '_', '\_', $wpdb->prefix );
72 $tables = $wpdb->get_col( "SHOW TABLES LIKE '{$prefix}%'" );
73 foreach ( $tables as $table ) {
74 $wpdb->query( "DROP TABLE $table" );
75 }
76
77 $result = wp_install( $blogname, $current_user->user_login, $current_user->user_email, $blog_public, '', '', $wplang);
78 $user_id = $result['user_id'];
79
80 $query = $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s, user_activation_key = '' WHERE ID = %d LIMIT 1", array($current_user->user_pass, $user_id));
81 $wpdb->query( $query );
82
83 update_option('siteurl', $siteurl);
84 update_option('home', $home);
85
86 if ( get_user_meta( $user_id, 'default_password_nag' ) )
87 update_user_meta( $user_id, 'default_password_nag', false );
88
89 if ( get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) )
90 update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false );
91
92
93 if ( defined( 'REACTIVATE_THE_WP_RESET' ) && REACTIVATE_THE_WP_RESET === true )
94 @activate_plugin( plugin_basename( __FILE__ ) );
95
96
97 wp_clear_auth_cookie();
98 wp_set_auth_cookie( $user_id );
99
100 wp_redirect( admin_url() . "?wp-reset=wp-reset" );
101 exit();
102 }
103
104 if ( array_key_exists( 'wp-reset', $_GET ) && stristr( $_SERVER['HTTP_REFERER'], 'wp-reset' ) )
105 add_action( 'admin_notices', array( &$this, 'successfully_reset' ) );
106 } // admin_init
107
108
109 // add settings link to plugins page
110 static function plugin_action_links($links) {
111 $settings_link = '<a href="' . admin_url('tools.php?page=wp-reset') . '" title="' . __('Reset WordPress', 'wp-reset') . '">' . __('Reset WordPress', 'wp-reset') . '</a>';
112
113 array_unshift($links, $settings_link);
114
115 return $links;
116 } // plugin_action_links
117
118
119 // test if we're on plugin's page
120 function is_plugin_page() {
121 $current_screen = get_current_screen();
122
123 if ($current_screen->id == 'tools_page_wp-reset') {
124 return true;
125 } else {
126 return false;
127 }
128 } // is_plugin_page
129
130
131 // additional powered by text in admin footer; only on UCP page
132 function admin_footer_text($text) {
133 if (!$this->is_plugin_page()) {
134 return $text;
135 }
136
137 $text = '<i><a href="https://wordpress.org/plugins/wp-reset/" title="' . __('Visit WP Reset page for more info', 'wp-reset') . '" target="_blank">WP Reset</a> v' . self::$version . ' by <a href="https://www.webfactoryltd.com/" title="' . __('Visit our site to get more great plugins', 'wp-reset'). '" target="_blank">WebFactory Ltd</a>.</i> '. $text;
138
139 return $text;
140 } // admin_footer_text
141
142
143 // admin_menu action hook operations & Add the settings page
144 function add_tools_page() {
145 $hook = add_management_page( 'WP Reset', 'WP Reset', 'administrator', 'wp-reset', array( &$this, 'admin_page' ) );
146 add_action( "admin_print_scripts-{$hook}", array( &$this, 'admin_script' ) );
147 add_action( "admin_footer-{$hook}", array( &$this, 'footer_script' ) );
148 } // add_tools_page
149
150
151 function load_textdomain() {
152 load_plugin_textdomain( 'wp-reset' );
153 } // load_textdomain
154
155
156 function link_admin_bar() {
157 global $wp_admin_bar;
158
159 if (!current_user_can('administrator')) {
160 return;
161 }
162
163 $wp_admin_bar->add_menu(
164 array(
165 'parent' => 'site-name',
166 'id' => 'wp-reset',
167 'title' => 'WP Reset',
168 'href' => admin_url( 'tools.php?page=wp-reset' )
169 )
170 );
171 } // link_admin_bar
172
173
174 // Inform the user that WordPress has been successfully reset
175 function successfully_reset() {
176 global $current_user;
177
178 echo '<div id="message" class="updated fade"><p>' . sprintf( __( '<b>Site has been reset</b> to default settings. User "%s" was restored with the password unchanged.', 'wp-reset' ), $current_user->user_login ) . '</p></div>';
179
180 } // successfully_reset
181
182
183 function admin_script() {
184 $localize = array('invalid_confirmation' => __('Invalid confirmation. Please type "reset" in the confirmation field.', 'wp-reset'),
185 'confirm1' => __('Clicking "OK" will reset your site to default values. All content will be lost. There is NO UNDO.', 'wp-reset'),
186 'confirm2' => __('Click "Cancel" to abort.', 'wp-reset'));
187
188 wp_enqueue_script( 'jquery' );
189 wp_localize_script('jquery', 'wp_reset', $localize);
190 } // admin_script
191
192
193 function footer_script() {
194 ?>
195 <script type="text/javascript">
196 jQuery('#wp_reset_submit').click(function(e) {
197 if ( jQuery('#wp_reset_confirm').val() == 'reset' ) {
198 message = wp_reset.confirm1 + '\n' + wp_reset.confirm2;
199 reset = confirm(message);
200 if ( reset ) {
201 jQuery('#wp_reset_form').submit();
202 } else {
203 return false;
204 }
205 } else {
206 alert(wp_reset.invalid_confirmation);
207 return false;
208 }
209 });
210 </script>
211 <?php
212 } // footer_script
213
214
215 // add_option_page callback operations
216 function admin_page() {
217 global $current_user, $wpdb;
218
219 if (!current_user_can('administrator')) {
220 return;
221 }
222
223 if ( isset( $_POST['wp_reset_confirm'] ) && $_POST['wp_reset_confirm'] != 'reset' ) {
224 echo '<div class="error fade"><p>' . __('<b>Invalid confirmation code.</b> Please type "reset" in the confirmation field.', 'wp-reset') . '</p></div>';
225 } elseif ( isset( $_POST['_wpnonce'] ) && !wp_verify_nonce( $_POST['_wpnonce'], 'wp_reset' ) ) {
226 echo '<div class="error fade"><p>' . __('Something went wrong. Please refresh the page and try again.', 'wp-reset') . '</strong></p></div>';
227 }
228
229 ?>
230 <style type="text/css">
231 .plain-list {
232 margin-top: 5px;
233 list-style-type: circle;
234 list-style-position: inside;
235 }
236 .plain-list li {
237 text-indent: -18px;
238 padding-left: 23px;
239 line-height: 23px;
240 margin: 0;
241 }
242 .red {
243 color: red;
244 }
245 .green {
246 color: green;
247 }
248 </style>
249 <?php
250 echo '<div class="wrap">';
251 echo '<h1>WP Reset</h1>';
252
253 echo '<div class="card">';
254 echo '<h2>' . __('Please read carefully before proceeding. There is NO UNDO!', 'wp-reset') . '</h2>';
255 echo '<b class="red">' . __('Resetting will delete:', 'wp-reset') . '</b>';
256 echo '<ul class="plain-list">';
257 echo '<li>' . __('all posts, pages, custom post types, comments, media entries, users', 'wp-reset') . '</li>';
258 echo '<li>' . __('all default WP database tables', 'wp-reset') . '</li>';
259 echo '<li>' . sprintf(__('all custom database tables that have the same prefix "%s" as default tables in this installation', 'wp-reset'), $wpdb->prefix) . '</li>';
260 echo '</ul>';
261
262 echo '<b class="green">' . __('Resetting will not delete:', 'wp-reset') . '</b>';
263 echo '<ul class="plain-list">';
264 echo '<li>' . __('media files - they\'ll remain in the <i>wp-uploads</i> folder but will no longer be listed under Media', 'wp-reset') . '</li>';
265 echo '<li>' . __('no files are touched; plugins, themes, uploads - everything stays', 'wp-reset') . '</li>';
266 echo '<li>' . __('site title, WordPress address, site address, site language and search engine visibility settings', 'wp-reset') . '</li>';
267 echo '<li>' . sprintf(__('logged in user "%s" will be restored with the current password', 'wp-reset'), $current_user->user_login) . '</li>';
268 echo '</ul>';
269
270 echo '<b>' . __('What happens when I click the Reset button?', 'wp-reset') . '</b>';
271 echo '<ul class="plain-list">';
272 echo '<li>' . __('you will have to confirm the action one more time because there is NO UNDO', 'wp-reset') . '</li>';
273 echo '<li>' . __('everything will be reset; see bullets above for details', 'wp-reset') . '</li>';
274 echo '<li>' . __('site title, WordPress address, site address, site language, search engine visibility and current user will be restored', 'wp-reset') . '</li>';
275 echo '<li>' . __('you will be logged out, automatically logged in and taken to the admin dashboard', 'wp-reset') . '</li>';
276 echo '<li>' . __('WP Reset plugin will be reactivated', 'wp-reset') . '</li>';
277 echo '</ul>';
278 echo '</div>';
279
280 echo '<div class="card">';
281 echo '<h2>' . __('Reset', 'wp-reset') . '</h2>';
282 echo '<p>' . __('Type <b>reset</b> in the confirmation field to confirm the reset and then click the "Reset WordPress" button. <b>There is NO UNDO. No backups are made by this plugin.</b>', 'wp-reset') . '</p>';
283 echo '<p>' . sprintf(__('While doing work on your site we recommend installing the free <a href="%s" target="_blank">UnderConstructionPage</a> plugin. It helps with SEO and builds trust with visitors.', 'wp-reset'), 'https://wordpress.org/plugins/under-construction-page/') . '</p>';
284 echo '<form id="wp_reset_form" action="" method="post" autocomplete="off">';
285 wp_nonce_field( 'wp_reset' );
286 echo '<input id="wp_reset_confirm" type="text" name="wp_reset_confirm" placeholder="' . esc_attr__('Type in "reset"', 'wp-reset'). '" value="" autocomplete="off"> &nbsp;';
287 echo '<input id="wp_reset_submit" type="submit" name="submit" class="button-primary" value="' . __('Reset WordPress', 'wp-reset') . '">';
288 echo '</form>';
289 echo '</div>';
290
291 echo '<div class="card">';
292 echo '<h2>' . __('Please help us continue developing WP Reset', 'wp-reset') . '</h2>';
293 echo '<p>By <a href="https://wordpress.org/support/plugin/wp-reset/reviews/#new-post" target="_blank">rating the plugin</a> (which takes about 30 seconds :)) you help us keep going! Your ratings will ensoure the plugin is kept maintained, up-to-date and safe.<br><br>Thank you for your time!</p>';
294 echo '</div>';
295 echo '</div>';
296 } // admin_page
297 } // WPReset class
298
299 $WPReset = new WPReset();
300
301 add_action( 'plugins_loaded', array(&$WPReset, 'load_textdomain' ) );
302
303 } // is_admin