get_color_classes_for_block_core_search() – Returns color classnames depending on whether there are named or custom text and background colors.

You appear to be a bot. Output may be restricted

Description

Returns color classnames depending on whether there are named or custom text and background colors.

Usage

$string = get_color_classes_for_block_core_search( $attributes );

Parameters

$attributes
( array ) required – The block attributes.

Returns

string The color classnames to be applied to the block elements.

Source

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

1 to 35 of 35
function get_color_classes_for_block_core_search( $attributes ) {
  $classnames = array();

  // Text color.
  $has_named_text_color  = ! empty( $attributes['textColor'] );
  $has_custom_text_color = ! empty( $attributes['style']['color']['text'] );
  if ( $has_named_text_color ) {
    $classnames[] = sprintf( 'has-text-color has-%s-color', $attributes['textColor'] );
  } elseif ( $has_custom_text_color ) {
    // If a custom 'textColor' was selected instead of a preset, still add the generic `has-text-color` class.
    $classnames[] = 'has-text-color';
  }

  // Background color.
  $has_named_background_color  = ! empty( $attributes['backgroundColor'] );
  $has_custom_background_color = ! empty( $attributes['style']['color']['background'] );
  $has_named_gradient          = ! empty( $attributes['gradient'] );
  $has_custom_gradient         = ! empty( $attributes['style']['color']['gradient'] );
  if (
    $has_named_background_color ||
    $has_custom_background_color ||
    $has_named_gradient ||
    $has_custom_gradient
  ) {
    $classnames[] = 'has-background';
  }
  if ( $has_named_background_color ) {
    $classnames[] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] );
  }
  if ( $has_named_gradient ) {
    $classnames[] = sprintf( 'has-%s-gradient-background', $attributes['gradient'] );
  }

  return implode( ' ', $classnames );
}
 

 View on GitHub View on Trac