body {
background: #1a1b26;
color: #f7768e;
font-family: system-ui, -apple-system, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.warning {
background: rgba(247, 118, 142, 0.1);
padding: 2rem;
border-radius: 8px;
border-left: 4px solid #f7768e;
max-width: 600px;
}
code {
background: rgba(0,0,0,0.2);
padding: 0.2em 0.4em;
border-radius: 3px;
font-family: monospace;
}
.example {
word-break: break-all;
}
⚠️ Security Warning
For security reasons, please rename this file from wp-recovery-tools.php
to something like:
wp-recovery-tools_YOUR-SECRET-PASSWORD.php
Example: wp-recovery-tools-' . $random_suffix . '.php
This helps prevent unauthorized access to your recovery tools.
');
}
?>
WP Recovery Tools
Error Cannot find wp-config.php file. Make sure this script is in the WordPress root directory.
");
}
// Define an array to store the extracted values
$conf = array();
// Iterate through each line
foreach ($lines as $line) {
// Check if the line contains 'define' and the specified constants
if (preg_match("/^define\(\s*'(DB_NAME|DB_USER|DB_PASSWORD|DB_HOST)',\s*(['\"])(.*?)\\2\s*\);/", $line, $conf_matches)) {
// Extract the constant and its value and store them in the $conf array
$conf[strtolower(str_replace('DB_', 'db_', $conf_matches[1]))] = $conf_matches[3];
} elseif (preg_match("/^\\\$table_prefix\s*=\s*['\"](.+?)['\"].*/", $line, $table_prefix)) {
$conf['table_prefix'] = $table_prefix[1];
}
}
if (empty($conf['db_name']) || empty($conf['db_user']) || empty($conf['db_host'])) {
die("Error Required database configuration not found in wp-config.php
");
}
return $conf;
}
// Replacement for wp_generate_password()
function generate_secure_password($length = 16)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_[]{}<>~+=';
$password = '';
for ($i = 0; $i < $length; $i++) {
$password .= $chars[random_int(0, strlen($chars) - 1)];
}
return $password;
}
// Replacement for wp_hash_password()
function hash_password($password)
{
require_once ABSPATH . WPINC . '/class-phpass.php';
$hasher = new PasswordHash(8, true);
return $hasher->HashPassword($password);
}
// Database connection
$config = get_wp_db_config();
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
$link = mysqli_connect($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']);
mysqli_set_charset($link, 'utf8mb4');
} catch (mysqli_sql_exception $e) {
error_log($e->getMessage());
die("Cannot connect to database Please verify your wp-config.php credentials.
{$e->getMessage()}
");
}
$wp_ = $config['table_prefix'];
// Handle form submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['reset_password'])) {
$user_id = intval($_POST['user_id']);
$new_password = generate_secure_password();
$hashed_password = hash_password($new_password);
$result = mysqli_query($link, "UPDATE `{$wp_}users` SET `user_pass` = '$hashed_password' WHERE `ID` = $user_id");
if ($result) {
echo "";
echo "
✅ Password reset successful ";
echo "
New password: $new_password
";
echo "
";
}
}
if (isset($_POST['add_admin'])) {
$username = mysqli_real_escape_string($link, $_POST['username']);
$email = mysqli_real_escape_string($link, $_POST['email']);
$password = generate_secure_password(16); // Using our custom function
$hashed_password = hash_password($password); // Using our custom function
// Check if username exists
$check_user = mysqli_query($link, "SELECT ID FROM `{$wp_}users` WHERE user_login = '$username' OR user_email = '$email'");
if (mysqli_num_rows($check_user) > 0) {
echo "";
echo "
❌ Error: Username or email already exists ";
echo "";
} else {
// Insert user
$result = mysqli_query($link, "INSERT INTO `{$wp_}users`
(`user_login`, `user_pass`, `user_email`, `user_registered`, `user_status`, `display_name`)
VALUES
('$username', '$hashed_password', '$email', NOW(), 0, '$username')");
if ($result) {
$user_id = mysqli_insert_id($link);
// Add user meta for admin role
$capabilities = serialize(array('administrator' => true));
mysqli_query($link, "INSERT INTO `{$wp_}usermeta`
(`user_id`, `meta_key`, `meta_value`)
VALUES
($user_id, '{$wp_}capabilities', '$capabilities')");
// Set user level to 10 (admin)
mysqli_query($link, "INSERT INTO `{$wp_}usermeta`
(`user_id`, `meta_key`, `meta_value`)
VALUES
($user_id, '{$wp_}user_level', '10')");
echo "";
echo "
✅ Admin user created successfully ";
echo "
Username: $username
";
echo "Password: $password
";
echo "
Please save these credentials immediately!
";
echo "
";
} else {
echo "";
echo "
❌ Error creating user ";
echo "
" . mysqli_error($link) . "
";
echo "
";
}
}
}
}
// Version Check
echo "";
echo "
System Information ";
echo "WordPress Version: $wp_version | PHP Version: " . phpversion() . " | MySQL Version: " . mysqli_get_server_info($link);
echo "";
// Handle form submissions for additional tools
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['repair_db'])) {
echo "";
echo "
🔧 Repairing Database Tables ";
$tables = mysqli_query($link, "SHOW TABLES LIKE '{$wp_}%'");
while ($table = mysqli_fetch_array($tables)) {
$repair = mysqli_query($link, "REPAIR TABLE `{$table[0]}`");
$optimize = mysqli_query($link, "OPTIMIZE TABLE `{$table[0]}`");
echo "
Repaired and optimized: {$table[0]}
";
}
echo "
";
}
if (isset($_POST['clear_cache'])) {
// Clear various WordPress caches
mysqli_query($link, "DELETE FROM `{$wp_}options` WHERE `option_name` LIKE '%_transient_%'");
echo "";
echo "
✅ Cache Cleared ";
echo "
Transients and cached data have been cleared.
";
echo "
";
}
if (isset($_POST['reset_permalinks'])) {
mysqli_query($link, "UPDATE `{$wp_}options` SET `option_value` = '' WHERE `option_name` = 'rewrite_rules'");
echo "";
echo "
✅ Permalinks Reset ";
echo "
Permalink structure has been reset. Please visit the Permalinks settings page to regenerate.
";
echo "
";
}
}
// Recovery Mode Section
echo "";
echo "
🔑 Recovery Mode ";
$result = mysqli_query($link, "SELECT * FROM `{$wp_}options` WHERE `option_name` = 'recovery_keys';");
$row = mysqli_fetch_row($result);
$option_id = $row[0];
$recovery_keys_arr = unserialize($row[2]);
if (isset($_GET['delete_rm_keys'])) {
mysqli_query($link, "UPDATE `{$wp_}options` SET `option_value`='" . serialize(array()) . "' WHERE `option_id`={$option_id};");
echo "
✅ All recovery links erased ";
} else {
$token = 'wp-rm-script-' . bin2hex(random_bytes(16));
$key = 'wp-rm-script-' . bin2hex(random_bytes(16));
$hashed_key = wp_hash_password($key);
$recovery_keys_arr[$token] = array('hashed_key' => $hashed_key, 'created_at' => time());
$serialized_recovery_keys = serialize($recovery_keys_arr);
$recovery_url = SITE_URL . '/wp-login.php?action=enter_recovery_mode&rm_token=' . $token . '&rm_key=' . $key;
mysqli_query($link, "UPDATE `{$wp_}options` SET `option_value`='{$serialized_recovery_keys}' WHERE `option_id`={$option_id};");
echo "
Enter Recovery Mode ";
echo "
Note: Links expire after a certain time and can only be used twice. Generate a new link by refreshing this page.
";
}
echo "
Erase All Recovery Links ";
echo "
";
// Users Section
echo "";
echo "
👥 User Management ";
$users = mysqli_query($link, "SELECT u.*, um.meta_value as capabilities
FROM `{$wp_}users` u
LEFT JOIN `{$wp_}usermeta` um ON u.ID = um.user_id AND um.meta_key = '{$wp_}capabilities'
ORDER BY u.ID ASC");
echo "
";
echo "ID Username Email Role Actions ";
while ($user = mysqli_fetch_assoc($users)) {
$capabilities = unserialize($user['capabilities']);
$role = $capabilities ? key($capabilities) : 'none';
echo "";
echo "{$user['ID']} ";
echo "{$user['user_login']} ";
echo "{$user['user_email']} ";
echo "$role ";
echo "
";
echo " ";
}
echo "
";
// Add New Admin Form
echo "
Add New Admin User ";
echo "
";
echo "
";
// Additional Recovery Tools
echo "";
echo "
🛠️ Additional Recovery Tools ";
echo "
";
// Database Repair
echo "
Database Repair
";
// Clear Cache
echo "
Cache Management
";
// Reset Permalinks
echo "
Permalink Reset
";
// Debug Information
echo "
Debug Information
Debug Info
";
echo "PHP Info:\n";
echo "PHP Version: " . phpversion() . "\n";
echo "MySQL Version: " . mysqli_get_server_info($link) . "\n";
echo "WordPress Version: " . $wp_version . "\n";
echo "\nActive PHP Extensions:\n";
echo implode(", ", get_loaded_extensions());
echo "
";
echo "
"; // End grid
echo "
"; // End Additional Tools card
// Themes section
echo "";
echo "
🎨 Themes ";
// Get active theme directly from database
$active_theme_query = mysqli_query($link, "SELECT option_value FROM `{$wp_}options` WHERE option_name = 'template'");
$active_theme_data = mysqli_fetch_assoc($active_theme_query);
$active_theme = $active_theme_data['option_value'];
// Get all themes from the themes directory
$themes_dir = ABSPATH . 'wp-content/themes/';
$all_themes = array();
if (is_dir($themes_dir)) {
$theme_folders = scandir($themes_dir);
foreach ($theme_folders as $theme) {
if ($theme === '.' || $theme === '..') continue;
$theme_path = $themes_dir . $theme;
if (is_dir($theme_path) && file_exists($theme_path . '/style.css')) {
// Read theme's style.css
$style_css = file_get_contents($theme_path . '/style.css');
// Extract theme data
preg_match('/Theme Name:\s*(.+)$/mi', $style_css, $name);
preg_match('/Version:\s*(.+)$/mi', $style_css, $version);
preg_match('/Author:\s*(.+)$/mi', $style_css, $author);
$all_themes[$theme] = array(
'name' => isset($name[1]) ? trim($name[1]) : $theme,
'version' => isset($version[1]) ? trim($version[1]) : 'Unknown',
'author' => isset($author[1]) ? trim($author[1]) : 'Unknown',
'active' => ($theme === $active_theme)
);
}
}
}
// Handle theme activation
if (isset($_POST['activate_theme']) && isset($_POST['theme'])) {
$theme_to_activate = mysqli_real_escape_string($link, $_POST['theme']);
// Update template (theme directory name)
mysqli_query($link, "UPDATE `{$wp_}options` SET option_value = '$theme_to_activate'
WHERE option_name = 'template'");
// Update stylesheet (might be different for child themes)
mysqli_query($link, "UPDATE `{$wp_}options` SET option_value = '$theme_to_activate'
WHERE option_name = 'stylesheet'");
echo "
";
echo "
✅ Theme activated successfully ";
echo "";
echo "
"; // Refresh to show changes
}
// Display themes table
if (!empty($all_themes)) {
echo "
";
echo "
Theme
Version
Author
Status
Actions
";
foreach ($all_themes as $theme_dir => $theme) {
echo "";
echo "" . htmlspecialchars($theme['name']) . " ";
echo "" . htmlspecialchars($theme['version']) . " ";
echo "" . htmlspecialchars($theme['author']) . " ";
echo "" .
($theme['active'] ? '✅ Active' : '⚠️ Inactive') . " ";
echo "";
if (!$theme['active']) {
echo "";
}
echo " ";
echo " ";
}
echo "
";
} else {
echo "
No themes found or unable to read themes directory.
";
}
echo "
";
// Plugins Section
echo "";
echo "
🔌 Plugins ";
// Get active plugins directly from database
$plugins_query = mysqli_query($link, "SELECT option_value FROM `{$wp_}options` WHERE option_name = 'active_plugins'");
$plugins_data = mysqli_fetch_assoc($plugins_query);
$active_plugins = $plugins_data ? unserialize($plugins_data['option_value']) : array();
// Get all plugins from the plugins directory
$plugins_dir = ABSPATH . 'wp-content/plugins/';
$all_plugins = array();
if (is_dir($plugins_dir)) {
$plugin_folders = scandir($plugins_dir);
foreach ($plugin_folders as $plugin) {
if ($plugin === '.' || $plugin === '..') continue;
$plugin_path = $plugins_dir . $plugin;
if (is_dir($plugin_path)) {
// For directory plugins
$files = scandir($plugin_path);
foreach ($files as $file) {
if (strpos($file, '.php') !== false) {
// Read the first 8kiB of the file
$plugin_file_path = $plugin_path . '/' . $file;
$fp = fopen($plugin_file_path, 'r');
if ($fp) {
$file_data = fread($fp, 8192);
fclose($fp);
// Check if this is the main plugin file
if (strpos($file_data, 'Plugin Name:') !== false) {
$plugin_file = $plugin . '/' . $file;
// Extract plugin name
preg_match('/Plugin Name:\s*(.+)$/mi', $file_data, $name);
// Extract version
preg_match('/Version:\s*(.+)$/mi', $file_data, $version);
$all_plugins[$plugin_file] = array(
'name' => isset($name[1]) ? trim($name[1]) : $plugin,
'version' => isset($version[1]) ? trim($version[1]) : 'Unknown',
'active' => in_array($plugin_file, $active_plugins)
);
break;
}
}
}
}
} elseif (strpos($plugin, '.php') !== false) {
// For single file plugins
$fp = fopen($plugins_dir . $plugin, 'r');
if ($fp) {
$file_data = fread($fp, 8192);
fclose($fp);
if (strpos($file_data, 'Plugin Name:') !== false) {
// Extract plugin name
preg_match('/Plugin Name:\s*(.+)$/mi', $file_data, $name);
// Extract version
preg_match('/Version:\s*(.+)$/mi', $file_data, $version);
$all_plugins[$plugin] = array(
'name' => isset($name[1]) ? trim($name[1]) : $plugin,
'version' => isset($version[1]) ? trim($version[1]) : 'Unknown',
'active' => in_array($plugin, $active_plugins)
);
}
}
}
}
}
// Display plugins table
if (!empty($all_plugins)) {
echo "
";
echo "Plugin Version Status Actions ";
foreach ($all_plugins as $plugin_file => $plugin) {
echo "";
echo "" . htmlspecialchars($plugin['name']) . " ";
echo "" . htmlspecialchars($plugin['version']) . " ";
echo "" .
($plugin['active'] ? '✅ Active' : '⚠️ Inactive') . " ";
echo "
";
echo " ";
}
echo "
";
} else {
echo "
No plugins found or unable to read plugins directory.
";
}
// Handle plugin activation/deactivation
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['activate_plugin']) && isset($_POST['plugin'])) {
$plugin_to_activate = $_POST['plugin'];
if (!in_array($plugin_to_activate, $active_plugins)) {
$active_plugins[] = $plugin_to_activate;
$serialized_plugins = serialize($active_plugins);
mysqli_query($link, "UPDATE `{$wp_}options` SET option_value = '" .
mysqli_real_escape_string($link, $serialized_plugins) .
"' WHERE option_name = 'active_plugins'");
echo "
";
echo "
✅ Plugin activated successfully ";
echo "";
echo "
";
}
}
if (isset($_POST['deactivate_plugin']) && isset($_POST['plugin'])) {
$plugin_to_deactivate = $_POST['plugin'];
$active_plugins = array_diff($active_plugins, array($plugin_to_deactivate));
$serialized_plugins = serialize($active_plugins);
mysqli_query($link, "UPDATE `{$wp_}options` SET option_value = '" .
mysqli_real_escape_string($link, $serialized_plugins) .
"' WHERE option_name = 'active_plugins'");
echo "
";
echo "
✅ Plugin deactivated successfully ";
echo "";
echo "
";
}
}
echo "
";
// Function to parse plugin headers
function get_plugin_header_data($plugin_file)
{
$default_headers = array(
'Name' => 'Plugin Name',
'Version' => 'Version',
'Description' => 'Description',
'Author' => 'Author',
);
$plugin_data = array();
$fp = fopen($plugin_file, 'r');
// Read first 8kiB of the file
$file_data = fread($fp, 8192);
fclose($fp);
foreach ($default_headers as $field => $regex) {
if (preg_match('/^[ \t\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match)) {
$plugin_data[$field] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1]));
} else {
$plugin_data[$field] = '';
}
}
return $plugin_data;
}
mysqli_close($link);
?>