当你看最后一行img_caption_shortcode(), 然后你可以看到wp_kses() 正在剥离不允许的HTML标记。这个wp_kses_hook() 函数仅包装筛选器:
return apply_filters( \'pre_kses\', $string, $allowed_html, $allowed_protocols );
允许在
wp_kses_split() 最后使用删除HTML标记
preg_replace_callback 具有
_wp_kses_split_callback() 作为移除标签的功能。
与内部一样_wp_kses_split_callback(), 这个wp_kses_split2() 函数被调用时,您还有一个(糟糕的)选择:更改全局。
回调中有以下两个全局变量:
global $pass_allowed_html, $pass_allowed_protocols;
这意味着您还可以执行以下操作(不推荐):
// Fetch the global context
global $pass_allowed_html;
// Save the global context for restoring it to not nuke other code
$temp = $pass_allowed_html;
// Alter the context
$GLOBALS[\'pass_allowed_html\'] = [ /* your allowed HTML tags here */ ];
// Fetch the result
$result = img_caption_shortcode();
// Reset the global context
$GLOBALS[\'pass_allowed_html\'] = $temp;
// Return your altered result
return $result;
请记住
wp_kses_allowed_html() 然后会触发
explicit 案例
像img_caption_shortcode() 仅通过string 有价值的post 到wp_kses(), 你也可以从以下几行中获利wp_kses_split2():
if ( ! is_array( $allowed_html ) )
$allowed_html = wp_kses_allowed_html( $allowed_html );
正在查看[
wp_kses_allowed_html()] 再次强调:
return apply_filters( \'wp_kses_allowed_html\', $allowedposttags, $context );
您可以简单地使用此过滤器。确保您
remove the filter again 运行后,它不会与其他内容冲突,因此会意外地允许标记在其他地方。