wppaste
WordPress

block_core_navigation_submenu_build_css_colors( array $context, array $attributes, bool $is_sub_menu = false ): array

Since
5.9.0
Source
wp-includes/deprecated.php:5325
Build an array with CSS classes and inline styles defining the colors which will be applied to the navigation markup in the front-end.

Compatibility

Deprecated in WordPress 6.3.0. This was removed from the Navigation Submenu block in favour of <code>wp_apply_colors_support()</code>.<br> <code>wp_apply_colors_support()</code> returns an array with similar class and style values, but with different keys: <code>class</code> and <code>style</code>.

WordPress
since 5.9.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
Navigation block context.
$attributesarray
Block attributes.
$is_sub_menubooloptional
Whether the block is a sub-menu.Default: false

Return value

array
Colors CSS classes and inline styles.

Performance profile

How much work a call to block_core_navigation_submenu_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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
31–71

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

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 it touches

  • hookthird-party callbacksdo_action()one call below block_core_navigation_submenu_build_css_colors()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost block_core_navigation_submenu_build_css_colors() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$named_text_color === null && $named_background_color === null31–71_deprecated_function()
always38–71_deprecated_function(), array_push()
$named_text_color !== null && $named_background_color !== null46–70_deprecated_function(), array_push(), array_push()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10731–7118
8.510731–7118
8.410731–71184 fewer instructions than PHP 8.3
8.311131–7318
8.211131–7318
8.111131–7318
7.411131–7318

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 · 1

Source code

function block_core_navigation_submenu_build_css_colors( $context, $attributes, $is_sub_menu = false ) {	_deprecated_function( __FUNCTION__, '6.3.0' );	$colors = array(		'css_classes'   => array(),		'inline_styles' => '',	); 	// Text color.	$named_text_color  = null;	$custom_text_color = null; 	if ( $is_sub_menu && array_key_exists( 'customOverlayTextColor', $context ) ) {		$custom_text_color = $context['customOverlayTextColor'];	} elseif ( $is_sub_menu && array_key_exists( 'overlayTextColor', $context ) ) {		$named_text_color = $context['overlayTextColor'];	} elseif ( array_key_exists( 'customTextColor', $context ) ) {		$custom_text_color = $context['customTextColor'];	} elseif ( array_key_exists( 'textColor', $context ) ) {		$named_text_color = $context['textColor'];	} elseif ( isset( $context['style']['color']['text'] ) ) {		$custom_text_color = $context['style']['color']['text'];	} 	// If has text color.	if ( ! is_null( $named_text_color ) ) {		// Add the color class.		array_push( $colors['css_classes'], 'has-text-color', sprintf( 'has-%s-color', $named_text_color ) );	} elseif ( ! is_null( $custom_text_color ) ) {		// Add the custom color inline style.		$colors['css_classes'][]  = 'has-text-color';		$colors['inline_styles'] .= sprintf( 'color: %s;', $custom_text_color );	} 	// Background color.	$named_background_color  = null;	$custom_background_color = null; 	if ( $is_sub_menu && array_key_exists( 'customOverlayBackgroundColor', $context ) ) {		$custom_background_color = $context['customOverlayBackgroundColor'];	} elseif ( $is_sub_menu && array_key_exists( 'overlayBackgroundColor', $context ) ) {		$named_background_color = $context['overlayBackgroundColor'];	} elseif ( array_key_exists( 'customBackgroundColor', $context ) ) {		$custom_background_color = $context['customBackgroundColor'];	} elseif ( array_key_exists( 'backgroundColor', $context ) ) {		$named_background_color = $context['backgroundColor'];	} elseif ( isset( $context['style']['color']['background'] ) ) {		$custom_background_color = $context['style']['color']['background'];	} 	// If has background color.	if ( ! is_null( $named_background_color ) ) {		// Add the background-color class.		array_push( $colors['css_classes'], 'has-background', sprintf( 'has-%s-background-color', $named_background_color ) );	} elseif ( ! is_null( $custom_background_color ) ) {		// Add the custom background-color inline style.		$colors['css_classes'][]  = 'has-background';		$colors['inline_styles'] .= sprintf( 'background-color: %s;', $custom_background_color );	} 	return $colors;}

Changelog

Introduced in 5.9.0. Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

Signature, return type and hooks compared across 5 parsed releases.

6.3.0
Deprecated. This was removed from the Navigation Submenu block in favour of wp_apply_colors_support().
wp_apply_colors_support() returns an array with similar class and style values, but with different keys: class and style.from the docblock
5.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.3 tag, from src/wp-includes/deprecated.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.