AdvancedCustomFields / AdvancedCustomFields/acf
Color picker field wrongly returns rgba(0,0,0,0) for unset values
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
The color picker returns rgba(0,0,0,0) if the field value is unset. This is especially curious behaviour since the field value can be cleared using a dedicated "clear" button in the field UI.
The issue is easily reproducible, and the code leading to this misbehaviour is obvious in the string_to_array() function in class-acf-field-color_picker.php: If $value is empty, all the conditions fall through and rgba(0,0,0,0) is returned.
IMNSHO, the field should return false or null if the value is not set, in line with other fields. Alternatively, one could argue it should respect and return the default value if set. In any case, returning rgba(0,0,0,0) is wrong since it is not a null value but an actual color and especially wrong if one only were only to take the RGB components returned from an alpha-less color picker.
Edit: Of course one can test for rgba(0,0,0,0) and treat it as "unset" value down the line, but it still shouldn't return an rgba value in the first place, even if it's an obviously "wrong" one.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in class-acf-field-color_picker.php at the string_to_array() function and reproduce the unset-value case described in the issue. Review how other fields represent unset values and determine the expected null or false behavior, including whether a configured default should apply. Update the relevant behavior and verify that an unset color no longer becomes rgba(0,0,0,0).
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100