1. 首页
  2. WordPress钩子手册

esc_html

apply_filters( ‘esc_html’, string $safe_text, string $text )

过滤器::过滤一个已清理并转义的字符串,以便在HTML中输出。
Filter Hook: Filters a string cleaned and escaped for output in HTML.

目录锚点:#说明#参数#源码


说明(Description)

在输出之前,传递给esc_html()的文本将被去除无效或特殊字符。


参数(Parameters)

参数 类型 说明
$safe_text (string) 转义后的文本。
$text (string) 在被转义之前的文本。

源码(Source)

/**
 * Escaping for HTML blocks.
 *
 * @since 2.8.0
 *
 * @param string $text
 * @return string
 */
function esc_html( $text ) {
	$safe_text = wp_check_invalid_utf8( $text );
	$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
	/**
	 * Filter a string cleaned and escaped for output in HTML.
	 *
	 * Text passed to esc_html() is stripped of invalid or special characters
	 * before output.
	 *
	 * @since 2.8.0
	 *
	 * @param string $safe_text The text after it has been escaped.
 	 * @param string $text      The text prior to being escaped.
	 */
	return apply_filters( 'esc_html', $safe_text, $text );
}
更新版本 源码位置 使用 被使用
2.8.0 wp-includes/formatting.php:4470 1 0

esc_html 为WP2原创文章,链接:https://www.wp2.cn/hook/esc_html/