This is a bug that has been present for some time, but I finially got myself to reporting it:
Bricks 2.4.2, includes/assets.php, generate_css_rules_from_setting().
When a control declares more than one css definition and more than one of them uses the %s placeholder, the frontend CSS of the second (and every following) definition is broken. The builder canvas renders it correctly, because the JS implementation substitutes per definition.
Control:
'css' => [
[ 'property' => '--section-pt', 'value' => 'var(--section-pt-%s)' ],
[ 'property' => '--section-pb', 'value' => 'var(--section-pb-%s)' ],
],
Setting value none. Frontend output:
#brxe-vwmavn {
--section-pt: var(--section-pt-none);
--section-pb: var(--section-pb-var(--section-pt-none));
}
Cause
$setting_value is set once before the foreach ( $css_definitions as $css_definition ) loop (line 2975). Inside the loop the substitution writes its result back into the same variable:
// line 3137
$setting_value = str_replace( '%s', $setting_value, $css_definition['value'] );
The same happens at line 3135 for definitions without %s ($setting_value = $css_definition['value']). From the second iteration on, %s is therefore replaced with the previous definition’s output instead of the raw setting value.
Suggested fix
Keep the raw setting value per control and work on a per-definition copy, for example:
$raw_setting_value = $setting_value;
foreach ( $css_definitions as $css_definition ) {
$setting_value = $raw_setting_value;
// ... existing code unchanged
}
or write the substituted value into a separate variable ($css_value) and use that for the rest of the iteration. This would make the PHP generator behave like the builder’s JS.
Best Regards
Suat







