wp_kses

函式
wp_kses ( $string, $allowed_html, $allowed_protocols = array() )
引數
  • (string) $string Text content to filter.
    Required:
  • (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.
    Required:
  • (string[]) $allowed_protocols Optional. Array of allowed URL protocols. Defaults to the result of wp_allowed_protocols().
    Required:
    Default: array()
返回值
  • (string) Filtered content containing only the allowed HTML.
相關
  • wp_kses_post()
  • wp_allowed_protocols()
定義位置
相關方法
wp_rsswp_styleswp_kses_postwp_kses_hookwp_kses_hair
引入
1.0.0
棄用
-

wp_kses: 這個函式用來對一串HTML內容進行淨化,刪除任何潛在的惡意或不允許的內容,同時允許某些安全的HTML標籤和屬性。

對文字內容進行過濾,剔除不允許的HTML。

這個函式確保只有允許的HTML元素名稱、屬性名稱、屬性值和HTML實體會出現在給定的文字字串中。

這個函式期望的是不加刪節的資料。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) {
if ( empty( $allowed_protocols ) ) {
$allowed_protocols = wp_allowed_protocols();
}
$string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) );
$string = wp_kses_normalize_entities( $string );
$string = wp_kses_hook( $string, $allowed_html, $allowed_protocols );
return wp_kses_split( $string, $allowed_html, $allowed_protocols );
}
function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) { if ( empty( $allowed_protocols ) ) { $allowed_protocols = wp_allowed_protocols(); } $string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); $string = wp_kses_normalize_entities( $string ); $string = wp_kses_hook( $string, $allowed_html, $allowed_protocols ); return wp_kses_split( $string, $allowed_html, $allowed_protocols ); }
function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) {
	if ( empty( $allowed_protocols ) ) {
		$allowed_protocols = wp_allowed_protocols();
	}

	$string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) );
	$string = wp_kses_normalize_entities( $string );
	$string = wp_kses_hook( $string, $allowed_html, $allowed_protocols );

	return wp_kses_split( $string, $allowed_html, $allowed_protocols );
}

常見問題

FAQs
檢視更多 >