childNodes as $child ) { if ( ! $child instanceof DOMElement ) { continue; } $classes = explode( ' ', $child->getAttribute( 'class' ) ); if ( ! in_array( 'has-inline-color', $classes, true ) ) { continue; } $styles = css_string_to_array( $child->getAttribute( 'style' ) ); foreach ( $color_palette as $color ) { $hex_value = $styles['color'] ?? ''; $color_value = $color['color'] ?? ''; if ( ! $hex_value || ! $color_value ) { continue; } if ( $hex_value === $color_value ) { $styles['color'] = "var(--wp--preset--color--{$color['slug']})"; $child->setAttribute( 'style', css_array_to_string( $styles ) ); break; } } $html = $dom->saveHTML(); } return $html; }