wp_kses_check_attr_val( string $value, string $vless, string $checkname, mixed $checkvalue ): bool
- Since
- 1.0.0
- Source
wp-includes/kses.php:1873
Description
The currently implemented checks are "maxlen", "minlen", "maxval", "minval", and "valueless".
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
$valuestring- Attribute value.
$vlessstring- Whether the attribute is valueless. Use 'y' or 'n'.
$checknamestring- What $checkvalue is checking for.
$checkvaluemixed- What constraint the value should pass.
Return value
bool- Whether check passes.
Performance profile
How much work a call to wp_kses_check_attr_val() 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
- 11–31
- 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, depending on the branch taken. The body compiles to 70.
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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_kses_check_attr_val() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 11–26 | strtolower() |
| always | 15–30 | strtolower(), call_user_func() |
| always | 16–31 | strtolower(), strtolower() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 70 | 11–31 | 17 | |
| 8.5 | 70 | 11–31 | 17 | |
| 8.4 | 70 | 11–31 | 17 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 79 | 11–34 | 17 | |
| 8.2 | 79 | 11–34 | 17 | 1 more instruction than PHP 8.1 |
| 8.1 | 78 | 11–34 | 17 | |
| 7.4 | 78 | 11–34 | 17 |
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.
Used by · 1
- wp_kses_attr_check()Determines whether an attribute is allowed.
Source code
function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) { $ok = true; switch ( strtolower( $checkname ) ) { case 'maxlen': /* * The maxlen check makes sure that the attribute value has a length not * greater than the given value. This can be used to avoid Buffer Overflows * in WWW clients and various Internet servers. */ if ( strlen( $value ) > $checkvalue ) { $ok = false; } break; case 'minlen': /* * The minlen check makes sure that the attribute value has a length not * smaller than the given value. */ if ( strlen( $value ) < $checkvalue ) { $ok = false; } break; case 'maxval': /* * The maxval check does two things: it checks that the attribute value is * an integer from 0 and up, without an excessive amount of zeroes or * whitespace (to avoid Buffer Overflows). It also checks that the attribute * value is not greater than the given value. * This check can be used to avoid Denial of Service attacks. */ if ( ! preg_match( '/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value ) ) { $ok = false; } if ( $value > $checkvalue ) { $ok = false; } break; case 'minval': /* * The minval check makes sure that the attribute value is a positive integer, * and that it is not smaller than the given value. */ if ( ! preg_match( '/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value ) ) { $ok = false; } if ( $value < $checkvalue ) { $ok = false; } break; case 'valueless': /* * The valueless check makes sure if the attribute has a value * (like `<a href="blah">`) or not (`<option selected>`). If the given value * is a "y" or a "Y", the attribute must not have a value. * If the given value is an "n" or an "N", the attribute must have a value. */ if ( strtolower( $checkvalue ) !== $vless ) { $ok = false; } break; case 'values': /* * The values check is used when you want to make sure that the attribute * has one of the given values. */ if ( ! in_array( strtolower( $value ), $checkvalue, true ) ) { $ok = false; }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.