函数文档

allowed_tags()

💡 云策文档标注

概述

allowed_tags() 函数用于以 HTML 格式显示 WordPress 中允许的标签及其属性,常用于评论区域或插件开发中展示支持的 HTML 元素。

关键要点

  • 函数返回一个字符串,包含所有允许的 HTML 标签和属性,并进行 HTML 实体编码。
  • 主要用于在评论区域显示允许的 HTML 元素,或供插件开发者使用。
  • 自 WordPress 4.4.0 版本起,该函数在核心中不再使用,但可能仍存在于旧代码或插件中。

代码示例

$allowed_html_tags = allowed_tags();
echo $allowed_html_tags;

注意事项

该函数依赖于全局变量 $allowedtags,开发者应确保此变量已正确设置,并注意其自 4.4.0 版本后不再在核心中使用,建议检查兼容性。


📄 原文内容

Displays all of the allowed tags in HTML format with attributes.

Description

This is useful for displaying in the comment area, which elements and attributes are supported. As well as any plugins which want to display it.

Return

string HTML allowed tags entity encoded.

Source

function allowed_tags() {
	global $allowedtags;
	$allowed = '';
	foreach ( (array) $allowedtags as $tag => $attributes ) {
		$allowed .= '<' . $tag;
		if ( 0 < count( $attributes ) ) {
			foreach ( $attributes as $attribute => $limits ) {
				$allowed .= ' ' . $attribute . '=""';
			}
		}
		$allowed .= '> ';
	}
	return htmlentities( $allowed );
}

Changelog

Version Description
4.4.0 No longer used in core.
1.0.1 Introduced.

User Contributed Notes