render_block_core_icon( array $attributes ): string
- Since
- 7.0.0
- Source
wp-includes/blocks/icon.php:17
core/icon block on server.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
$attributesarray- The block attributes.
Return value
string- Returns the Icon.
Performance profile
How much work a call to render_block_core_icon() 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
- 93–166
- 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 233.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 14 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_icon() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($attributes) && !$attributes && !isset($value) && $svg === "" | 93–100 | color(), size() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && !->next_tag() | 109–119 | color(), size(), wp_get_icon(), ->next_tag(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles) | 127–141 | color(), size(), wp_get_icon(), ->next_tag(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles) | 130–143 | color(), size(), wp_get_icon(), ->next_tag(), ->add_class(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && !empty($styles) | 133–144 | color(), size(), wp_get_icon(), ->next_tag(), ->set_attribute(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles) | 133–146 | color(), size(), wp_get_icon(), ->next_tag(), ->add_class(), ->add_class(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && !empty($styles) | 136–147 | color(), size(), wp_get_icon(), ->next_tag(), ->set_attribute(), ->add_class(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles) | 139–157 | color(), size(), wp_get_icon(), ->next_tag(), ->get_attribute(), ->set_attribute(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && !empty($styles) | 139–150 | color(), size(), wp_get_icon(), ->next_tag(), ->set_attribute(), ->add_class(), ->add_class(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles) | 142–159 | color(), size(), wp_get_icon(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && !empty($styles) | 145–160 | color(), size(), wp_get_icon(), ->next_tag(), ->set_attribute(), ->get_attribute(), ->set_attribute(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles) | 145–162 | color(), size(), wp_get_icon(), ->next_tag(), ->add_class(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html(), get_block_wrapper_attributes() |
2 further outcomes, up to 166 instructions
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && !empty($styles) | 148–163 | color(), size(), wp_get_icon(), ->next_tag(), ->set_attribute(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html(), get_block_wrapper_attributes() |
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && !empty($styles) | 151–166 | color(), size(), wp_get_icon(), ->next_tag(), ->set_attribute(), ->add_class(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html(), get_block_wrapper_attributes() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 233 | 93–166 | 34 | |
| 8.5 | 233 | 93–166 | 34 | |
| 8.4 | 233 | 93–166 | 34 | |
| 8.3 | 233 | 93–166 | 34 | |
| 8.2 | 233 | 93–166 | 34 | |
| 8.1 | 233 | 93–166 | 34 | 4 fewer instructions than PHP 7.4 |
| 7.4 | 237 | 93–167 | 34 |
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 · 4
- wp_style_engine_get_styles()Global public interface method to generate styles from a single style object, e.g. the value of a block's attributes.style object or the top level styles in theme.json.
- wp_get_icon()Returns the SVG markup for a registered icon.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function render_block_core_icon( $attributes ) { if ( empty( $attributes['icon'] ) ) { return; } // Text color and background color. $color_styles = array(); $preset_text_color = array_key_exists( 'textColor', $attributes ) ? "var:preset|color|{$attributes['textColor']}" : null; $custom_text_color = $attributes['style']['color']['text'] ?? null; $color_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color; $preset_background_color = array_key_exists( 'backgroundColor', $attributes ) ? "var:preset|color|{$attributes['backgroundColor']}" : null; $custom_background_color = $attributes['style']['color']['background'] ?? null; $color_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color; // Border. $border_styles = array(); $sides = array( 'top', 'right', 'bottom', 'left' ); if ( isset( $attributes['style']['border']['radius'] ) ) { $border_styles['radius'] = $attributes['style']['border']['radius']; } if ( isset( $attributes['style']['border']['style'] ) ) { $border_styles['style'] = $attributes['style']['border']['style']; } if ( isset( $attributes['style']['border']['width'] ) ) { $border_styles['width'] = $attributes['style']['border']['width']; } $preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null; $custom_color = $attributes['style']['border']['color'] ?? null; $border_styles['color'] = $preset_color ? $preset_color : $custom_color; foreach ( $sides as $side ) { $border = $attributes['style']['border'][ $side ] ?? null; $border_styles[ $side ] = array( 'color' => $border['color'] ?? null, 'style' => $border['style'] ?? null, 'width' => $border['width'] ?? null, ); } // Spacing (Padding). $spacing_styles = array(); if ( isset( $attributes['style']['spacing']['padding'] ) ) { $spacing_styles['padding'] = $attributes['style']['spacing']['padding']; } // Dimensions (Width). $dimensions_styles = array(); if ( isset( $attributes['style']['dimensions']['width'] ) ) { $dimensions_styles['width'] = $attributes['style']['dimensions']['width']; } // Generate styles and classes. $styles = wp_style_engine_get_styles( array( 'color' => $color_styles, 'border' => $border_styles, 'spacing' => $spacing_styles, 'dimensions' => $dimensions_styles, ), ); $svg = wp_get_icon( $attributes['icon'], array( // Width is applied via the dimensions block support styles below. 'size' => null, 'class' => $styles['classnames'] ?? '', 'label' => $attributes['ariaLabel'] ?? '', ) ); if ( '' === $svg ) { return; } $processor = new WP_HTML_Tag_Processor( $svg );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/blocks/icon.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.