block_core_navigation_build_css_colors() – Build an array with CSS classes and inline styles defining the colors which will be applied to the navigation markup in the front-end.

You appear to be a bot. Output may be restricted

Description

Build an array with CSS classes and inline styles defining the colors which will be applied to the navigation markup in the front-end.

Usage

$array = block_core_navigation_build_css_colors( $attributes );

Parameters

$attributes
( array ) required – Navigation block attributes.

Returns

array Colors CSS classes and inline styles.

Source

File name: wordpress/wp-includes/blocks/navigation.php
Lines:

1 to 82 of 82
function block_core_navigation_build_css_colors( $attributes ) {
  $colors = array(
    'css_classes'           => array(),
    'inline_styles'         => '',
    'overlay_css_classes'   => array(),
    'overlay_inline_styles' => '',
  );

  // Text color.
  $has_named_text_color  = array_key_exists( 'textColor', $attributes );
  $has_custom_text_color = array_key_exists( 'customTextColor', $attributes );

  // 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', $attributes['textColor'] );
  } elseif ( $has_custom_text_color ) {
    // Add the custom color inline style.
    $colors['inline_styles'] .= sprintf( 'color: %s;', $attributes['customTextColor'] );
  }

  // Background color.
  $has_named_background_color  = array_key_exists( 'backgroundColor', $attributes );
  $has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes );

  // 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', $attributes['backgroundColor'] );
  } elseif ( $has_custom_background_color ) {
    // Add the custom background-color inline style.
    $colors['inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] );
  }

  // Overlay text color.
  $has_named_overlay_text_color  = array_key_exists( 'overlayTextColor', $attributes );
  $has_custom_overlay_text_color = array_key_exists( 'customOverlayTextColor', $attributes );

  // If has overlay text color.
  if ( $has_custom_overlay_text_color || $has_named_overlay_text_color ) {
    // Add has-text-color class.
    $colors['overlay_css_classes'][] = 'has-text-color';
  }

  if ( $has_named_overlay_text_color ) {
    // Add the overlay color class.
    $colors['overlay_css_classes'][] = sprintf( 'has-%s-color', $attributes['overlayTextColor'] );
  } elseif ( $has_custom_overlay_text_color ) {
    // Add the custom overlay color inline style.
    $colors['overlay_inline_styles'] .= sprintf( 'color: %s;', $attributes['customOverlayTextColor'] );
  }

  // Overlay background color.
  $has_named_overlay_background_color  = array_key_exists( 'overlayBackgroundColor', $attributes );
  $has_custom_overlay_background_color = array_key_exists( 'customOverlayBackgroundColor', $attributes );

  // If has overlay background color.
  if ( $has_custom_overlay_background_color || $has_named_overlay_background_color ) {
    // Add has-background class.
    $colors['overlay_css_classes'][] = 'has-background';
  }

  if ( $has_named_overlay_background_color ) {
    // Add the overlay background-color class.
    $colors['overlay_css_classes'][] = sprintf( 'has-%s-background-color', $attributes['overlayBackgroundColor'] );
  } elseif ( $has_custom_overlay_background_color ) {
    // Add the custom overlay background-color inline style.
    $colors['overlay_inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customOverlayBackgroundColor'] );
  }

  return $colors;
}
 

 View on GitHub View on Trac