当前浏览:首页 / WordPress钩子 / kses_allowed_protocols

apply_filters( 'kses_allowed_protocols', string[] $protocols )

过滤HTML属性中允许的协议列表

allowed 允许

kses 清理

protocols

sanitize 清理more...


参数

$protocolsstring[]
允许的协议数组,例如'http''ftp''tel'等。


源码

查看源码 官方文档


更新日志

版本描述
3.0.0开始引入

使用示例

  • 示例1

    允许Skype调用链接。

    add_filter( 'kses_allowed_protocols', function ( $protocols ) {
        $protocols[] = 'skype';
        return $protocols;
    } );
  • 示例2

    过滤器应该在init之前运行。

    注意:此示例仅适用于PHP 5.3+

    function wpse_allow_sms_protocol( $protocols ) {
        $protocols[] = 'sms';
        return $protocols;
    }
    add_action('plugins_loaded', function(){add_filter('kses_allowed_protocols', 'wpse_allow_sms_protocol' );});
    print_r(wp_allowed_protocols());