WP_Theme_JSON::remove_insecure_properties( array $theme_json, string $origin = 'theme' ): array
- Since
- 5.9.0, 6.3.2, 6.6.0
- Source
wp-includes/class-wp-theme-json.php:3516
Compatibility
- WordPress
- since 6.6.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
$theme_jsonarray- Structure to sanitize.
$originstringoptional- What source of data this object represents.
One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.Default:'theme'
Return value
array- Sanitized structure.
Performance profile
How much work a call to WP_Theme_JSON::remove_insecure_properties() 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
- Scaling
- Scales with input
- Instructions
- 61–67
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 199.
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 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_properties() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 61–67 | ::WP_Theme_JSON_Schema(), ::get_blocks_metadata(), array_keys(), array_keys(), ::get_valid_block_style_variations(), ::sanitize(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 199 | 61–67 | 24 | |
| 8.5 | 199 | 61–67 | 24 | |
| 8.4 | 199 | 61–67 | 24 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 202 | 64–70 | 24 | |
| 8.2 | 202 | 64–70 | 24 | |
| 8.1 | 202 | 64–70 | 24 | |
| 7.4 | 202 | 64–70 | 24 |
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 · 13
- _wp_array_get()Accesses an array in depth based on a path of keys.
- current_user_can()Returns whether the current user has the specified capability.
- _wp_array_set()Sets an array in depth based on a path of keys.
- WP_Theme_JSON_Schema::migrate()Function that migrates a given theme.json structure to the last version.
- static::get_blocks_metadata()
- static::get_valid_block_style_variations()
- static::sanitize()
- static::get_style_nodes()
- static::remove_insecure_styles()
- static::remove_insecure_inner_block_styles()
- static::remove_insecure_element_styles()
- static::get_setting_nodes()
Show all 13
- static::remove_insecure_settings()
Used by · 2
- _wp_add_block_level_preset_styles()Render the block level presets stylesheet.
- wp_filter_global_styles_post()Sanitizes global styles user content removing unsafe rules.
Source code
public static function remove_insecure_properties( $theme_json, $origin = 'theme' ) { if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) { $origin = 'theme'; } $sanitized = array(); $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json, $origin ); $blocks_metadata = static::get_blocks_metadata(); $valid_block_names = array_keys( $blocks_metadata ); $valid_element_names = array_keys( static::ELEMENTS ); $valid_variations = static::get_valid_block_style_variations( $blocks_metadata ); $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names, $valid_variations ); $blocks_metadata = static::get_blocks_metadata(); $style_options = array( 'include_block_style_variations' => true ); // Allow variations data. $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata, $style_options ); foreach ( $style_nodes as $metadata ) { $input = _wp_array_get( $theme_json, $metadata['path'], array() ); if ( empty( $input ) ) { continue; } // The global styles custom CSS is not sanitized, but can only be edited by users with 'edit_css' capability. if ( isset( $input['css'] ) && current_user_can( 'edit_css' ) ) { $output = $input; } else { $output = static::remove_insecure_styles( $input ); } /* * Get a reference to element name from path. * $metadata['path'] = array( 'styles', 'elements', 'link' ); */ $current_element = $metadata['path'][ count( $metadata['path'] ) - 1 ]; /* * $output is stripped of pseudo selectors. Re-add and process them * or insecure styles here. */ if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] ) ) { foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] as $pseudo_selector ) { if ( isset( $input[ $pseudo_selector ] ) ) { $output[ $pseudo_selector ] = static::remove_insecure_styles( $input[ $pseudo_selector ] ); } } } if ( ! empty( $output ) ) { _wp_array_set( $sanitized, $metadata['path'], $output ); } if ( isset( $metadata['variations'] ) ) { foreach ( $metadata['variations'] as $variation ) { $variation_input = _wp_array_get( $theme_json, $variation['path'], array() ); if ( empty( $variation_input ) ) { continue; } $variation_output = static::remove_insecure_styles( $variation_input ); if ( isset( $variation_input['blocks'] ) ) { $variation_output['blocks'] = static::remove_insecure_inner_block_styles( $variation_input['blocks'] ); } if ( isset( $variation_input['elements'] ) ) { $variation_output['elements'] = static::remove_insecure_element_styles( $variation_input['elements'] ); } if ( ! empty( $variation_output ) ) { _wp_array_set( $sanitized, $variation['path'], $variation_output ); } } } } $setting_nodes = static::get_setting_nodes( $theme_json );Changelog
Introduced in 5.9.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 6.9.7 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.