- Issue created by @makbay
- @makbay opened merge request.
There is a logic bug in the _get_color() function in the Barrio theme. It prevents heading, body and body background color values from resolving correctly when selecting named keys like 'primary', 'base', etc.
The current function is:
function _get_color($color, $colors) {
if (in_array($color, $colors)) {
return $colors[$color];
}
return $color;
}
However, in_array($color, $colors) checks for the value of $color in the $colors array, not the key. Since $colors is typically an associative array like:
$colors = [
'white' => $white,
'black' => '#000',
'gray-200' => $gray200,
'gray-800' => $gray800,
'primary' => $pc,
'secondary' => $sc,
];
...this condition fails even if $color is 'primary', 'secondary', etc.
The function silently returns the $color string (e.g., 'primary') rather than resolving it to a hex value like '#3366cc'.
I honestly don't understand how this has gone unnoticed until now.
Update the function to check if the key exists instead:
function _get_color($color, $colors) {
if (!empty($colors[$color])) {
return $colors[$color];
}
return $color;
}
This version correctly resolves the color from the associative array if it exists; otherwise it falls back to using the given value directly.
Active
5.5
Code