Skip to content

Commit

Permalink
Fix "Generate New DB Table Prefix" bug
Browse files Browse the repository at this point in the history
Problem:
If the old DB table prefix happens to also exist elsewhere in the $table_prefix line in wp-config.php then after the change is executed, all pageloads break with "Configuration Error - Your wp-config.php file has an empty database table prefix, which is not supported." because $table_prefix has been renamed.

eg: Changing the DB table prefix from "le_" to "foo_"  means `$table_prefix="le_"` becomes `$tabfoo_prefix="foo_"`

Solution:
Split line at "=" and only apply change to last part instead of whole line
  • Loading branch information
baddiedev committed Sep 16, 2020
1 parent 314f054 commit 69ade75
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion all-in-one-wp-security/admin/wp-security-database-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ function change_db_prefix($table_old_prefix, $table_new_prefix)
foreach ($config_contents as $line_num => $line) {
$no_ws_line = preg_replace( '/\s+/', '', $line ); //Strip white spaces
if(strpos($no_ws_line, $prefix_match_string) !== FALSE){
$config_contents[$line_num] = str_replace($table_old_prefix, $table_new_prefix, $line);
$prefix_parts = explode("=",$config_contents[$line_num]);
$prefix_parts[1] = str_replace($table_old_prefix, $table_new_prefix, $prefix_parts[1]);
$config_contents[$line_num] = implode("=",$prefix_parts);
break;
}
}
Expand Down

0 comments on commit 69ade75

Please sign in to comment.