Từ lúc cập nhật wordpress 4.7.0 thì wordpress bắt đầu xuất hiện lỗi number_format_thousands_sep, tuy không gây ảnh hưởng lắm tới hoạt động nhưng thật sự lỗi này rất khó chịu. Hôm nay, mình sẽ hướng dẫn các bạn cách sửa lỗi này.
Hướng dẫn khắc phục lỗi number_format_thousands_sep trong WordPress
Khi gặp lỗi này, thay vì hiện thông số 1234 nó sẽ hiển thị theo kiểu 1number_format_thousands_sep234 nhìn rất là ngứa mắt.
Cách 1: Sửa file class-wp-locate.php
1. Đầu tiên, các bạn cần truy cập vào Cpanel bằng FTP hoặc vào trực tiếp, tìm đến File wp-includes > class-wp-locate.php
2. Tìm và sửa đoạn code sau trong class-wp-locate.php
$this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep;
Và sửa nó thành:
$this->number_format['thousands_sep'] = ',';
3. Tìm tiếp đoạn code sau:
$this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point;
Thay thế nó bằng:
$this->number_format['decimal_point'] = '.';
Sau đó bạn lưu lại file là được. Lưu ý, cách này sửa thì nhanh nhưng khi cập nhật phiên bản mới có thể bị đè mất.
Cách 2: Chỉnh sửa file wp-includes/functions.php
Bạn tìm tới file wp-includes/functions.php và tìm dòng 219
/** * Convert float number to format based on the locale. * * @since 2.3.0 * * @global WP_Locale $wp_locale * * @param float $number The number to convert based on locale. * @param int $decimals Optional. Precision of the number of decimal places. Default 0. * @return string Converted number in string format. */ function number_format_i18n($number, $decimals = 0) { global $wp_locale; if (isset($wp_locale)) { $formatted = number_format($number, absint($decimals), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']); } else { $formatted = number_format($number, absint($decimals)); } /** * Filters the number formatted based on the locale. * * @since 2.8.0 * * @param string $formatted Converted number in string format. */ return apply_filters('number_format_i18n', $formatted); }
Và sửa nó thành:
function number_format_i18n($number, $decimals = 0) { global $wp_locale; if (isset($wp_locale)) { $formatted = number_format($number, absint($decimals), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['decimals']); } else { $formatted = number_format($number, absint($decimals)); } /** * Filters the number formatted based on the locale. * * @since 2.8.0 * * @param string $formatted Converted number in string format. */ return apply_filters('number_format_i18n', $formatted); }
Cách 3: Sửa file ngôn ngữ
Nguyên nhân chính của việc gây ra lỗi này là do dịch sai, ngôn ngữ tiếng Việt chưa được hỗ trợ đến phiên bản hiện tại. Để sửa thì bạn làm theo các cách sau:
- Các bạn vào thư mục: wp-content/languages/ Tải file: vi.po và sử dụng poedit mở file.
- number_format_decimal_point: bạn sửa thành dấu phẩy ,
- number_format_thousands_sep: Bạn sửa bằng dấu .
Sau đó các bạn cứ việc tải 2 file ngôn ngữ vừa được sinh ra khi lưu lại này vào đúng thư mục cũ. Chọn ghi đè lên là hoàn thành. Trong trường hợp lười xài Poedit thì bạn dùng Plugin locotranslate sửa, nó sẽ tự động tạo ra 2 thư mục trong file language. Dùng xong thì tải 2 file đó về, xóa plugin và tải lên lại là xong.