Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4746cdb
Initial plan
Copilot Feb 16, 2026
b587706
Add color slug resolution for advanced-heading block
Copilot Feb 16, 2026
d32169a
Build project successfully with color slug resolution
girishpanchal30 Apr 1, 2026
efb938a
Add useColorResolver hook for easier color slug resolution
Copilot Feb 16, 2026
bf522a5
Add documentation for color slug resolution
Copilot Feb 16, 2026
2ea551f
Fix trailing whitespace issues from code review
Copilot Feb 16, 2026
e08252c
Apply color slug resolution fix to circle-counter, countdown, sharing…
Copilot Feb 16, 2026
ff9a9ad
Apply color slug resolution to high-priority blocks (button, section,…
Copilot Feb 16, 2026
013c0da
Use CSS variables to preserve color slug connection to theme.json
Copilot Feb 19, 2026
c4f3f70
Add slug sanitization and improve documentation clarity
Copilot Feb 19, 2026
75d0ccb
Add comprehensive implementation summary documentation
Copilot Feb 19, 2026
ad981f1
Remove extra documentation and add unit tests for color CSS variable …
Copilot Feb 19, 2026
cd57850
Allow underscores in color slug sanitization per WordPress conventions
Copilot Feb 19, 2026
890c765
Remove color-slug-resolution.md documentation file
Copilot Feb 19, 2026
8079ae9
Fix JSDoc alignment error in helper-functions.js
Copilot Feb 19, 2026
e6c672c
Fix useDarkBackground to handle color slugs properly
Copilot Feb 19, 2026
b66e456
Add robust type checking and error handling to color functions
Copilot Feb 19, 2026
90a6c99
Simplify useColorResolver hook - remove unused palette dependency
Copilot Feb 23, 2026
243efd2
Fix accordion and tabs blocks to use color slug resolution
Copilot Feb 23, 2026
aaca3d9
Fix React Hooks dependencies in accordion block
Copilot Feb 23, 2026
0c7f0b8
Remove unnecessary dependency from useCallback in accordion
Copilot Feb 23, 2026
e008e63
Revert useCallback wrapping of getValue to fix accordion initialization
Copilot Feb 23, 2026
d5e0cf5
Add test infrastructure for e2e tests (emptytheme, wp-env.json)
Copilot Feb 23, 2026
8d9714d
Add comprehensive E2E test setup documentation
Copilot Feb 23, 2026
dda1c64
Revert e2e testing infrastructure additions (already exists in repo)
Copilot Feb 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions inc/class-base-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,54 @@ public static function hex2rgba( $color, $opacity = false ) {
return $output;
}

/**
* Convert a color slug to a CSS variable reference.
* WordPress generates CSS variables in the format: --wp--preset--color--{slug}
*
* @param string|null $slug The color slug.
* @return string|null The CSS variable reference.
* @since 3.1.5
* @access public
*/
public static function get_color_css_variable( $slug ) {
if ( empty( $slug ) ) {
return $slug;
}

// If it's already a color value or CSS variable, return as-is.
if (
strpos( $slug, '#' ) === 0 ||
strpos( $slug, 'rgb' ) === 0 ||
strpos( $slug, 'hsl' ) === 0 ||
strpos( $slug, 'var(' ) === 0
) {
return $slug;
}

// Sanitize slug: WordPress slugs should only contain lowercase alphanumeric, hyphens, and underscores.
// This prevents potential CSS injection if slug comes from untrusted sources.
$sanitized_slug = strtolower( preg_replace( '/[^a-z0-9-_]/', '', $slug ) );

// Convert slug to CSS variable.
return 'var(--wp--preset--color--' . $sanitized_slug . ')';
}

/**
* Resolve a color value which may be a slug from the theme color palette.
* This function converts slugs to CSS variables to preserve the connection to theme.json.
* If the value is a slug, it returns a CSS variable reference.
* Otherwise, returns the value as-is (for hex, rgb, hsl values).
*
* @param string|null $value The color value or slug.
* @return string|null The CSS variable or color value.
* @since 3.1.5
* @access public
*/
public static function resolve_color_value( $value ) {
// Use CSS variable conversion for slugs.
return self::get_color_css_variable( $value );
}

/**
* Get Blocks CSS
*
Expand Down
3 changes: 3 additions & 0 deletions inc/css/blocks/class-advanced-column-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ function ( $value ) use ( $block ) {
array(
'property' => '--background-color-hover',
'value' => 'backgroundColorHover',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'align-self',
Expand Down
18 changes: 18 additions & 0 deletions inc/css/blocks/class-advanced-heading-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'headingColor',
'format' => function ( $value, $attrs ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'background',
'value' => 'backgroundColor',
'format' => function ( $value, $attrs ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'font-family',
Expand Down Expand Up @@ -225,10 +231,16 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'highlightColor',
'format' => function ( $value, $attrs ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'background',
'value' => 'highlightBackground',
'format' => function ( $value, $attrs ) {
return Base_CSS::resolve_color_value( $value );
},
),
);

Expand Down Expand Up @@ -537,6 +549,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'linkColor',
'format' => function ( $value, $attrs ) {
return Base_CSS::resolve_color_value( $value );
},
),
),
)
Expand All @@ -549,6 +564,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'linkHoverColor',
'format' => function ( $value, $attrs ) {
return Base_CSS::resolve_color_value( $value );
},
),
),
)
Expand Down
36 changes: 36 additions & 0 deletions inc/css/blocks/class-button-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ public function render_css( $block ) {
'property' => 'color',
'value' => 'color',
'hasSync' => 'gr-btn-color',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'background',
'value' => 'background',
'hasSync' => 'gr-btn-background',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'background',
Expand All @@ -150,6 +156,9 @@ public function render_css( $block ) {
'property' => 'border-color',
'value' => 'border',
'hasSync' => 'gr-btn-border-color',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'box-shadow',
Expand Down Expand Up @@ -201,11 +210,17 @@ public function render_css( $block ) {
'property' => 'color',
'value' => 'hoverColor',
'hasSync' => 'gr-btn-color-hover',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'background',
'value' => 'hoverBackground',
'hasSync' => 'gr-btn-background-hover',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'background',
Expand All @@ -216,6 +231,9 @@ public function render_css( $block ) {
'property' => 'border-color',
'value' => 'hoverBorder',
'hasSync' => 'gr-btn-border-color-hover',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'box-shadow',
Expand Down Expand Up @@ -298,10 +316,16 @@ public function render_global_css() {
array(
'property' => '--gr-btn-color',
'value' => 'color',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--gr-btn-background',
'value' => 'background',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--gr-btn-background',
Expand Down Expand Up @@ -336,6 +360,9 @@ public function render_global_css() {
array(
'property' => '--gr-btn-border-color',
'value' => 'border',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
'condition' => function ( $attrs ) {
return isset( $attrs['border'] ) && ! empty( $attrs['border'] );
},
Expand Down Expand Up @@ -421,10 +448,16 @@ public function render_global_css() {
array(
'property' => '--gr-btn-color-hover',
'value' => 'hoverColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--gr-btn-background-hover',
'value' => 'hoverBackground',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--gr-btn-background-hover',
Expand All @@ -433,6 +466,9 @@ public function render_global_css() {
array(
'property' => '--gr-btn-border-color-hover',
'value' => 'hoverBorder',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--gr-btn-shadow-hover',
Expand Down
14 changes: 10 additions & 4 deletions inc/css/blocks/class-circle-counter-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public function render_css( $block ) {
$percentage = isset( $attrs['percentage'] ) ? $attrs['percentage'] : 50;

if ( 50 > $percentage ) {
return isset( $attrs['progressColor'] ) ? $attrs['progressColor'] : '#3878ff';
return isset( $attrs['progressColor'] ) ? Base_CSS::resolve_color_value( $attrs['progressColor'] ) : '#3878ff';
}

return $value;
return Base_CSS::resolve_color_value( $value );
},
),
array(
Expand All @@ -80,10 +80,10 @@ public function render_css( $block ) {
$percentage = isset( $attrs['percentage'] ) ? $attrs['percentage'] : 50;

if ( 50 > $percentage ) {
return isset( $attrs['backgroundColor'] ) ? $attrs['backgroundColor'] : '#4682b426';
return isset( $attrs['backgroundColor'] ) ? Base_CSS::resolve_color_value( $attrs['backgroundColor'] ) : '#4682b426';
}

return $value;
return Base_CSS::resolve_color_value( $value );
},
),
array(
Expand Down Expand Up @@ -132,6 +132,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'titleColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
),
)
Expand All @@ -144,6 +147,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'progressColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
),
)
Expand Down
15 changes: 15 additions & 0 deletions inc/css/blocks/class-countdown-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ public function render_css( $block ) {
array(
'property' => '--background-color',
'value' => 'backgroundColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--border-color',
'value' => 'borderColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--border-style',
Expand Down Expand Up @@ -279,6 +285,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'valueColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
),
)
Expand All @@ -291,6 +300,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'labelColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
),
)
Expand All @@ -303,6 +315,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'separatorColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
),
)
Expand Down
15 changes: 15 additions & 0 deletions inc/css/blocks/class-flip-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public function render_css( $block ) {
array(
'property' => '--border-color',
'value' => 'borderColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => '--border-width',
Expand Down Expand Up @@ -136,6 +139,9 @@ public function render_css( $block ) {
array(
'property' => '--front-background',
'value' => 'frontBackgroundColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
'condition' => function ( $attrs ) {
return ! isset( $attrs['frontBackgroundType'] );
},
Expand Down Expand Up @@ -198,6 +204,9 @@ public function render_css( $block ) {
array(
'property' => '--back-background',
'value' => 'backBackgroundColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
'condition' => function ( $attrs ) {
return ! isset( $attrs['backBackgroundType'] );
},
Expand Down Expand Up @@ -373,6 +382,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'titleColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'font-size',
Expand All @@ -392,6 +404,9 @@ public function render_css( $block ) {
array(
'property' => 'color',
'value' => 'descriptionColor',
'format' => function ( $value ) {
return Base_CSS::resolve_color_value( $value );
},
),
array(
'property' => 'font-size',
Expand Down
Loading
Loading