wp_render_custom_css_support_styles( array $parsed_block ): array
- Since
- 7.0.0
- Source
wp-includes/block-supports/custom-css.php:41
Compatibility
- WordPress
- since 7.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 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$parsed_blockarray- The parsed block.
Return value
array- The same parsed block with custom CSS class name added if appropriate.
Performance profile
How much work a call to wp_render_custom_css_support_styles() 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
- 9–85
- Plugin surface
- None
- Called by
- 0
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 89.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_render_custom_css_support_styles() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9–13 | none |
is_string($custom_css) | 26–29 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support() |
is_string($custom_css) && block_has_support() && !$custom_css && empty($processed_css) | 52–57 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_unique_id_from_values(), ::WP_Theme_JSON() |
is_string($custom_css) && block_has_support() && !$custom_css && !empty($processed_css) && wp_style_is() && $processed_css | 70–76 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_unique_id_from_values(), ::WP_Theme_JSON(), wp_style_is(), wp_styles(), ->get_data() |
is_string($custom_css) && block_has_support() && !$custom_css && !empty($processed_css) && wp_style_is() && !$processed_css | 74–80 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_unique_id_from_values(), ::WP_Theme_JSON(), wp_style_is(), wp_styles(), ->get_data(), wp_add_inline_style() |
is_string($custom_css) && block_has_support() && !$custom_css && !empty($processed_css) && !wp_style_is() && $processed_css | 75–81 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_unique_id_from_values(), ::WP_Theme_JSON(), wp_style_is(), wp_register_style(), wp_styles(), ->get_data() |
is_string($custom_css) && block_has_support() && !$custom_css && !empty($processed_css) && !wp_style_is() && !$processed_css | 79–85 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_unique_id_from_values(), ::WP_Theme_JSON(), wp_style_is(), wp_register_style(), wp_styles(), ->get_data(), wp_add_inline_style() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 89 | 9–85 | 11 | |
| 8.5 | 89 | 9–85 | 11 | |
| 8.4 | 89 | 9–85 | 11 | 8 fewer instructions than PHP 8.3 |
| 8.3 | 97 | 9–93 | 11 | |
| 8.2 | 97 | 9–93 | 11 | |
| 8.1 | 97 | 9–93 | 11 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 98 | 9–94 | 11 |
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 · 10
- block_has_support()Checks whether the current block type supports the feature requested.
- wp_unique_id_from_values()Generates a unique ID based on the structure and values of a given array.
- wp_style_is()Checks whether a CSS stylesheet has been added to the queue.
- wp_register_style()Registers a CSS stylesheet.
- wp_styles()Initializes $wp_styles if it has not been set.
- wp_add_inline_style()Adds extra CSS styles to a registered stylesheet.
- WP_Block_Type_Registry::get_instance()::get_registered()
- WP_Block_Type_Registry::get_instance()Utility method to retrieve the main instance of the class.
- WP_Theme_JSON::process_blocks_custom_css()Processes the CSS, to apply nesting.
- wp_styles()::get_data()
Source code
function wp_render_custom_css_support_styles( $parsed_block ) { $custom_css = $parsed_block['attrs']['style']['css'] ?? null; if ( ! is_string( $custom_css ) || '' === trim( $custom_css ) ) { return $parsed_block; } $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] ); if ( ! block_has_support( $block_type, 'customCSS', true ) ) { return $parsed_block; } // Validate CSS doesn't contain HTML markup (same validation as global styles REST API). if ( preg_match( '#</?\w+#', $custom_css ) ) { return $parsed_block; } // Generate a unique class name for this block instance. $class_name = wp_unique_id_from_values( $parsed_block, 'wp-custom-css-' ); $existing_class_name = $parsed_block['attrs']['className'] ?? null; $updated_class_name = is_string( $existing_class_name ) ? "$existing_class_name $class_name" : $class_name; $parsed_block['attrs']['className'] = $updated_class_name; // Process the custom CSS using the same method as global styles. $selector = '.' . $class_name; $processed_css = WP_Theme_JSON::process_blocks_custom_css( $custom_css, $selector ); if ( ! empty( $processed_css ) ) { /** * Reuse one handle so identical custom CSS is enqueued only once via * {@see wp_unique_id_from_values()}. Explicitly declare the `wp-block-library` * dependency so `global-styles` is guaranteed to print after it, preventing * block default styles from unintentionally overriding global styles. */ $handle = 'wp-block-custom-css'; if ( ! wp_style_is( $handle, 'registered' ) ) { wp_register_style( $handle, false, array( 'wp-block-library', 'global-styles' ) ); } $after_styles = wp_styles()->get_data( $handle, 'after' ); if ( ! is_array( $after_styles ) ) { $after_styles = array(); } if ( ! in_array( $processed_css, $after_styles, true ) ) { wp_add_inline_style( $handle, $processed_css ); } } return $parsed_block;}Changelog
Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/block-supports/custom-css.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.