wp_kses_allowed_html( string|array $context = '' ): array
- Since
- 3.5.0, 5.0.1
- Source
wp-includes/kses.php:1060
Compatibility
- WordPress
- since 5.0.1
- 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
$contextstring|arrayoptional- The context for which to retrieve tags. Allowed values are 'post', 'strip', 'data', 'entities', or the name of a field filter such as 'pre_user_description', or an array of allowed HTML elements and attributes.Default:
''
Return value
array- Array of allowed HTML tags and their allowed attributes.
Performance profile
How much work a call to wp_kses_allowed_html() 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
- 13–33
- Plugin surface
- 1 hook
- Called by
- 7
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 84.
Third-party callbacks on 'wp_kses_allowed_html' run inside this call, and their cost is not bounded by anything here.
7 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_kses_allowed_html() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 13–28 | apply_filters() |
!is_array($context) | 29–33 | apply_filters(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 84 instructions, 13–33 executed per call, 12 branches. The work does not change between versions.
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.
Hooks and filters fired · 7
7 hooks fire while wp_kses_allowed_html() runs, in this order:
- apply_filters( wp_kses_allowed_html )filterline 1080 (+20 into the body)
Filters the HTML tags that are allowed for a given context.
- apply_filters( wp_kses_allowed_html )filterline 1086 (+26 into the body)
Filters the HTML tags that are allowed for a given context.
- apply_filters( wp_kses_allowed_html )filterline 1103 (+43 into the body)
Filters the HTML tags that are allowed for a given context.
- apply_filters( wp_kses_allowed_html )filterline 1115 (+55 into the body)
Filters the HTML tags that are allowed for a given context.
- apply_filters( wp_kses_allowed_html )filterline 1119 (+59 into the body)
Filters the HTML tags that are allowed for a given context.
- apply_filters( wp_kses_allowed_html )filterline 1123 (+63 into the body)
Filters the HTML tags that are allowed for a given context.
- apply_filters( wp_kses_allowed_html )filterline 1128 (+68 into the body)
Filters the HTML tags that are allowed for a given context.
Uses · 1
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 7
- WP_Widget_Custom_HTML::render_control_template_scripts()Render form template scripts.
- filter_block_core_template_part_attributes()Sanitizes the value of the Template Part block's `tagName` attribute.
- gallery_shortcode()Builds the Gallery shortcode output.
- wp_get_code_editor_settings()Generates and returns code editor settings.
- wp_kses_attr()Removes all attributes, if none are allowed for this element.
- wp_kses_one_attr()Filters one HTML attribute and ensures its value is allowed.
- wp_kses_split2()Callback for `wp_kses_split()` for fixing malformed HTML tags.
Source code
function wp_kses_allowed_html( $context = '' ) { global $allowedposttags, $allowedtags, $allowedentitynames; if ( is_array( $context ) ) { // When `$context` is an array it's actually an array of allowed HTML elements and attributes. $html = $context; $context = 'explicit'; /** * Filters the HTML tags that are allowed for a given context. * * HTML tags and attribute names are case-insensitive in HTML but must be * added to the KSES allow list in lowercase. An item added to the allow list * in upper or mixed case will not recognized as permitted by KSES. * * @since 3.5.0 * * @param array[] $html Allowed HTML tags. * @param string $context Context name. */ return apply_filters( 'wp_kses_allowed_html', $html, $context ); } switch ( $context ) { case 'post': /** This filter is documented in wp-includes/kses.php */ $tags = apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context ); // 5.0.1 removed the `<form>` tag, allow it if a filter is allowing it's sub-elements `<input>` or `<select>`. if ( ! CUSTOM_TAGS && ! isset( $tags['form'] ) && ( isset( $tags['input'] ) || isset( $tags['select'] ) ) ) { $tags = $allowedposttags; $tags['form'] = array( 'action' => true, 'accept' => true, 'accept-charset' => true, 'enctype' => true, 'method' => true, 'name' => true, 'target' => true, ); /** This filter is documented in wp-includes/kses.php */ $tags = apply_filters( 'wp_kses_allowed_html', $tags, $context ); } return $tags; case 'user_description': case 'pre_term_description': case 'pre_user_description': $tags = $allowedtags; $tags['a']['rel'] = true; $tags['a']['target'] = true; /** This filter is documented in wp-includes/kses.php */ return apply_filters( 'wp_kses_allowed_html', $tags, $context ); case 'strip': /** This filter is documented in wp-includes/kses.php */ return apply_filters( 'wp_kses_allowed_html', array(), $context ); case 'entities': /** This filter is documented in wp-includes/kses.php */ return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context ); case 'data': default: /** This filter is documented in wp-includes/kses.php */ return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context ); }}Changelog
Introduced in 3.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
form removed as allowable HTML tag.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.