WP_Theme_JSON::get_feature_declarations_for_node( object $metadata, object $node ): array

In this article

Generates style declarations for a node’s features e.g., color, border, typography etc. that have custom selectors in their related block’s metadata.

Parameters

$metadataobjectrequired
The related block metadata containing selectors.
$nodeobjectrequired
A merged theme.json node for block or variation.

Return

array The style declarations for the node’s features with custom selectors.

Source

	}

	if ( empty( $sanitized['settings'] ) ) {
		unset( $theme_json['settings'] );
	} else {
		$theme_json['settings'] = $sanitized['settings'];
	}

	return $theme_json;
}

/**
 * Processes a setting node and returns the same node
 * without the insecure settings.
 *
 * @since 5.9.0
 *
 * @param array $input Node to process.
 * @return array
 */
protected static function remove_insecure_settings( $input ) {
	$output = array();
	foreach ( static::PRESETS_METADATA as $preset_metadata ) {
		foreach ( static::VALID_ORIGINS as $origin ) {
			$path_with_origin   = $preset_metadata['path'];
			$path_with_origin[] = $origin;
			$presets            = _wp_array_get( $input, $path_with_origin, null );
			if ( null === $presets ) {
				continue;
			}

			$escaped_preset = array();
			foreach ( $presets as $preset ) {
				if (
					esc_attr( esc_html( $preset['name'] ) ) === $preset['name'] &&
					sanitize_html_class( $preset['slug'] ) === $preset['slug']
				) {
					$value = null;
					if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) {
						$value = $preset[ $preset_metadata['value_key'] ];
					} elseif (
						isset( $preset_metadata['value_func'] ) &&
						is_callable( $preset_metadata['value_func'] )
					) {
						$value = call_user_func( $preset_metadata['value_func'], $preset );
					}

					$preset_is_valid = true;
					foreach ( $preset_metadata['properties'] as $property ) {
						if ( ! static::is_safe_css_declaration( $property, $value ) ) {
							$preset_is_valid = false;
							break;
						}
					}

					if ( $preset_is_valid ) {
						$escaped_preset[] = $preset;
					}
				}
			}

			if ( ! empty( $escaped_preset ) ) {
				_wp_array_set( $output, $path_with_origin, $escaped_preset );
			}
		}
	}

	// Ensure indirect properties not included in any `PRESETS_METADATA` value are allowed.
	static::remove_indirect_properties( $input, $output );

	return $output;
}

/**
 * Processes a style node and returns the same node
 * without the insecure styles.
 *
 * @since 5.9.0
 *
 * @param array $input Node to process.
 * @return array
 */
protected static function remove_insecure_styles( $input ) {
	$output       = array();
	$declarations = static::compute_style_properties( $input );

	foreach ( $declarations as $declaration ) {
		if ( static::is_safe_css_declaration( $declaration['name'], $declaration['value'] ) ) {
			$path = static::PROPERTIES_METADATA[ $declaration['name'] ];

			/*
			 * Check the value isn't an array before adding so as to not
			 * double up shorthand and longhand styles.
			 */
			$value = _wp_array_get( $input, $path, array() );
			if ( ! is_array( $value ) ) {
				_wp_array_set( $output, $path, $value );

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

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