wp_kses_bad_protocol() WordPress Function

The wp_kses_bad_protocol() function is used to remove bad protocols from a string. This is useful for making sure that links and other content are safe to display on a website.

wp_kses_bad_protocol( string $string, string[] $allowed_protocols ) #

Sanitizes a string and removed disallowed URL protocols.


Description

This function removes all non-allowed protocols from the beginning of the string. It ignores whitespace and the case of the letters, and it does understand HTML entities. It does its work recursively, so it won’t be fooled by a string like javascript:javascript:alert(57).


Top ↑

Parameters

$string

(string)(Required)Content to filter bad protocols from.

$allowed_protocols

(string[])(Required)Array of allowed URL protocols.


Top ↑

Return

(string) Filtered content.


Top ↑

Source

File: wp-includes/kses.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
1.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.