get_results("SHOW TABLES LIKE '".$GLOBALS['table_prefix']."%'", ARRAY_N); } function aiomh_prefix_renameTables($tables, $currentPrefix, $newPrefix) { global $wpdb; $changedTables = array(); foreach ($tables as $k=>$table) { $tableOldName = $table[0]; // Hide errors $wpdb->hide_errors(); // To rename the table $tableNewName = substr_replace($tableOldName, $newPrefix, 0, strlen($currentPrefix)); $wpdb->query("RENAME TABLE `{$tableOldName}` TO `{$tableNewName}`"); array_push($changedTables, $tableNewName); } return $changedTables; } function aiomh_prefix_renameDbFields($oldPrefix,$newPrefix) { global $wpdb; /* * usermeta table *=========================== wp_* * options table * =========================== wp_user_roles */ $str = ''; if (false === $wpdb->query("UPDATE {$newPrefix}options SET option_name='{$newPrefix}user_roles' WHERE option_name='{$oldPrefix}user_roles';")) { $str .= '
Changing value: '.$newPrefix.'user_roles in table '.$newPrefix.'options: Failed'; } $query = 'update '.$newPrefix.'usermeta set meta_key = CONCAT(replace(left(meta_key, ' . strlen($oldPrefix) . "), '{$oldPrefix}', '{$newPrefix}'), SUBSTR(meta_key, " . (strlen($oldPrefix) + 1) . ")) where meta_key in ('{$oldPrefix}autosave_draft_ids', '{$oldPrefix}capabilities', '{$oldPrefix}metaboxorder_post', '{$oldPrefix}user_level', '{$oldPrefix}usersettings','{$oldPrefix}usersettingstime', '{$oldPrefix}user-settings', '{$oldPrefix}user-settings-time', '{$oldPrefix}dashboard_quick_press_last_post_id')"; if (false === $wpdb->query($query)) { $str .= '
Changing values in table '.$newPrefix.'usermeta: Failed'; } if (!empty($str)) { $str = '

Changing database prefix:

'.$str.'

'; } return $str; } global $wpdb; $bprefix_Message=""; $bprefix_prefix=$wpdb->prefix; if((isset($_POST['aiomh_prefix_hidden']) && $_POST['aiomh_prefix_hidden']=='Y') && (isset($_POST['Submit']))) { echo '
'; //Form data sent $old_aiomh_prefix = $_POST['aiomh_prefix_old_aiomh_prefix']; update_option('aiomh_prefix_old_aiomh_prefix', $old_aiomh_prefix); $aiomh_prefix_new = $_POST['aiomh_prefix_new']; update_option('aiomh_prefix_new', $aiomh_prefix_new); $wpdb =& $GLOBALS['wpdb']; $new_prefix = preg_replace("/[^0-9a-zA-Z_]/", "", $aiomh_prefix_new); $aiomh_prefix_class="aiomh_prefix-error"; if($_POST['aiomh_prefix_new'] =='' || strlen($_POST['aiomh_prefix_new']) < 2 ){$bprefix_Message .= aiomh_translate('Vui lòng cung cấp tiền tố chính xác').'.';} else if ($new_prefix == $old_aiomh_prefix) {$bprefix_Message .= aiomh_translate('Không thay đổi! Vui lòng nhập tiền tố mới khác tiền tố cũ');} else if (strlen($new_prefix) < strlen($aiomh_prefix_new)){ $bprefix_Message .= aiomh_translate('Bạn đã sử dụng một số ký tự không được phép cho tiền tố của bảng. Vui lòng sử dụng ký tự cho phép không phải').' '. $aiomh_prefix_new .''; } else { $tables = aiomh_prefix_getTablesToAlter(); if (empty($tables)) { $bprefix_Message .= aiomh_prefixaiomh_translateInfo('There are no tables to rename!'); } else { $result = aiomh_prefix_renameTables($tables, $old_aiomh_prefix, $aiomh_prefix_new); // check for errors if (!empty($result)){ $bprefix_Message .=aiomh_translate('Tất cả các bảng đã được cập nhật thành công với tiền tố').' '.$aiomh_prefix_new.' !
'; // try to rename the fields $bprefix_Message .= aiomh_prefix_renameDbFields($old_aiomh_prefix, $aiomh_prefix_new); $aiomh_prefix_wpConfigFile= ABSPATH.'wp-config.php'; if (aiomh_prefix_updateWpConfigTablePrefix($aiomh_prefix_wpConfigFile, $old_aiomh_prefix, $aiomh_prefix_new)){ $bprefix_Message .= aiomh_translate('Tệp wp-config đã được cập nhật thành công với tiền tố').' '.$aiomh_prefix_new.'!'; $aiomh_prefix_class="aiomh_prefix-success"; } else { $bprefix_Message .= aiomh_translate('Không thể cập nhật tập tin wp-config! Bạn phải sửa lại biến $table_prefix trong wp-config với tiền tố mới bạn thay đổi').': '.$aiomh_prefix_new; } // End if tables successfully renamed $bprefix_prefix=$aiomh_prefix_new; } else { $bprefix_Message .= aiomh_translate('Đã xảy ra lỗi và không thể cập nhật bảng cơ sở dữ liệu'); } $_POST['aiomh_prefix_hidden'] = 'n'; } } } else { echo '
'; //Normal page display $dbhost = get_option('aiomh_prefix_dbhost'); $dbname = get_option('aiomh_prefix_dbname'); $dbuser = get_option('aiomh_prefix_dbuser'); $dbpwd = get_option('aiomh_prefix_dbpwd'); $aiomh_prefixaiomh_translatexist = get_option('aiomh_prefix_prefixaiomh_translatexist'); $aiomh_prefix_new = get_option('aiomh_prefix_new'); } ?>

:

  • wp-config.php phải ghi được')?>.
  • ALTER')?>.
'.aiomh_translate('Cảnh báo: file wp-config không có quyền chỉnh sửa. Sau khi đổi tiền tố bạn phải sửa lại biến $table_prefix trong file wp-config một cách thủ công.').''; } ?>

Các kí tự cho phép: tất cả chữ latin, chữ số cũng như _ (gạch dưới), không dùng ký tự đặc biệt và tiếng việt có dấu" )?>.