wp_pre_kses_block_attributes

函式
wp_pre_kses_block_attributes ( $string, $allowed_html, $allowed_protocols )
引數
  • (string) $string Content to be run through KSES.
    Required:
  • (array[]|string) $allowed_html An array of allowed HTML elements and attributes, or a context name such as 'post'.
    Required:
  • (string[]) $allowed_protocols Array of allowed URL protocols.
    Required:
返回值
  • (string) Filtered text to run through KSES.
定義位置
相關方法
wp_kses_uri_attributesserialize_block_attributeswp_kses_one_attrwp_sanitize_script_attributeswp_pre_kses_less_than
引入
5.3.1
棄用
-

wp_pre_kses_block_attributes: 這個過濾器用於過濾塊元素的屬性,然後再對它們進行淨化。它被用來確保屬性在HTML輸出中的安全使用。

當在文章上下文中進行過濾時,從解析的塊屬性值中刪除不允許的HTML。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_pre_kses_block_attributes( $string, $allowed_html, $allowed_protocols ) {
/*
* `filter_block_content` is expected to call `wp_kses`. Temporarily remove
* the filter to avoid recursion.
*/
remove_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10 );
$string = filter_block_content( $string, $allowed_html, $allowed_protocols );
add_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10, 3 );
return $string;
}
function wp_pre_kses_block_attributes( $string, $allowed_html, $allowed_protocols ) { /* * `filter_block_content` is expected to call `wp_kses`. Temporarily remove * the filter to avoid recursion. */ remove_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10 ); $string = filter_block_content( $string, $allowed_html, $allowed_protocols ); add_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10, 3 ); return $string; }
function wp_pre_kses_block_attributes( $string, $allowed_html, $allowed_protocols ) {
	/*
	 * `filter_block_content` is expected to call `wp_kses`. Temporarily remove
	 * the filter to avoid recursion.
	 */
	remove_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10 );
	$string = filter_block_content( $string, $allowed_html, $allowed_protocols );
	add_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10, 3 );

	return $string;
}

常見問題

FAQs
檢視更多 >