js_escape()
云策文档标注
概述
js_escape() 是一个已弃用的 WordPress 函数,用于转义 JavaScript 字符串中的特殊字符,如单引号、双引号和换行符。它已被 esc_js() 替代,开发者应使用 esc_js() 来实现相同功能。
关键要点
- js_escape() 函数在 WordPress 2.8.0 版本中被弃用,推荐使用 esc_js()。
- 该函数转义单引号、双引号、& 符号,并修复换行符。
- 参数 $text 是必需的字符串,用于指定要转义的文本。
- 返回值为转义后的字符串。
- 相关函数包括 esc_js() 和 _deprecated_function()。
代码示例
function js_escape( $text ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'esc_js()' );
return esc_js( $text );
}注意事项
- 由于 js_escape() 已弃用,新代码中应避免使用,改用 esc_js() 以确保兼容性和安全性。
- 弃用信息通过 _deprecated_function() 记录,有助于开发者识别和更新旧代码。
原文内容
Escape single quotes, specialchar double quotes, and fix line endings.
Description
The filter ‘js_escape’ is also applied by esc_js() .
See also
Parameters
$textstringrequired-
The text to be escaped.
Source
function js_escape( $text ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'esc_js()' );
return esc_js( $text );
}