Incorrect logic in _get_color() causes color values useless

Created on 6 May 2025, 12 days ago

Problem/Motivation

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.

As a result:

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.

Proposed fix

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.

🐛 Bug report
Status

Active

Version

5.5

Component

Code

Created by

🇹🇷Turkey makbay

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024