钩子文档

esc_html

💡 云策文档标注

概述

esc_html 是一个 WordPress 过滤器,用于在 HTML 输出前对字符串进行清理和转义。它确保文本在显示时安全,防止 XSS 攻击。

关键要点

  • esc_html 过滤器在字符串被 esc_html() 函数转义后应用,允许开发者修改转义后的文本。
  • 参数包括 $safe_text(转义后的文本)和 $text(原始文本),便于自定义处理。
  • 此过滤器自 WordPress 2.8.0 版本引入,常用于 HTML 块转义场景。

📄 原文内容

Filters a string cleaned and escaped for output in HTML.

Description

Text passed to esc_html() is stripped of invalid or special characters before output.

Parameters

$safe_textstring
The text after it has been escaped.
$textstring
The text prior to being escaped.

Source

return apply_filters( 'esc_html', $safe_text, $text );

Changelog

Version Description
2.8.0 Introduced.