函数文档

wp_kses_hook()

💡 云策文档标注

概述

wp_kses_hook() 函数用于在 KSES 过滤内容前应用 'pre_kses' 钩子,允许开发者自定义内容过滤逻辑。它接收内容、允许的 HTML 和协议参数,并返回过滤后的字符串。

关键要点

  • 函数调用 apply_filters('pre_kses', ...) 来触发 'pre_kses' 钩子,这是 WordPress 中唯一的 KSES 钩子。
  • 参数包括 $content(要过滤的内容)、$allowed_html(允许的 HTML 元素和属性数组或上下文名称)和 $allowed_protocols(允许的 URL 协议数组)。
  • 返回值为通过 'pre_kses' 钩子过滤后的字符串内容。

代码示例

function wp_kses_hook( $content, $allowed_html, $allowed_protocols ) {
    /**
     * Filters content to be run through KSES.
     *
     * @since 2.3.0
     *
     * @param string         $content           Content to filter through KSES.
     * @param array[]|string $allowed_html      An array of allowed HTML elements and attributes,
     *                                          or a context name such as 'post'. See wp_kses_allowed_html()
     *                                          for the list of accepted context names.
     * @param string[]       $allowed_protocols Array of allowed URL protocols.
     */
    return apply_filters( 'pre_kses', $content, $allowed_html, $allowed_protocols );
}

📄 原文内容

You add any KSES hooks here.

Description

There is currently only one KSES WordPress hook, ‘pre_kses’, and it is called here.
All parameters are passed to the hooks and expected to receive a string.

Parameters

$contentstringrequired
Content to filter through KSES.
$allowed_htmlarray[]|stringrequired
An array of allowed HTML elements and attributes, or a context name such as 'post'. See wp_kses_allowed_html() for the list of accepted context names.
$allowed_protocolsstring[]required
Array of allowed URL protocols.

Return

string Filtered content through ‘pre_kses’ hook.

Source

function wp_kses_hook( $content, $allowed_html, $allowed_protocols ) {
	/**
	 * Filters content to be run through KSES.
	 *
	 * @since 2.3.0
	 *
	 * @param string         $content           Content to filter through KSES.
	 * @param array[]|string $allowed_html      An array of allowed HTML elements and attributes,
	 *                                          or a context name such as 'post'. See wp_kses_allowed_html()
	 *                                          for the list of accepted context names.
	 * @param string[]       $allowed_protocols Array of allowed URL protocols.
	 */
	return apply_filters( 'pre_kses', $content, $allowed_html, $allowed_protocols );
}

Hooks

apply_filters( ‘pre_kses’, string $content, array[]|string $allowed_html, string[] $allowed_protocols )

Filters content to be run through KSES.

Changelog

Version Description
1.0.0 Introduced.