wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_resolve_block_style_variation_ref_values › WordPress Function

Depuis6.6.0
Dépréciéen/a
wp_resolve_block_style_variation_ref_values ( $variation_data, $theme_json )
Accès:
  • private
Paramètres: (2)
  • (array) $variation_data Reference to the variation data being processed.
    Requis: Oui
  • (array) $theme_json Theme.json data to retrieve referenced values from.
    Requis: Oui
Défini(e) dans:
Codex:

Recursively resolves any `ref` values within a block style variation's data.



Source

function wp_resolve_block_style_variation_ref_values( &$variation_data, $theme_json ) {
	foreach ( $variation_data as $key => &$value ) {
		// Only need to potentially process arrays.
		if ( is_array( $value ) ) {
			// If ref value is set, attempt to find its matching value and update it.
			if ( array_key_exists( 'ref', $value ) ) {
				// Clean up any invalid ref value.
				if ( empty( $value['ref'] ) || ! is_string( $value['ref'] ) ) {
					unset( $variation_data[ $key ] );
				}

				$value_path = explode( '.', $value['ref'] ?? '' );
				$ref_value  = _wp_array_get( $theme_json, $value_path );

				// Only update the current value if the referenced path matched a value.
				if ( null === $ref_value ) {
					unset( $variation_data[ $key ] );
				} else {
					$value = $ref_value;
				}
			} else {
				// Recursively look for ref instances.
				wp_resolve_block_style_variation_ref_values( $value, $theme_json );
			}
		}
	}
}