attribute_escape()
云策文档标注
概述
attribute_escape() 是一个已弃用的 WordPress 函数,用于对 HTML 属性进行转义。自 WordPress 2.8.0 起,建议使用 esc_attr() 替代。
关键要点
- 函数功能:对字符串进行 HTML 属性转义,防止 XSS 攻击。
- 弃用状态:自 WordPress 2.8.0 起被弃用,应改用 esc_attr()。
- 参数:接受一个必需的字符串参数 $text。
- 返回值:返回转义后的字符串。
代码示例
function attribute_escape( $text ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'esc_attr()' );
return esc_attr( $text );
}注意事项
- 在开发新代码时,应直接使用 esc_attr() 而非 attribute_escape()。
- 如果维护旧代码,需注意此函数已弃用,可能在未来版本中移除。
原文内容
Escaping for HTML attributes.
Description
See also
Parameters
$textstringrequired
Source
function attribute_escape( $text ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'esc_attr()' );
return esc_attr( $text );
}
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Deprecated. Use esc_attr() |
| 2.0.6 | Introduced. |