钩子文档

esc_xml

💡 云策文档标注

概述

esc_xml 是一个 WordPress 函数,用于过滤和转义字符串,以便安全输出到 XML 中。它会移除无效或特殊字符,并将 HTML 命名字符引用转换为对应的代码点。

关键要点

  • esc_xml 函数用于清理和转义字符串,确保 XML 输出的安全性。
  • 它接受两个参数:$safe_text(转义后的文本)和 $text(转义前的原始文本)。
  • 该函数通过 apply_filters('esc_xml', $safe_text, $text) 实现,允许开发者通过 Hook 进行自定义过滤。
  • esc_xml 在 WordPress 5.5.0 版本中引入,位于 wp-includes/formatting.php 文件中。

代码示例

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

📄 原文内容

Filters a string cleaned and escaped for output in XML.

Description

Text passed to esc_xml() is stripped of invalid or special characters before output. HTML named character references are converted to their equivalent code points.

Parameters

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

Source

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

Changelog

Version Description
5.5.0 Introduced.