wppaste
WordPress

render_block_core_icon( array $attributes ): string

Since
7.0.0
Source
wp-includes/blocks/icon.php:17
Renders the 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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
93–166

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

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 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.

WhenInstructionsCalls it makes
!empty($attributes) && !$attributes && !isset($value) && $svg === ""93–100color(), size()
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && !->next_tag()109–119color(), size(), wp_get_icon(), ->next_tag(), get_block_wrapper_attributes()
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles)127–141color(), size(), wp_get_icon(), ->next_tag(), ->get_updated_html(), get_block_wrapper_attributes()
!empty($attributes) && !$attributes && !isset($value) && $svg !== "" && ->next_tag() && empty($styles)130–143color(), 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–144color(), 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–146color(), 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–147color(), 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–157color(), 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–150color(), 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–159color(), 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–160color(), 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–162color(), 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–163color(), 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–166color(), 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

PHPCompiledExecutedBranchesNotes
8.6-dev23393–16634
8.523393–16634
8.423393–16634
8.323393–16634
8.223393–16634
8.123393–166344 fewer instructions than PHP 7.4
7.423793–16734

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

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.

  1. 7.0.4
  2. 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.