WP_Theme_JSON::update_separator_declarations( array $declarations ): array

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Returns a filtered declarations array if there is a separator block with only a background style defined in theme.json by adding a color attribute to reflect the changes in the front.

Parameters

$declarationsarrayrequired
List of declarations.

Return

array $declarations List of declarations filtered.

Source

private static function update_separator_declarations( $declarations ) {
	$background_color     = '';
	$border_color_matches = false;
	$text_color_matches   = false;

	foreach ( $declarations as $declaration ) {
		if ( 'background-color' === $declaration['name'] && ! $background_color && isset( $declaration['value'] ) ) {
			$background_color = $declaration['value'];
		} elseif ( 'border-color' === $declaration['name'] ) {
			$border_color_matches = true;
		} elseif ( 'color' === $declaration['name'] ) {
			$text_color_matches = true;
		}

		if ( $background_color && $border_color_matches && $text_color_matches ) {
			break;
		}
	}

	if ( $background_color && ! $border_color_matches && ! $text_color_matches ) {
		$declarations[] = array(
			'name'  => 'color',
			'value' => $background_color,
		);
	}

	return $declarations;
}

Changelog

VersionDescription
6.1.1Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.