Version Description
Download this release
Release Info
| Developer | WebFactory |
| Plugin | |
| Version | 1.0 |
| Comparing to | |
| See all releases | |
Version 1.0
- wp-reset.php +188 -0
wp-reset.php
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
Plugin Name: WP Reset
|
| 4 |
+
Plugin URI: https://plugins.svn.wordpress.org/wp-reset/trunk/WP-Reset/
|
| 5 |
+
Description: It's Resets the your database to the default installation and does not modify files. Deletes all customizations and content of wordpress.
|
| 6 |
+
Version: 1.0
|
| 7 |
+
Author: Bhupender Singh
|
| 8 |
+
Author URI: https://github.com/Bhupi188/
|
| 9 |
+
Text Domain: WP-Reset
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
if ( ! defined( 'ABSPATH' ) ){
|
| 13 |
+
exit; // Exit if accessed this file directly
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
if ( is_admin() ) {
|
| 17 |
+
|
| 18 |
+
define( 'REACTIVATE_THE_WP_RESET', true );
|
| 19 |
+
|
| 20 |
+
class WPReset {
|
| 21 |
+
|
| 22 |
+
function WPReset() {
|
| 23 |
+
add_action( 'admin_menu', array( &$this, 'add_set_page' ) );
|
| 24 |
+
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
| 25 |
+
add_filter( 'favorite_actions', array( &$this, 'action_favorite' ), 100 );
|
| 26 |
+
add_action( 'wp_before_admin_bar_render', array( &$this, 'link_admin_bar' ) );
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Checks wp_reset post value and performs an installation.
|
| 30 |
+
function admin_init() {
|
| 31 |
+
global $current_user;
|
| 32 |
+
|
| 33 |
+
$wp_reset = ( isset( $_POST['wp_reset'] ) && $_POST['wp_reset'] == 'true' ) ? true : false;
|
| 34 |
+
$wp_reset_confirm = ( isset( $_POST['wp_reset_confirm'] ) && $_POST['wp_reset_confirm'] == 'wp-reset' ) ? true : false;
|
| 35 |
+
$valid_nonce = ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wp_reset' ) ) ? true : false;
|
| 36 |
+
|
| 37 |
+
if ( $wp_reset && $wp_reset_confirm && $valid_nonce ) {
|
| 38 |
+
require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
|
| 39 |
+
|
| 40 |
+
$blogname = get_option( 'blogname' );
|
| 41 |
+
$admin_email = get_option( 'admin_email' );
|
| 42 |
+
$blog_public = get_option( 'blog_public' );
|
| 43 |
+
|
| 44 |
+
if ( $current_user->user_login != 'admin' )
|
| 45 |
+
$user = get_user_by( 'login', 'admin' );
|
| 46 |
+
|
| 47 |
+
if ( empty( $user->user_level ) || $user->user_level < 10 )
|
| 48 |
+
$user = $current_user;
|
| 49 |
+
|
| 50 |
+
global $wpdb;
|
| 51 |
+
|
| 52 |
+
$prefix = str_replace( '_', '\_', $wpdb->prefix );
|
| 53 |
+
$tables = $wpdb->get_col( "SHOW TABLES LIKE '{$prefix}%'" );
|
| 54 |
+
foreach ( $tables as $table ) {
|
| 55 |
+
$wpdb->query( "DROP TABLE $table" );
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
$result = wp_install( $blogname, $user->user_login, $user->user_email, $blog_public );
|
| 59 |
+
extract( $result, EXTR_SKIP );
|
| 60 |
+
|
| 61 |
+
$query = $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = '".$user->user_pass."', user_activation_key = '' WHERE ID = '".$user_id."' ");
|
| 62 |
+
$wpdb->query( $query );
|
| 63 |
+
|
| 64 |
+
$get_user_meta = function_exists( 'get_user_meta' ) ? 'get_user_meta' : 'get_usermeta';
|
| 65 |
+
$update_user_meta = function_exists( 'update_user_meta' ) ? 'update_user_meta' : 'update_usermeta';
|
| 66 |
+
|
| 67 |
+
if ( $get_user_meta( $user_id, 'default_password_nag' ) )
|
| 68 |
+
$update_user_meta( $user_id, 'default_password_nag', false );
|
| 69 |
+
|
| 70 |
+
if ( $get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) )
|
| 71 |
+
$update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false );
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
if ( defined( 'REACTIVATE_THE_WP_RESET' ) && REACTIVATE_THE_WP_RESET === true )
|
| 75 |
+
@activate_plugin( plugin_basename( __FILE__ ) );
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
wp_clear_auth_cookie();
|
| 79 |
+
|
| 80 |
+
wp_set_auth_cookie( $user_id );
|
| 81 |
+
|
| 82 |
+
wp_redirect( admin_url()."?wp-reset=wp-reset" );
|
| 83 |
+
exit();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if ( array_key_exists( 'wp-reset', $_GET ) && stristr( $_SERVER['HTTP_REFERER'], 'wp-reset' ) )
|
| 87 |
+
add_action( 'admin_notices', array( &$this, 'my_wordpress_successfully_reset' ) );
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// admin_menu action hook operations & Add the settings page
|
| 91 |
+
function add_set_page() {
|
| 92 |
+
if ( current_user_can( 'level_10' ) && function_exists( 'add_management_page' ) )
|
| 93 |
+
$hook = add_management_page( 'WP Reset', 'WP Reset', 'level_10', 'wp-reset', array( &$this, 'admin_page' ) );
|
| 94 |
+
add_action( "admin_print_scripts-{$hook}", array( &$this, 'admin_script' ) );
|
| 95 |
+
add_action( "admin_footer-{$hook}", array( &$this, 'footer_script' ) );
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
function action_favorite( $actions ) {
|
| 99 |
+
$reset['tools.php?page=wp-reset'] = array( 'WP Reset', 'level_10' );
|
| 100 |
+
return array_merge( $reset, $actions );
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
function link_admin_bar() {
|
| 104 |
+
global $wp_admin_bar;
|
| 105 |
+
$wp_admin_bar->add_menu(
|
| 106 |
+
array(
|
| 107 |
+
'parent' => 'site-name',
|
| 108 |
+
'id' => 'wp-reset',
|
| 109 |
+
'title' => 'WP Reset',
|
| 110 |
+
'href' => admin_url( 'tools.php?page=wp-reset' )
|
| 111 |
+
)
|
| 112 |
+
);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// Inform the user that WordPress has been successfully reset
|
| 116 |
+
function my_wordpress_successfully_reset() {
|
| 117 |
+
$user = get_user_by( 'id', 1 );
|
| 118 |
+
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>';
|
| 119 |
+
do_action( 'wordpress_reset_post', $user );
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
function admin_script() {
|
| 123 |
+
wp_enqueue_script( 'jquery' );
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
function footer_script() {
|
| 127 |
+
?>
|
| 128 |
+
<script type="text/javascript">
|
| 129 |
+
jQuery('#wp_reset_submit').click(function(){
|
| 130 |
+
if ( jQuery('#wp_reset_confirm').val() == 'wp-reset' ) {
|
| 131 |
+
var message = 'This action is not reversable.\n\nClicking "OK" will reset your database back to it\'s defaults. Click "Cancel" to abort.'
|
| 132 |
+
var reset = confirm(message);
|
| 133 |
+
if ( reset ) {
|
| 134 |
+
jQuery('#wp_reset_form').submit();
|
| 135 |
+
} else {
|
| 136 |
+
jQuery('#wp_reset').val('false');
|
| 137 |
+
return false;
|
| 138 |
+
}
|
| 139 |
+
} else {
|
| 140 |
+
alert('Invalid confirmation. Please type \'wp-reset\' in the confirmation field.');
|
| 141 |
+
return false;
|
| 142 |
+
}
|
| 143 |
+
});
|
| 144 |
+
</script>
|
| 145 |
+
<?php
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// add_option_page callback operations
|
| 149 |
+
function admin_page() {
|
| 150 |
+
global $current_user;
|
| 151 |
+
if ( isset( $_POST['wp_reset_confirm'] ) && $_POST['wp_reset_confirm'] != 'wp-reset' )
|
| 152 |
+
echo '<div class="error fade"><p><strong>Invalid confirmation. Please type \'wp-reset\' in the confirmation field.</strong></p></div>';
|
| 153 |
+
elseif ( isset( $_POST['_wpnonce'] ) )
|
| 154 |
+
echo '<div class="error fade"><p><strong>Invalid wpnonce. Please try again.</strong></p></div>';
|
| 155 |
+
|
| 156 |
+
?>
|
| 157 |
+
<div class="wrap">
|
| 158 |
+
<div id="icon-tools" class="icon32"><br /></div>
|
| 159 |
+
<h2>WP Reset</h2>
|
| 160 |
+
<p><strong>After completing this reset you will be taken to the dashboard.</strong></p>
|
| 161 |
+
|
| 162 |
+
<?php $admin = get_user_by( 'login', 'admin' ); ?>
|
| 163 |
+
<?php if ( ! isset( $admin->user_login ) || $admin->user_level < 10 ) : $user = $current_user; ?>
|
| 164 |
+
<p>The 'admin' user does not exist. The user '<strong><?php echo esc_html( $user->user_login ); ?></strong>' will be recreated with its <strong>current password</strong> with user level 10.</p>
|
| 165 |
+
<?php else : ?>
|
| 166 |
+
|
| 167 |
+
<p>The '<strong>admin</strong>' user exists and will be recreated with its <strong>current password</strong>.</p>
|
| 168 |
+
<?php endif; ?>
|
| 169 |
+
<p>This plugin <strong>will be automatically reactivated</strong> after the reset operation.</p>
|
| 170 |
+
|
| 171 |
+
<hr/>
|
| 172 |
+
<h3>Reset</h3>
|
| 173 |
+
<p>Type <strong>wp-reset</strong> in the confirmation field to confirm the reset and then click the Reset button:</p>
|
| 174 |
+
<form id="wp_reset_form" action="" method="post" autocomplete="off">
|
| 175 |
+
<?php wp_nonce_field( 'wp_reset' ); ?>
|
| 176 |
+
<input id="wp_reset" type="hidden" name="wp_reset" value="true" />
|
| 177 |
+
<input id="wp_reset_confirm" type="text" name="wp_reset_confirm" value="" maxlength="8" />
|
| 178 |
+
<input id="wp_reset_submit" style="width: 80px;" type="submit" name="Submit" class="button-primary" value="Reset" />
|
| 179 |
+
|
| 180 |
+
</form>
|
| 181 |
+
</div>
|
| 182 |
+
<?php
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
$WPReset = new WPReset();
|
| 187 |
+
|
| 188 |
+
}
|
