wp_kses_bad_protocol_once( string $content, string[] $allowed_protocols, int $count = 1 ): string
- Since
- 1.0.0
- Source
wp-includes/kses.php:2100
Description
This function searches for URL protocols at the beginning of the string, while handling whitespace and HTML entities.
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
$contentstring- Content to check for bad protocols.
$allowed_protocolsstring[]- Array of allowed URL protocols.
$countintoptional- Depth of call recursion to this function.Default:
1
Return value
string- Sanitized content.
Performance profile
How much work a call to wp_kses_bad_protocol_once() 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
- 15–43
- Plugin surface
- None
- Called by
- 2
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, depending on the branch taken. The body compiles to 45.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- regexregular expression over the whole input
preg_split()called directly
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_kses_bad_protocol_once() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 15–18 | preg_split() |
isset($content2) | 32 | preg_split(), wp_kses_bad_protocol_once2() |
isset($content2) && $protocol === "feed:" && !$count | 41–43 | preg_split(), wp_kses_bad_protocol_once2(), wp_kses_bad_protocol_once() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 45 | 15–43 | 5 | |
| 8.5 | 45 | 15–43 | 5 | |
| 8.4 | 45 | 15–43 | 5 | 8 fewer instructions than PHP 8.3 |
| 8.3 | 53 | 18–51 | 5 | |
| 8.2 | 53 | 18–51 | 5 | |
| 8.1 | 53 | 18–51 | 5 | |
| 7.4 | 53 | 18–51 | 5 |
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 · 2
- wp_kses_bad_protocol_once2()Callback for `wp_kses_bad_protocol_once()` regular expression.
- wp_kses_bad_protocol_once()Sanitizes content from bad protocols and other characters.
Used by · 2
- wp_kses_bad_protocol()Sanitizes a string and removed disallowed URL protocols.
- wp_kses_bad_protocol_once()Sanitizes content from bad protocols and other characters.
Source code
function wp_kses_bad_protocol_once( $content, $allowed_protocols, $count = 1 ) { $content = preg_replace( '/(�*58(?![;0-9])|�*3a(?![;a-f0-9]))/i', '$1;', $content ); $content2 = preg_split( '/:|�*58;|�*3a;|:/i', $content, 2 ); if ( isset( $content2[1] ) && ! preg_match( '%/\?%', $content2[0] ) ) { $content = trim( $content2[1] ); $protocol = wp_kses_bad_protocol_once2( $content2[0], $allowed_protocols ); if ( 'feed:' === $protocol ) { if ( $count > 2 ) { return ''; } $content = wp_kses_bad_protocol_once( $content, $allowed_protocols, ++$count ); if ( empty( $content ) ) { return $content; } } $content = $protocol . $content; } return $content;}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.