Version Description
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 | sivel |
| Plugin | |
| Version | 1.3 |
| Comparing to | |
| See all releases | |
Code changes from version 1.2 to 1.3
- readme.txt +33 -15
- wordpress-reset.php +143 -81
readme.txt
CHANGED
|
@@ -1,24 +1,22 @@
|
|
| 1 |
=== WordPress Reset ===
|
| 2 |
-
Contributors: sivel
|
| 3 |
Donate Link: http://sivel.net/donate
|
| 4 |
Tags: wordpress-reset, wordpress, reset, admin
|
| 5 |
-
Requires at least: 2.
|
| 6 |
-
Tested up to: 3.
|
| 7 |
-
Stable tag: 1.
|
| 8 |
|
| 9 |
-
Resets the WordPress database back to it's defaults.
|
| 10 |
|
| 11 |
== Description ==
|
| 12 |
|
| 13 |
-
Resets the WordPress database back to it's defaults.
|
| 14 |
|
| 15 |
This plugin is very helpful for plugin and theme developers.
|
| 16 |
|
| 17 |
-
If the admin user exists and has level_10 permissions it will be recreated with its current password and email address.
|
| 18 |
|
| 19 |
-
The plugin will add an entry to the
|
| 20 |
-
|
| 21 |
-
Props to [Jonathan Dingman](http://www.ginside.com/) for the idea behind this plugin, testing and feedback.
|
| 22 |
|
| 23 |
== Installation ==
|
| 24 |
|
|
@@ -27,9 +25,20 @@ Props to [Jonathan Dingman](http://www.ginside.com/) for the idea behind this pl
|
|
| 27 |
|
| 28 |
== Frequently Asked Questions ==
|
| 29 |
|
| 30 |
-
= How can I
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
== Upgrade ==
|
| 35 |
|
|
@@ -39,16 +48,25 @@ Open the wordpress-reset.php file in an editor and modify the line that reads `v
|
|
| 39 |
|
| 40 |
== Usage ==
|
| 41 |
|
| 42 |
-
1. Visit the WordPress Reset Tools page by either clicking the link in the
|
| 43 |
1. Type 'reset' in the text field and click reset.
|
| 44 |
|
| 45 |
== Upgrade Notice ==
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
|
| 49 |
== Changelog ==
|
| 50 |
|
| 51 |
-
= 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
* Updates to fix deprecated notices for WP 3.0
|
| 53 |
* Updates for 3.0 to disable password nag
|
| 54 |
* Modify new blog email to not include the generated password
|
| 1 |
=== WordPress Reset ===
|
| 2 |
+
Contributors: sivel
|
| 3 |
Donate Link: http://sivel.net/donate
|
| 4 |
Tags: wordpress-reset, wordpress, reset, admin
|
| 5 |
+
Requires at least: 2.8
|
| 6 |
+
Tested up to: 3.3
|
| 7 |
+
Stable tag: 1.3
|
| 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 |
|
| 11 |
== Description ==
|
| 12 |
|
| 13 |
+
Resets the WordPress database back to it's defaults. Deletes all customizations and content. Does not modify files only resets the database.
|
| 14 |
|
| 15 |
This plugin is very helpful for plugin and theme developers.
|
| 16 |
|
| 17 |
+
If the admin user exists and has level_10 permissions it will be recreated with its current password and email address. If the admin user does not exist or is a dummy account without admin permissions the username that is logged in will be recreated with its email address and current password. The blog name is also kept.
|
| 18 |
|
| 19 |
+
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.
|
|
|
|
|
|
|
| 20 |
|
| 21 |
== Installation ==
|
| 22 |
|
| 25 |
|
| 26 |
== Frequently Asked Questions ==
|
| 27 |
|
| 28 |
+
= How can I get this plugin to automatically reactive after the reset? =
|
| 29 |
+
|
| 30 |
+
Add `define( 'REACTIVATE_WP_RESET', true );` to `wp-config.php` above `/* That's all, stop editing! Happy blogging. */`
|
| 31 |
+
|
| 32 |
+
= Can this plugin reactivate other plugins automatically after performing the reset? =
|
| 33 |
|
| 34 |
+
Add an array called `$reactivate_wp_reset_additional` to the global scope by placing it in `wp-config.php` above `/* That's all, stop editing! Happy blogging. */` that contains the plugin basenames of the plugins to activate, such as:
|
| 35 |
+
|
| 36 |
+
`
|
| 37 |
+
$reactivate_wp_reset_additional = array(
|
| 38 |
+
'hello.php',
|
| 39 |
+
'akismet/akismet.php'
|
| 40 |
+
);
|
| 41 |
+
`
|
| 42 |
|
| 43 |
== Upgrade ==
|
| 44 |
|
| 48 |
|
| 49 |
== Usage ==
|
| 50 |
|
| 51 |
+
1. Visit the WordPress Reset Tools page by either clicking the link in the Admin Bar or Tools>WordPress Reset
|
| 52 |
1. Type 'reset' in the text field and click reset.
|
| 53 |
|
| 54 |
== Upgrade Notice ==
|
| 55 |
|
| 56 |
+
= 1.3 =
|
| 57 |
+
|
| 58 |
+
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
|
| 59 |
|
| 60 |
== Changelog ==
|
| 61 |
|
| 62 |
+
= 1.3 (2012-01-29): =
|
| 63 |
+
* Fixes a deprecated notice in WordPress 3.3 when using get_userdatabylogin
|
| 64 |
+
* Removes the $auto_reactivate variable
|
| 65 |
+
* Look for REACTIVATE_WP_RESET constant to be defined in wp-config.php for auto reactivation after reset
|
| 66 |
+
* Look for global $reactivate_wp_reset_additional for additional plugins to auto reactivate after reset
|
| 67 |
+
* Add a Reset link to the admin bar under the site title
|
| 68 |
+
|
| 69 |
+
= 1.2 (2010-04-04): =
|
| 70 |
* Updates to fix deprecated notices for WP 3.0
|
| 71 |
* Updates for 3.0 to disable password nag
|
| 72 |
* Modify new blog email to not include the generated password
|
wordpress-reset.php
CHANGED
|
@@ -2,116 +2,145 @@
|
|
| 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.
|
| 6 |
Author: Matt Martz
|
| 7 |
-
Version: 1.
|
| 8 |
Author URI: http://sivel.net/
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
*/
|
| 14 |
|
| 15 |
// Only run the code if we are in the admin
|
| 16 |
if ( is_admin() ) :
|
| 17 |
|
| 18 |
class WordPressReset {
|
| 19 |
-
// Set to true by default, this allows the plugin to be automatically reactivated after the reset
|
| 20 |
-
var $auto_reactivate = true;
|
| 21 |
-
|
| 22 |
// Action/Filter Hooks
|
| 23 |
function WordPressReset() {
|
| 24 |
-
add_action('admin_menu', array(&$this, 'add_page'));
|
| 25 |
-
add_action('
|
| 26 |
-
|
| 27 |
-
add_action('
|
| 28 |
-
add_filter('
|
| 29 |
-
add_filter('wp_mail', array(&$this, 'hijack_mail'), 1);
|
| 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 |
-
function favorites($actions) {
|
| 35 |
-
$reset['tools.php?page=wordpress-reset'] = array('WordPress Reset', 'level_10');
|
| 36 |
-
return array_merge($reset, $actions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
-
//
|
| 40 |
// Checks for wordpress_reset post value and if there deletes all wp tables
|
| 41 |
// and performs an install, populating the users previous password also
|
| 42 |
-
function
|
| 43 |
global $current_user;
|
| 44 |
-
if ( isset($_POST['wordpress_reset']) && $_POST['wordpress_reset'] == 'true' && isset($_POST['wordpress_reset_confirm']) && $_POST['wordpress_reset_confirm'] == 'reset' ) {
|
| 45 |
-
require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
if ( $current_user->user_login != 'admin' )
|
| 52 |
-
$user =
|
| 53 |
-
|
|
|
|
| 54 |
$user = $current_user;
|
| 55 |
|
| 56 |
-
global $wpdb;
|
| 57 |
-
$tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'");
|
| 58 |
-
foreach ($tables as $table) {
|
| 59 |
-
$wpdb->query("DROP TABLE $table");
|
| 60 |
}
|
| 61 |
|
| 62 |
-
$result = wp_install($blogname, $user->user_login, $user->user_email, $blog_public);
|
| 63 |
-
extract($result, EXTR_SKIP);
|
| 64 |
|
| 65 |
-
$query = $wpdb->prepare("UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user_id);
|
| 66 |
-
$wpdb->query($query);
|
| 67 |
|
| 68 |
-
$get_user_meta = function_exists('get_user_meta') ? 'get_user_meta' : 'get_usermeta';
|
| 69 |
-
$update_user_meta = function_exists('update_user_meta') ? 'update_user_meta' : 'update_usermeta';
|
| 70 |
|
| 71 |
-
if ( $get_user_meta($user_id, 'default_password_nag') )
|
| 72 |
-
$update_user_meta($user_id, 'default_password_nag', false);
|
| 73 |
-
if ( $get_user_meta($user_id, $wpdb->prefix . 'default_password_nag') )
|
| 74 |
-
$update_user_meta($user_id, $wpdb->prefix . 'default_password_nag', false);
|
| 75 |
|
| 76 |
-
if ( $
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
wp_clear_auth_cookie();
|
| 80 |
-
wp_set_auth_cookie($user_id);
|
| 81 |
|
| 82 |
-
wp_redirect(admin_url() . '?reset');
|
| 83 |
exit();
|
| 84 |
}
|
| 85 |
|
| 86 |
-
if ( array_key_exists('reset', $_GET) && stristr($_SERVER['HTTP_REFERER'], 'wordpress-reset') ) {
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
| 93 |
// Overwrite the password, because we actually reset it after this email goes out
|
| 94 |
-
function hijack_mail($args) {
|
| 95 |
-
if (
|
| 96 |
-
$args['message'] =
|
|
|
|
|
|
|
| 97 |
return $args;
|
| 98 |
}
|
| 99 |
|
| 100 |
-
//
|
| 101 |
// Enqueue jQuery to the head
|
| 102 |
-
function
|
| 103 |
-
wp_enqueue_script('jquery');
|
| 104 |
}
|
| 105 |
|
| 106 |
// admin_footer action hook operations
|
| 107 |
// Do some jQuery stuff to warn the user before submission
|
| 108 |
-
function
|
| 109 |
?>
|
| 110 |
<script type="text/javascript">
|
| 111 |
/* <![CDATA[ */
|
| 112 |
jQuery('#wordpress_reset_submit').click(function(){
|
| 113 |
if ( jQuery('#wordpress_reset_confirm').val() == 'reset' ) {
|
| 114 |
-
var message = 'This action is not reversable.\n\nClicking "OK" will reset your database back to it\'s defaults.
|
| 115 |
var reset = confirm(message);
|
| 116 |
if ( reset ) {
|
| 117 |
jQuery('#wordpress_reset_form').submit();
|
|
@@ -120,7 +149,7 @@ class WordPressReset {
|
|
| 120 |
return false;
|
| 121 |
}
|
| 122 |
} else {
|
| 123 |
-
alert('Invalid confirmation word.
|
| 124 |
return false;
|
| 125 |
}
|
| 126 |
});
|
|
@@ -132,38 +161,72 @@ class WordPressReset {
|
|
| 132 |
// admin_menu action hook operations
|
| 133 |
// Add the settings page
|
| 134 |
function add_page() {
|
| 135 |
-
if ( current_user_can('level_10') && function_exists('add_management_page') )
|
| 136 |
-
add_management_page('
|
| 137 |
-
|
|
|
|
| 138 |
}
|
| 139 |
|
| 140 |
// add_option_page callback operations
|
| 141 |
// The settings page
|
| 142 |
function admin_page() {
|
| 143 |
-
global $current_user;
|
| 144 |
-
if ( isset($_POST['wordpress_reset_confirm']) && $_POST['wordpress_reset_confirm'] != 'reset' )
|
| 145 |
-
echo '<div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
?>
|
| 147 |
<div class="wrap">
|
| 148 |
-
<
|
| 149 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
<form id="wordpress_reset_form" action="" method="post">
|
|
|
|
| 151 |
<input id="wordpress_reset" type="hidden" name="wordpress_reset" value="true" />
|
| 152 |
-
|
| 153 |
-
<
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
<?php
|
| 157 |
-
$admin = get_userdatabylogin('admin');
|
| 158 |
-
if ( ! isset($admin->user_login) || $admin->user_level < 10 ) :
|
| 159 |
-
$user = $current_user;
|
| 160 |
-
?>
|
| 161 |
-
<li>The 'admin' user does not exist. The user '<strong><?php echo $user->user_login; ?></strong>' will be recreated with its current password with user level 10.</li>
|
| 162 |
-
<?php else : ?>
|
| 163 |
-
<li>The '<strong>admin</strong>' user exists and will be recreated with its current password.</li>
|
| 164 |
-
<?php endif; ?>
|
| 165 |
-
<li>This plugin <strong>will<?php echo $this->auto_reactivate ? '</strong> ' : ' not</strong> ';?>be automatically reactivated after the reset.</li>
|
| 166 |
-
</ul>
|
| 167 |
</form>
|
| 168 |
</div>
|
| 169 |
<?php
|
|
@@ -175,4 +238,3 @@ $WordPressReset = new WordPressReset();
|
|
| 175 |
|
| 176 |
// End if for is_admin
|
| 177 |
endif;
|
| 178 |
-
?>
|
| 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.3
|
| 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() ) :
|
| 17 |
|
| 18 |
class WordPressReset {
|
|
|
|
|
|
|
|
|
|
| 19 |
// Action/Filter Hooks
|
| 20 |
function WordPressReset() {
|
| 21 |
+
add_action( 'admin_menu', array( &$this, 'add_page' ) );
|
| 22 |
+
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
| 23 |
+
add_filter( 'favorite_actions', array( &$this, 'favorites' ), 100 );
|
| 24 |
+
add_action( 'wp_before_admin_bar_render', array( &$this, 'admin_bar_link' ) );
|
| 25 |
+
add_filter( 'wp_mail', array( &$this, 'hijack_mail' ), 1 );
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
// favorite_actions filter hook operations
|
| 29 |
// While this plugin is active put a link to the reset page in the favorites drop down.
|
| 30 |
+
function favorites( $actions ) {
|
| 31 |
+
$reset['tools.php?page=wordpress-reset'] = array( 'WordPress Reset', 'level_10' );
|
| 32 |
+
return array_merge( $reset, $actions );
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// wp_before_admin_bar_render action hook operations
|
| 36 |
+
// While this plugin is active put a link to the reset page in the admin bar under the site title
|
| 37 |
+
function admin_bar_link() {
|
| 38 |
+
global $wp_admin_bar;
|
| 39 |
+
$wp_admin_bar->add_menu(
|
| 40 |
+
array(
|
| 41 |
+
'parent' => 'site-name',
|
| 42 |
+
'id' => 'wordpress-reset',
|
| 43 |
+
'title' => 'Reset Site',
|
| 44 |
+
'href' => admin_url( 'tools.php?page=wordpress-reset' )
|
| 45 |
+
)
|
| 46 |
+
);
|
| 47 |
}
|
| 48 |
|
| 49 |
+
// admin_init action hook operations
|
| 50 |
// Checks for wordpress_reset post value and if there deletes all wp tables
|
| 51 |
// and performs an install, populating the users previous password also
|
| 52 |
+
function admin_init() {
|
| 53 |
global $current_user;
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
$wordpress_reset = ( isset( $_POST['wordpress_reset'] ) && $_POST['wordpress_reset'] == 'true' ) ? true : false;
|
| 56 |
+
$wordpress_reset_confirm = ( isset( $_POST['wordpress_reset_confirm'] ) && $_POST['wordpress_reset_confirm'] == 'reset' ) ? true : false;
|
| 57 |
+
$valid_nonce = ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wordpress_reset' ) ) ? true : false;
|
| 58 |
+
|
| 59 |
+
if ( $wordpress_reset && $wordpress_reset_confirm && $valid_nonce ) {
|
| 60 |
+
require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
|
| 61 |
+
|
| 62 |
+
$blogname = get_option( 'blogname' );
|
| 63 |
+
$admin_email = get_option( 'admin_email' );
|
| 64 |
+
$blog_public = get_option( 'blog_public' );
|
| 65 |
|
| 66 |
if ( $current_user->user_login != 'admin' )
|
| 67 |
+
$user = get_user_by( 'login', 'admin' );
|
| 68 |
+
|
| 69 |
+
if ( ! isset( $user ) || $user->user_level < 10 )
|
| 70 |
$user = $current_user;
|
| 71 |
|
| 72 |
+
global $wpdb, $reactivate_wp_reset_additional;
|
| 73 |
+
$tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}%'" );
|
| 74 |
+
foreach ( $tables as $table ) {
|
| 75 |
+
$wpdb->query( "DROP TABLE $table" );
|
| 76 |
}
|
| 77 |
|
| 78 |
+
$result = wp_install( $blogname, $user->user_login, $user->user_email, $blog_public );
|
| 79 |
+
extract( $result, EXTR_SKIP );
|
| 80 |
|
| 81 |
+
$query = $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user_id );
|
| 82 |
+
$wpdb->query( $query );
|
| 83 |
|
| 84 |
+
$get_user_meta = function_exists( 'get_user_meta' ) ? 'get_user_meta' : 'get_usermeta';
|
| 85 |
+
$update_user_meta = function_exists( 'update_user_meta' ) ? 'update_user_meta' : 'update_usermeta';
|
| 86 |
|
| 87 |
+
if ( $get_user_meta( $user_id, 'default_password_nag' ) )
|
| 88 |
+
$update_user_meta( $user_id, 'default_password_nag', false );
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
if ( $get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) )
|
| 91 |
+
$update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false );
|
| 92 |
+
|
| 93 |
+
if ( defined( 'REACTIVATE_WP_RESET' ) && REACTIVATE_WP_RESET === true )
|
| 94 |
+
@activate_plugin( plugin_basename( __FILE__ ) );
|
| 95 |
+
|
| 96 |
+
if ( ! empty( $reactivate_wp_reset_additional ) ) {
|
| 97 |
+
foreach ( $reactivate_wp_reset_additional as $plugin ) {
|
| 98 |
+
$plugin = plugin_basename( $plugin );
|
| 99 |
+
if ( ! is_wp_error( validate_plugin( $plugin ) ) )
|
| 100 |
+
@activate_plugin( $plugin );
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
|
| 104 |
wp_clear_auth_cookie();
|
| 105 |
+
wp_set_auth_cookie( $user_id );
|
| 106 |
|
| 107 |
+
wp_redirect( admin_url() . '?reset' );
|
| 108 |
exit();
|
| 109 |
}
|
| 110 |
|
| 111 |
+
if ( array_key_exists( 'reset', $_GET ) && stristr( $_SERVER['HTTP_REFERER'], 'wordpress-reset' ) ) {
|
| 112 |
+
add_action( 'admin_notices', function () {
|
| 113 |
+
$user = get_user_by( 'id', 1 );
|
| 114 |
+
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>';
|
| 115 |
+
do_action( 'wordpress_reset_post', $user );
|
| 116 |
+
} );
|
| 117 |
}
|
| 118 |
}
|
| 119 |
|
| 120 |
// Overwrite the password, because we actually reset it after this email goes out
|
| 121 |
+
function hijack_mail( $args ) {
|
| 122 |
+
if ( preg_match( '/Your new WordPress (blog|site) has been successfully set up at/i', $args['message'] ) ) {
|
| 123 |
+
$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'] );
|
| 124 |
+
$args['message'] = preg_replace( '/Password:.+/', 'Password: previously specified password', $args['message'] );
|
| 125 |
+
}
|
| 126 |
return $args;
|
| 127 |
}
|
| 128 |
|
| 129 |
+
// admin_print_scripts action hook operations
|
| 130 |
// Enqueue jQuery to the head
|
| 131 |
+
function admin_js() {
|
| 132 |
+
wp_enqueue_script( 'jquery' );
|
| 133 |
}
|
| 134 |
|
| 135 |
// admin_footer action hook operations
|
| 136 |
// Do some jQuery stuff to warn the user before submission
|
| 137 |
+
function footer_js() {
|
| 138 |
?>
|
| 139 |
<script type="text/javascript">
|
| 140 |
/* <![CDATA[ */
|
| 141 |
jQuery('#wordpress_reset_submit').click(function(){
|
| 142 |
if ( jQuery('#wordpress_reset_confirm').val() == 'reset' ) {
|
| 143 |
+
var message = 'This action is not reversable.\n\nClicking "OK" will reset your database back to it\'s defaults. Click "Cancel" to abort.'
|
| 144 |
var reset = confirm(message);
|
| 145 |
if ( reset ) {
|
| 146 |
jQuery('#wordpress_reset_form').submit();
|
| 149 |
return false;
|
| 150 |
}
|
| 151 |
} else {
|
| 152 |
+
alert('Invalid confirmation word. Please type the word \'reset\' in the confirmation field.');
|
| 153 |
return false;
|
| 154 |
}
|
| 155 |
});
|
| 161 |
// admin_menu action hook operations
|
| 162 |
// Add the settings page
|
| 163 |
function add_page() {
|
| 164 |
+
if ( current_user_can( 'level_10' ) && function_exists( 'add_management_page' ) )
|
| 165 |
+
$hook = add_management_page( 'Reset', 'Reset', 'level_10', 'wordpress-reset', array( &$this, 'admin_page' ) );
|
| 166 |
+
add_action( "admin_print_scripts-{$hook}", array( &$this, 'admin_js' ) );
|
| 167 |
+
add_action( "admin_footer-{$hook}", array( &$this, 'footer_js' ) );
|
| 168 |
}
|
| 169 |
|
| 170 |
// add_option_page callback operations
|
| 171 |
// The settings page
|
| 172 |
function admin_page() {
|
| 173 |
+
global $current_user, $reactivate_wp_reset_additional;
|
| 174 |
+
if ( isset( $_POST['wordpress_reset_confirm'] ) && $_POST['wordpress_reset_confirm'] != 'reset' )
|
| 175 |
+
echo '<div class="error fade"><p><strong>Invalid confirmation word. Please type the word \'reset\' in the confirmation field.</strong></p></div>';
|
| 176 |
+
elseif ( isset( $_POST['_wpnonce'] ) )
|
| 177 |
+
echo '<div class="error fade"><p><strong>Invalid nonce. Please try again.</strong></p></div>';
|
| 178 |
+
|
| 179 |
+
$missing = array();
|
| 180 |
+
if ( ! empty( $reactivate_wp_reset_additional ) ) {
|
| 181 |
+
foreach ( $reactivate_wp_reset_additional as $key => $plugin ) {
|
| 182 |
+
if ( is_wp_error( validate_plugin( $plugin ) ) ) {
|
| 183 |
+
unset( $reactivate_wp_reset_additional[$key] );
|
| 184 |
+
$missing[] = $plugin;
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
$will_reactivate = ( defined( 'REACTIVATE_WP_RESET') && REACTIVATE_WP_RESET === true ) ? true : false;
|
| 190 |
?>
|
| 191 |
<div class="wrap">
|
| 192 |
+
<div id="icon-tools" class="icon32"><br /></div>
|
| 193 |
+
<h2>Reset</h2>
|
| 194 |
+
<h3>Details about the reset</h3>
|
| 195 |
+
<p><strong>After completing this reset you will taken to the dashboard.</strong></p>
|
| 196 |
+
<?php $admin = get_user_by( 'login', 'admin' ); ?>
|
| 197 |
+
<?php if ( ! isset( $admin->user_login ) || $admin->user_level < 10 ) : $user = $current_user; ?>
|
| 198 |
+
<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>
|
| 199 |
+
<?php else : ?>
|
| 200 |
+
<p>The '<strong>admin</strong>' user exists and will be recreated with its <strong>current password</strong>.</p>
|
| 201 |
+
<?php endif; ?>
|
| 202 |
+
<p>This plugin <strong>will<?php echo $will_reactivate ? '' : ' not';?> be automatically reactivated</strong> after the reset. <?php echo ! $will_reactivate ? "To have this plugin auto-reactivate add <span class='code'>define( 'REACTIVATE_WP_RESET', true );</span> to <span class='code'>wp-config.php</span>." : ''; ?></p>
|
| 203 |
+
<?php if ( ! empty( $reactivate_wp_reset_additional ) ) : ?>
|
| 204 |
+
<p>The following <strong>additional plugins will be reactivated</strong>:
|
| 205 |
+
<ul style="list-style-type: disc;">
|
| 206 |
+
<?php foreach ( $reactivate_wp_reset_additional as $plugin ) : $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); ?>
|
| 207 |
+
<li style="margin: 5px 0 0 30px;"><strong><?php echo esc_html( $plugin_data['Name'] ); ?></strong></li>
|
| 208 |
+
<?php endforeach; unset( $reactivate_wp_reset_additional, $plugin, $plugin_data ); ?>
|
| 209 |
+
</ul>
|
| 210 |
+
</p>
|
| 211 |
+
<?php endif; ?>
|
| 212 |
+
<?php if ( ! empty( $missing ) ) : ?>
|
| 213 |
+
<p>The following <strong>additional plugins are missing</strong> and cannot be reactivated:
|
| 214 |
+
<ul style="list-style-type: disc;">
|
| 215 |
+
<?php foreach ( $missing as $plugin ) : ?>
|
| 216 |
+
<li style="margin: 5px 0 0 30px;"><strong><?php echo esc_html( $plugin ); ?></strong></li>
|
| 217 |
+
<?php endforeach; unset( $missing, $plugin ); ?>
|
| 218 |
+
</ul>
|
| 219 |
+
</p>
|
| 220 |
+
<?php endif; ?>
|
| 221 |
+
<h3>Reset</h3>
|
| 222 |
+
<p>Type '<strong>reset</strong>' in the confirmation field to confirm the reset and then click the reset button:</p>
|
| 223 |
<form id="wordpress_reset_form" action="" method="post">
|
| 224 |
+
<?php wp_nonce_field( 'wordpress_reset' ); ?>
|
| 225 |
<input id="wordpress_reset" type="hidden" name="wordpress_reset" value="true" />
|
| 226 |
+
<input id="wordpress_reset_confirm" type="text" name="wordpress_reset_confirm" value="" />
|
| 227 |
+
<p class="submit">
|
| 228 |
+
<input id="wordpress_reset_submit" style="width: 80px;" type="submit" name="Submit" class="button-primary" value="Reset" />
|
| 229 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
</form>
|
| 231 |
</div>
|
| 232 |
<?php
|
| 238 |
|
| 239 |
// End if for is_admin
|
| 240 |
endif;
|
|
|
