wp_kses_bad_protocol_once2( string $scheme, string[] $allowed_protocols ): string
- Since
- 1.0.0
- Source
wp-includes/kses.php:2137
wp_kses_bad_protocol_once() regular expression.Description
This function processes URL protocols, checks to see if they're in the list of allowed protocols or not, and returns different data depending on the answer.
Compatibility
- WordPress
- since 1.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$schemestring- URI scheme to check against the list of allowed protocols.
$allowed_protocolsstring[]- Array of allowed URL protocols.
Return value
string- Sanitized content.
Performance profile
How much work a call to wp_kses_bad_protocol_once2() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 7
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 35.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_kses_bad_protocol_once2() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7 | strtolower() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 35 | 7 | 1 | |
| 8.5 | 35 | 7 | 1 | |
| 8.4 | 35 | 7 | 1 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 39 | 7 | 1 | |
| 8.2 | 39 | 7 | 1 | |
| 8.1 | 39 | 7 | 1 | |
| 7.4 | 39 | 7 | 1 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 3
- wp_kses_decode_entities()Converts all numeric HTML entities to their named counterparts.
- wp_kses_no_null()Removes any invalid control characters in a text string.
- array_any()Polyfill for `array_any()` function added in PHP 8.4.
Used by · 1
- wp_kses_bad_protocol_once()Sanitizes content from bad protocols and other characters.
Source code
function wp_kses_bad_protocol_once2( $scheme, $allowed_protocols ) { $scheme = wp_kses_decode_entities( $scheme ); $scheme = preg_replace( '/\s/', '', $scheme ); $scheme = wp_kses_no_null( $scheme ); $scheme = strtolower( $scheme ); $allowed = array_any( (array) $allowed_protocols, fn( $protocol ) => strtolower( $protocol ) === $scheme ); if ( $allowed ) { return "$scheme:"; } else { return ''; }}Changelog
Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/kses.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.