WP_Theme_JSON::merge( WP_Theme_JSON $incoming )

In this article

Merges new incoming data.

Parameters

$incomingWP_Theme_JSONrequired
Data to merge.

Source

 *
 * @return array The block nodes in theme.json.
 */
public function get_styles_block_nodes() {
	return static::get_block_nodes( $this->theme_json );
}

/**
 * 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.
 *
 * @since 6.1.1
 *
 * @param array $declarations List of declarations.
 * @return array $declarations List of declarations filtered.
 */
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;
}

/**
 * An internal method to get the block nodes from a theme.json file.
 *
 * @since 6.1.0
 * @since 6.3.0 Refactored and stabilized selectors API.
 * @since 6.6.0 Added optional selectors and options for generating block nodes.
 *
 * @param array $theme_json The theme.json converted to an array.
 * @param array $selectors  Optional list of selectors per block.
 * @param array $options {
 *     Optional. An array of options for now used for internal purposes only (may change without notice).
 *
 *     @type bool   $include_block_style_variations  Includes nodes for block style variations. Default false.
 * }
 * @return array The block nodes in theme.json.
 */
private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) {
	$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
	$nodes     = array();
	if ( ! isset( $theme_json['styles'] ) ) {
		return $nodes;
	}

	// Blocks.
	if ( ! isset( $theme_json['styles']['blocks'] ) ) {
		return $nodes;
	}

	foreach ( $theme_json['styles']['blocks'] as $name => $node ) {
		$selector = null;
		if ( isset( $selectors[ $name ]['selector'] ) ) {
			$selector = $selectors[ $name ]['selector'];
		}

		$duotone_selector = null;
		if ( isset( $selectors[ $name ]['duotone'] ) ) {
			$duotone_selector = $selectors[ $name ]['duotone'];
		}

		$feature_selectors = null;

Changelog

VersionDescription
5.9.0Duotone preset also has origins.
5.8.0Introduced.

User Contributed Notes

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