wppaste
WordPress

WP_Theme_JSON::remove_insecure_settings( array $input ): array

Since
5.9.0
Source
wp-includes/class-wp-theme-json.php:3671
Processes a setting node and returns the same node without the insecure settings.

Compatibility

WordPress
since 5.9.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

$inputarray
Node to process.

Return value

array

Performance profile

How much work a call to WP_Theme_JSON::remove_insecure_settings() 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
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
10–11

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below WP_Theme_JSON::remove_insecure_settings()

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

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_Theme_JSON::remove_insecure_settings() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always10–11::remove_indirect_properties()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 96 instructions, 10–11 executed per call, 18 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.

Uses · 7

  • _wp_array_get()Accesses an array in depth based on a path of keys.
  • esc_attr()Escaping for HTML attributes.
  • esc_html()Escaping for HTML blocks.
  • sanitize_html_class()Sanitizes an HTML classname to ensure it only contains valid characters.
  • _wp_array_set()Sets an array in depth based on a path of keys.
  • static::is_safe_css_declaration()
  • static::remove_indirect_properties()

Source code

	protected static function remove_insecure_settings( $input ) {		$output = array();		foreach ( static::PRESETS_METADATA as $preset_metadata ) {			foreach ( static::VALID_ORIGINS as $origin ) {				$path_with_origin   = $preset_metadata['path'];				$path_with_origin[] = $origin;				$presets            = _wp_array_get( $input, $path_with_origin, null );				if ( null === $presets ) {					continue;				} 				$escaped_preset = array();				foreach ( $presets as $preset ) {					if (						esc_attr( esc_html( $preset['name'] ) ) === $preset['name'] &&						sanitize_html_class( $preset['slug'] ) === $preset['slug']					) {						$value = null;						if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) {							$value = $preset[ $preset_metadata['value_key'] ];						} elseif (							isset( $preset_metadata['value_func'] ) &&							is_callable( $preset_metadata['value_func'] )						) {							$value = call_user_func( $preset_metadata['value_func'], $preset );						} 						$preset_is_valid = true;						foreach ( $preset_metadata['properties'] as $property ) {							if ( ! static::is_safe_css_declaration( $property, $value ) ) {								$preset_is_valid = false;								break;							}						} 						if ( $preset_is_valid ) {							$escaped_preset[] = $preset;						}					}				} 				if ( ! empty( $escaped_preset ) ) {					_wp_array_set( $output, $path_with_origin, $escaped_preset );				}			}		} 		// Ensure indirect properties not included in any `PRESETS_METADATA` value are allowed.		static::remove_indirect_properties( $input, $output ); 		return $output;	}

Changelog

Introduced in 5.9.0. One change between 6.7.7 and 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.

7.1.0
Parameter $is_root added.verified against source
5.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-theme-json.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.