wp_kses_bad_protocol

函式
wp_kses_bad_protocol ( $string, $allowed_protocols )
引數
  • (string) $string Content to filter bad protocols from.
    Required:
  • (string[]) $allowed_protocols Array of allowed URL protocols.
    Required:
返回值
  • (string) Filtered content.
定義位置
相關方法
wp_kses_bad_protocol_oncewp_allowed_protocolswp_kses_postwp_get_server_protocolwp_kses_allowed_html
引入
1.0.0
棄用
-

wp_kses_bad_protocol: 這個函式用來從一個HTML屬性的值中刪除任何不允許的協議。

對字串進行淨化,並刪除不允許的URL協議。

這個函式從字串的開頭刪除所有不允許的協議。它忽略了空格和字母的大小寫,而且它確實理解HTML實體。它的工作是遞迴的,所以它不會被`javascript:javascript:alert(57)`這樣的字串所欺騙。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_kses_bad_protocol( $string, $allowed_protocols ) {
$string = wp_kses_no_null( $string );
$iterations = 0;
do {
$original_string = $string;
$string = wp_kses_bad_protocol_once( $string, $allowed_protocols );
} while ( $original_string != $string && ++$iterations < 6 );
if ( $original_string != $string ) {
return '';
}
return $string;
}
function wp_kses_bad_protocol( $string, $allowed_protocols ) { $string = wp_kses_no_null( $string ); $iterations = 0; do { $original_string = $string; $string = wp_kses_bad_protocol_once( $string, $allowed_protocols ); } while ( $original_string != $string && ++$iterations < 6 ); if ( $original_string != $string ) { return ''; } return $string; }
function wp_kses_bad_protocol( $string, $allowed_protocols ) {
	$string     = wp_kses_no_null( $string );
	$iterations = 0;

	do {
		$original_string = $string;
		$string          = wp_kses_bad_protocol_once( $string, $allowed_protocols );
	} while ( $original_string != $string && ++$iterations < 6 );

	if ( $original_string != $string ) {
		return '';
	}

	return $string;
}

常見問題

FAQs
檢視更多 >