block_core_home_link_build_css_colors( array $context ): array
- Since
- 6.0.0
- Source
wp-includes/blocks/home-link.php:17
Compatibility
- WordPress
- since 6.0.0
- PHP
- 7.4–8.6-dev
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$contextarray- home link block context.
Return value
array- Colors CSS classes and inline styles.
Performance profile
How much work a call to block_core_home_link_build_css_colors() 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
- 17–41
- Plugin surface
- None
- Called by
- 1
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 57.
Nothing here hands control to plugin code.
1 place 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 block_core_home_link_build_css_colors() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 17–41 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 57 | 17–41 | 8 | |
| 8.5 | 57 | 17–41 | 8 | |
| 8.4 | 57 | 17–41 | 8 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 61 | 17–43 | 8 | |
| 8.2 | 61 | 17–43 | 8 | |
| 8.1 | 61 | 17–43 | 8 | |
| 7.4 | 61 | 17–43 | 8 |
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.
Used by · 1
- block_core_home_link_build_li_wrapper_attributes()Builds an array with classes and style for the li wrapper
Source code
function block_core_home_link_build_css_colors( $context ) { $colors = array( 'css_classes' => array(), 'inline_styles' => '', ); // Text color. $has_named_text_color = array_key_exists( 'textColor', $context ); $has_custom_text_color = isset( $context['style']['color']['text'] ); // If has text color. if ( $has_custom_text_color || $has_named_text_color ) { // Add has-text-color class. $colors['css_classes'][] = 'has-text-color'; } if ( $has_named_text_color ) { // Add the color class. $colors['css_classes'][] = sprintf( 'has-%s-color', $context['textColor'] ); } elseif ( $has_custom_text_color ) { // Add the custom color inline style. $colors['inline_styles'] .= sprintf( 'color: %s;', $context['style']['color']['text'] ); } // Background color. $has_named_background_color = array_key_exists( 'backgroundColor', $context ); $has_custom_background_color = isset( $context['style']['color']['background'] ); // If has background color. if ( $has_custom_background_color || $has_named_background_color ) { // Add has-background class. $colors['css_classes'][] = 'has-background'; } if ( $has_named_background_color ) { // Add the background-color class. $colors['css_classes'][] = sprintf( 'has-%s-background-color', $context['backgroundColor'] ); } elseif ( $has_custom_background_color ) { // Add the custom background-color inline style. $colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['style']['color']['background'] ); } return $colors;}Changelog
Introduced in 6.0.0. Unchanged from 6.7.10 through 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.3 tag, from
src/wp-includes/blocks/home-link.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.