I found one strange thing related to JSON and depending on what site language using WordPress.
For example, when Site Language is set to English and you viewing source code of the page, system scripts looks like that:
var thickboxL10n = {"next":"Next >","prev":"< Prev","image":"Image","of":"of","close":"Close","noiframes":"This feature requires inline frames. You have iframes disabled or your browser does not support them.","loadingAnimation":"https:\/\/site\/wp-includes\/js\/thickbox\/loadingAnimation.gif"};
But, when I change Site Language to Russian (or other non-latin language), I see that script becomes like this:
var thickboxL10n = {"next":"\u0414\u0430\u043b\u0435\u0435 \u2192","prev":"\u2190 \u041d\u0430\u0437\u0430\u0434","image":"\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435","of":"\u0438\u0437","close":"\u0417\u0430\u043a\u0440\u044b\u0442\u044c","noiframes":"\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0432. \u0423 \u0432\u0430\u0441 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0442\u0435\u0433\u0438 iframe, \u043b\u0438\u0431\u043e \u0432\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0438\u0445 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442.","loadingAnimation":"https:\/\/krutygolov.pp.ua\/wp-includes\/js\/thickbox\/loadingAnimation.gif"};
I think, it's related to wp_json_encode()
function, which using for JSON encoding (not sure).
Is there any way, to use JSON_UNESCAPED_UNICODE
in WordPress by default?
I want to see in source code Далее
insted of \u0414\u0430\u043b\u0435\u0435
or it's not impossible due JSON validation?
I found one strange thing related to JSON and depending on what site language using WordPress.
For example, when Site Language is set to English and you viewing source code of the page, system scripts looks like that:
var thickboxL10n = {"next":"Next >","prev":"< Prev","image":"Image","of":"of","close":"Close","noiframes":"This feature requires inline frames. You have iframes disabled or your browser does not support them.","loadingAnimation":"https:\/\/site\/wp-includes\/js\/thickbox\/loadingAnimation.gif"};
But, when I change Site Language to Russian (or other non-latin language), I see that script becomes like this:
var thickboxL10n = {"next":"\u0414\u0430\u043b\u0435\u0435 \u2192","prev":"\u2190 \u041d\u0430\u0437\u0430\u0434","image":"\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435","of":"\u0438\u0437","close":"\u0417\u0430\u043a\u0440\u044b\u0442\u044c","noiframes":"\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0432. \u0423 \u0432\u0430\u0441 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0442\u0435\u0433\u0438 iframe, \u043b\u0438\u0431\u043e \u0432\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0438\u0445 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442.","loadingAnimation":"https:\/\/krutygolov.pp.ua\/wp-includes\/js\/thickbox\/loadingAnimation.gif"};
I think, it's related to wp_json_encode()
function, which using for JSON encoding (not sure).
Is there any way, to use JSON_UNESCAPED_UNICODE
in WordPress by default?
I want to see in source code Далее
insted of \u0414\u0430\u043b\u0435\u0435
or it's not impossible due JSON validation?
1 Answer
Reset to default 1Because until relatively recently WordPress supported PHP 5.2+, but that constant was only added in PHP 5.4.
Given that wp_json_encode
is meant to encapsulate and account for the differing behaviour of json_encode
across multiple PHP versions, it doesn't make sense to deliberatly change its behaviour for PHP 5.4+
Now that WordPress has raised its minimum PHP version, you should consider opening a Trac ticket with a patch to add the constant with the reasons why it would be an improvement and testing instructions