[wp-trac] [WordPress Trac] #55962: Upgrade `sanitize_hex_color()` to CSS Color Level 4

WordPress Trac noreply at wordpress.org
Sat Jun 11 15:19:01 UTC 2022


#55962: Upgrade `sanitize_hex_color()` to CSS Color Level 4
------------------------------------------+-----------------------------
 Reporter:  anrghg                        |       Owner:  (none)
     Type:  enhancement                   |      Status:  new
 Priority:  normal                        |   Milestone:  Future Release
Component:  Formatting                    |     Version:
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:  css
------------------------------------------+-----------------------------

Comment (by anrghg):

 Thank you all for looking into this.

 I’m fine with the outcome as long as WordPress does not make this specific
 color code sanitization a requirement.

 The existing function works well on output from browsers’ built-in color
 pickers not supporting alpha either.

 If storage is limited to 3 hex digits, a more appropriate function must be
 used instead. If storage is limited to 6 hex digits, without sanitization
 it could be used for a limited 4‑digit hex with alpha workaround.

 I see an issue with configuration filters, that users may wish to use for
 opacity as well.

 However, that issue goes beyond adding support for alpha, as users may as
 well wish to set colors in decimal RGB format, using `rgb()` or `rgba()`
 functions interchangeably, or in HSL format.

 As for naming the **new** function, I’d strongly recommend to opt for
 `sanitize_any_hex_color()`, regardless of alpha provided or not, or it
 would not be backward compatible.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55962#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list