wppaste
WordPress

wp_kses_allowed_html( string|array $context = '' ): array

Since
3.5.0, 5.0.1
Source
wp-includes/kses.php:1063
Returns an array of allowed HTML tags and attributes for a given context.

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

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
13–33

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 84.

Plugin surface
1 hook

Third-party callbacks on 'wp_kses_allowed_html' run inside this call, and their cost is not bounded by anything here.

Called by
7

7 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always13–28apply_filters()
!is_array($context)29–33apply_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:

  1. apply_filters( wp_kses_allowed_html )filterline 1083 (+20 into the body)

    Filters the HTML tags that are allowed for a given context.

  2. apply_filters( wp_kses_allowed_html )filterline 1089 (+26 into the body)

    Filters the HTML tags that are allowed for a given context.

  3. apply_filters( wp_kses_allowed_html )filterline 1106 (+43 into the body)

    Filters the HTML tags that are allowed for a given context.

  4. apply_filters( wp_kses_allowed_html )filterline 1118 (+55 into the body)

    Filters the HTML tags that are allowed for a given context.

  5. apply_filters( wp_kses_allowed_html )filterline 1122 (+59 into the body)

    Filters the HTML tags that are allowed for a given context.

  6. apply_filters( wp_kses_allowed_html )filterline 1126 (+63 into the body)

    Filters the HTML tags that are allowed for a given context.

  7. apply_filters( wp_kses_allowed_html )filterline 1131 (+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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.0.1
form removed as allowable HTML tag.from the docblock
3.5.0
Introduced.from the docblock

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.