最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why WordPress not using JSON_UNESCAPED_UNICODE by default?

programmeradmin0浏览0评论

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?

Share Improve this question asked Mar 10, 2020 at 14:52 BogdanBogdan 1415 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Because 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

发布评论

评论列表(0)

  1. 暂无评论