add_menu( array( 'parent' => 'site-name', 'id' => 'wordpress-reset', 'title' => 'Reset Site', 'href' => admin_url( 'tools.php?page=wordpress-reset' ), ) ); } /** * Checks for wordpress_reset post value and if there deletes all wp tables * and performs an install, also populating the users previous password. */ public function admin_init() { global $current_user; $wordpress_reset = ( isset( $_POST['wordpress_reset'] ) && 'true' == $_POST['wordpress_reset'] ); $wordpress_reset_confirm = ( isset( $_POST['wordpress_reset_confirm'] ) && 'reset' == $_POST['wordpress_reset_confirm'] ); $valid_nonce = ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wordpress_reset' ) ); if ( $wordpress_reset && $wordpress_reset_confirm && $valid_nonce ) { require_once ABSPATH . '/wp-admin/includes/upgrade.php'; $blogname = get_option( 'blogname' ); $admin_email = get_option( 'admin_email' ); $blog_public = get_option( 'blog_public' ); if ( 'admin' !== $current_user->user_login ) { $user = get_user_by( 'login', 'admin' ); } if ( empty( $user->user_level ) || $user->user_level < 10 ) { $user = $current_user; } global $wpdb, $reactivate_wp_reset_additional; $prefix = str_replace( '_', '\_', $wpdb->prefix ); $tables = $wpdb->get_col( "SHOW TABLES LIKE '{$prefix}%'" ); foreach ( $tables as $table ) { $wpdb->query( "DROP TABLE $table" ); } $result = wp_install( $blogname, $user->user_login, $user->user_email, $blog_public ); extract( $result, EXTR_SKIP ); $query = $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user_id ); $wpdb->query( $query ); $get_user_meta = function_exists( 'get_user_meta' ) ? 'get_user_meta' : 'get_usermeta'; $update_user_meta = function_exists( 'update_user_meta' ) ? 'update_user_meta' : 'update_usermeta'; if ( $get_user_meta( $user_id, 'default_password_nag' ) ) { $update_user_meta( $user_id, 'default_password_nag', false ); } if ( $get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) ) { $update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false ); } if ( defined( 'REACTIVATE_WP_RESET' ) && REACTIVATE_WP_RESET === true ) { activate_plugin( plugin_basename( __FILE__ ) ); } if ( ! empty( $reactivate_wp_reset_additional ) ) { foreach ( $reactivate_wp_reset_additional as $plugin ) { $plugin = plugin_basename( $plugin ); if ( ! is_wp_error( validate_plugin( $plugin ) ) ) { activate_plugin( $plugin ); } } } wp_clear_auth_cookie(); wp_set_auth_cookie( $user_id ); wp_redirect( admin_url() . '?reset' ); exit(); } if ( array_key_exists( 'reset', $_GET ) && stristr( $_SERVER['HTTP_REFERER'], 'wordpress-reset' ) ) { add_action( 'admin_notices', array( &$this, 'reset_notice' ) ); } } /** * Inform the user that WordPress has been successfully reset. * * @access public */ public function reset_notice() { $user = get_user_by( 'id', 1 ); printf( /* translators: The username. */ '
' . esc_html__( 'WordPress has been reset back to defaults. The user "%s" was recreated with its previous password.', 'wp-reset' ) . '
' . esc_html__( 'Invalid confirmation word. Please type the word "reset" in the confirmation field.', 'wp-reset' ) . '
'; } elseif ( isset( $_POST['_wpnonce'] ) ) { echo '' . esc_html__( 'Invalid nonce. Please try again.', 'wp-reset' ) . '
user_login ) || $admin->user_level < 10 ) : ?>
' . esc_html( $user->user_login ) . '' ); ?>
will be automatically reactivated after the reset.', 'wp-reset' ); // WPCS: XSS ok. ?>
will not be automatically reactivated after the reset.', 'wp-reset' ); // WPCS: XSS ok. ?>
define( \'REACTIVATE_WP_RESET\', true );', 'wp-config.php' ); ?>
reset' ); ?>