Make a backup before using this tool:
Change your database table prefix to mitigate zero-day SQL Injection attacks.
get_results("SHOW GRANTS FOR '".DB_USER."'@'".DB_HOST."'", ARRAY_N);
foreach ($rights as $right) {
if (ereg("ALTER(.*)(\*|`".str_replace("_", "\\_", DB_NAME)."`)\.(\*|`".DB_HOST."`) TO '".DB_USER."'@'".DB_HOST."'", $right[0]) || ereg("ALL PRIVILEGES ON (\*|`".str_replace("_", "\\_", DB_NAME)."`)\.(\*|`".DB_HOST."`) TO '".DB_USER."'@'".DB_HOST."'", $right[0])) {
$rightsenough = true;
$rightstomuch = true;
break;
} else {
if (ereg("ALTER(.*)`".DB_NAME."`", $right[0])) {
$rightsenough = true;
break;
}
}
}
if (!isset($rightsenough) && $rightsenough != true) {
exit('
Your User which is used to access your Wordpress Tables/Database, hasn\'t enough rights( is missing ALTER-right) to alter your Tablestructure.
');
}
if (isset($rightstomuch) && $rightstomuch === true) {
echo ('Your currently used User to Access the Wordpress Database, holds too many rights. '.
'We suggest that you limit his rights or to use another User with more limited rights instead, to increase your Security.
');
}
if ($newpref == $GLOBALS['table_prefix']) {
exit ("No change: Please select a new table_prefix value. ");
} elseif (strlen($newpref) < strlen($_POST['prefix_n'])){
echo ("You used some Chars which aren't allowed within Tablenames".
"The sanitized prefix is used instead: " . $newpref);
}
echo("
Started Prefix Changer:
");
//we rename the tables before we change the Config file, so We can aviod changed Configs, without changed prefixes.
echo("
Start Renaming of Tables:
");
$oldtables = $wpdb->get_results("SHOW TABLES LIKE '".$GLOBALS['table_prefix']."%'", ARRAY_N);//retrieving all tables named with the prefix on start
$table_c = count($oldtables);
$table_s = 0;//holds the count of successful changed tables.
$table_f[] = '';//holds all table names which failed to be changed
for($i = 0; $i < $table_c; $i++) {//renaming each table to the new prefix
$wpdb->hide_errors();
$table_n = str_replace($GLOBALS['table_prefix'], $newpref, $oldtables[$i][0]);
echo " Renaming ".$oldtables[$i][0]." to $table_n:";
$table_r = $wpdb->query("RENAME TABLE ".$oldtables[$i][0]." TO $table_n");
if ($table_r === 0) {
echo ('
Success');
$table_s++;
} elseif ($table_r === FALSE) {
echo ('
Failed');
$table_f[] = $oldtables[$i][0];
}
}//changing some "hardcoded" wp values within the tables
echo ("
Start changing Databasesettings:
");
if ($wpdb->query("UPDATE ".$newpref."options SET option_name='".$newpref."user_roles' WHERE option_name='".$GLOBALS['table_prefix']."user_roles' LIMIT 1") <> 1) {
echo (' Changing values in table '.$newpref.'options: 1/1
Failed');
} else {
echo (' Changing values in table '.$GLOBALS['table_prefix'].'options 1/1:
Success');
}
if ($wpdb->query("UPDATE ".$newpref."usermeta SET meta_key='".$newpref."capabilities' WHERE meta_key='".$GLOBALS['table_prefix']."capabilities'") <> 1) {
echo (' Changing values in table '.$GLOBALS['table_prefix'].'usermeta 1/3:
Failed');
} else {
echo (' Changing values in table '.$GLOBALS['table_prefix'].'usermeta 1/3:
Success');
}
if ($wpdb->query("UPDATE ".$newpref."usermeta SET meta_key='".$newpref."user_level' WHERE meta_key='".$GLOBALS['table_prefix']."user_level'") === FALSE)
{
echo (' Changing values in table '.$GLOBALS['table_prefix'].'usermeta 2/3:
Failed');
} else {
echo (' Changing values in table '.$GLOBALS['table_prefix'].'usermeta 2/3:
Success');
}
if ($wpdb->query("UPDATE ".$newpref."usermeta SET meta_key='".$newpref."autosave_draft_ids' WHERE meta_key='".$GLOBALS['table_prefix']."autosave_draft_ids'") === 0) {
echo (' Changing values in table '.$GLOBALS['table_prefix'].'usermeta 3/3:
Value doesn\'t exist');
} else {
echo (' Changing values in table '.$GLOBALS['table_prefix'].'usermeta 3/3:
Success');
}
if ($table_s == 0) {
exit('
Some Error occured, it wasn\'t possible to change any Tableprefix. Please retry, no changes are done to your wp-config File.');
} elseif ($table_s < $table_c) {
echo('
It wasn\'t possible to rename some of your Tables prefix. Please change them manually. Following you\'ll see all failed tables:
');
for ($i = 1; $i < count($tables_f); $i++) {
echo ($tables_f[$i])."
";
}
exit('No changes where done to your wp-config File.');
}
echo("
Changing Config File:
");
$conf_f = "../wp-config.php";
@chmod($conf_f, 0777);//making the the config readable to change the prefix
if (!is_writeable($conf_f)) {//when automatic config file changing isn't possible the user get's all needed information to do it manually
echo(' 1/1 file writeable:
Not Writeable');
echo('
Please make your wp-config.php file writable for this process.');
die("
");
} else {//changing if possible the config file automatically
echo(' 1/3 file writeable: