当前浏览:首页 / WordPress函数 / wp_kses_allowed_html()

wp_kses_allowed_html( string|array $context = '' ): array

返回给定上下文允许的HTML标签和属性的数组

allowed 允许

html

kses 清理

sanitize 清理more...


参数

$contextstring|array可选
要检索其标签的上下文。允许的值为'post''strip''data''entities',或字段过滤器(如'pre_user_description')的名称,或允许的HTML元素和属性的数组。

默认:''


返回

array 允许的HTML标签及其允许的属性的数组。


更多信息

返回的值是一个多维数组,标签名为键,属性数组为值。


钩子



源码

查看源码 官方文档


更新日志

版本描述
5.0.1form作为允许的HTML标签被删除。
3.5.0开始引入

使用示例

  • 示例1

    从Codex迁移的示例:

    // strips all html (empty array)
    $allowed_html = wp_kses_allowed_html( 'strip' );
    
    // allows all most inline elements and strips all block level elements except blockquote
    $allowed_html = wp_kses_allowed_html( 'data' );
    
    // very permissive: allows pretty much all HTML to pass - same as what's normally applied to the_content by default
    $allowed_html = wp_kses_allowed_html( 'post' );
    
    // allows a list of HTML Entities such as  
    $allowed_html = wp_kses_allowed_html( 'entities' );