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

WordPress Trac noreply at wordpress.org
Sat Jun 11 04:57:08 UTC 2022


#55962: Upgrade `sanitize_hex_color()` to CSS Color Level 4
--------------------------+-----------------------------
 Reporter:  anrghg        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:
 Severity:  normal        |   Keywords:
  Focuses:  css           |
--------------------------+-----------------------------
 I’ve noticed that the `sanitize_hex_color()` function unsupports the CSS
 Color Level 4 with the alpha channel and can therefore not be used. As
 users are given the ability to provide settings by configuration filters
 in a mini-plugin or in their theme’s `functions.php`, they may wish to
 configure opacity alongside.

 The fix is to extend the validation condition of `sanitize_hex_color()`
 from:

 `if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )`

 to

 `if ( preg_match( '|^#([A-Fa-f0-9]{3,4}){1,2}$|', $color ) )`

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


More information about the wp-trac mailing list