Commit 4973e7dc1f for wordpress.org

commit 4973e7dc1f372cb68c33351ef13de3ba49ca1f1e
Author: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Date:   Wed Sep 16 18:26:48 2026 +0000

    Editor: Kebab-case preset slugs when converting references to custom properties.

    `WP_Theme_JSON` kebab-cases a preset slug when generating its custom property but
    converted `var:preset|type|slug` references verbatim, so a slug that changes under
    kebab-casing (e.g. `n27`) referenced a property that was never declared and the
    style silently fell back.
    Kebab-case the slug segment of three-segment preset references with the same
    `_wp_to_kebab_case()` used to generate them.

    Developed in: https://github.com/WordPress/wordpress-develop/pull/12656

    Props jorgefilipecosta, ramonopoly, oandregal, fabiankaegy, greenshady, mmaattiiaass.
    Fixes #66121.
    Built from https://develop.svn.wordpress.org/trunk@63641


    git-svn-id: http://core.svn.wordpress.org/trunk@62816 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php
index fb41bde81a..087c215e56 100644
--- a/wp-includes/class-wp-theme-json.php
+++ b/wp-includes/class-wp-theme-json.php
@@ -5635,6 +5635,7 @@ class WP_Theme_JSON {
 	 * For example, `var:preset|color|vivid-green-cyan` becomes `var(--wp--preset--color--vivid-green-cyan)`.
 	 *
 	 * @since 6.3.0
+	 * @since 7.2.0 Preset reference slugs are kebab-cased to match the generated custom properties.
 	 *
 	 * @param string $value The variable such as var:preset|color|vivid-green-cyan to convert.
 	 * @return string The converted variable.
@@ -5645,12 +5646,29 @@ class WP_Theme_JSON {
 		$token_in   = '|';
 		$token_out  = '--';
 		if ( str_starts_with( $value, $prefix ) ) {
-			$unwrapped_name = str_replace(
-				$token_in,
-				$token_out,
-				substr( $value, $prefix_len )
-			);
-			$value          = "var(--wp--$unwrapped_name)";
+			$parts = explode( $token_in, substr( $value, $prefix_len ) );
+
+			/*
+			 * The slug of a preset reference is kebab-cased so the resulting
+			 * custom property matches the one generated from the preset,
+			 * whose slug is also kebab-cased (see `get_settings_values_by_slug()`).
+			 * For slugs that are not already kebab-cased (e.g. `n27`), a verbatim
+			 * conversion produces a reference to a custom property that does
+			 * not exist (`--wp--preset--font-family--n27` instead of the
+			 * generated `--wp--preset--font-family--n-27`).
+			 *
+			 * Duotone is the exception: its custom properties are generated by
+			 * `WP_Duotone` from the presets it registers in
+			 * `get_all_global_styles_presets()`. Duotone references are
+			 * kebab-cased all the same: the editor and the JS style engine
+			 * kebab-case the references of every preset type, and
+			 * `WP_Duotone` looks up presets by kebab-cased filter ID.
+			 */
+			if ( 3 === count( $parts ) && 'preset' === $parts[0] ) {
+				$parts[2] = _wp_to_kebab_case( $parts[2] );
+			}
+
+			$value = 'var(--wp--' . implode( $token_out, $parts ) . ')';
 		}

 		return $value;
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 0be594d2ef..c86d928f4c 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-alpha-63640';
+$wp_version = '7.2-alpha-63641';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.