[wp-trac] [WordPress Trac] #56078: PHP Warning when adding fonts to fontFamilies in wp_global_styles post

WordPress Trac noreply at wordpress.org
Fri Nov 18 22:47:23 UTC 2022


#56078: PHP Warning when adding fonts to fontFamilies in wp_global_styles post
-----------------------------------+---------------------------------------
 Reporter:  domainsupport          |       Owner:  (none)
     Type:  defect (bug)           |      Status:  new
 Priority:  normal                 |   Milestone:  6.2
Component:  Editor                 |     Version:  6.0
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch needs-       |     Focuses:  administration, template
  testing                          |
-----------------------------------+---------------------------------------

Comment (by azaozz):

 Replying to [comment:11 domainsupport]:
 > the easiest way to demonstrate that is to install Template Editor plugin

 Thanks, this is really helpful.

 > the way that `script-loader.php` loads the fonts from those in the
 `wp_global_styles` post ''and'' then merges them with those from
 `theme.json` suggests that it is expected

 I tried to reproduce this without using the Template Editor plugin, but
 seems it's not possible. Assuming there are very few cases, if any, where
 this bug is triggered. That's not surprising as
 `_wp_theme_json_webfonts_handler()` is clearly marked as a temporary
 solution: "A future public Webfonts API will replace this stopgap code.".

 At the same time the use of `array_unique()` is still a bug and should
 probably be fixed, even in this temporary code.

 > are you saying you'd like me to amend the patch accordingly rather than
 just adding `SORT_REGULAR` which prevents the PHP notification?

 The intention here is to make sure no duplicate font families remain in
 the settings after merging them with the fonts from theme.json. As far as
 I see `fontFamily` is the identification, so probably best to ensure there
 are no duplicates of it even if `name` and `slug` are not the same.
 Perhaps the function that looks in the arrays and compares sub-array
 elements would work best.

 On the other hand this is a temporary, stopgap code that is going to be
 removed soon (I hope), so maybe adding `SORT_REGULAR` would be enough.
 Going to ping @hellofromTonya here for a decision.

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


More information about the wp-trac mailing list