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

WordPress Trac noreply at wordpress.org
Mon Jun 27 16:05:26 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:  Awaiting Review
Component:  Editor         |     Version:  6.0
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:  administration, template
---------------------------+---------------------------------------
Description changed by sabernhardt:

Old description:

> I am injecting additional Google Fonts to the Full Site Editor global
> styles by adding elements to
> **['settings']['typography']['fontFamilies']** of the
> **wp_global_styles** post type in the database (rather than users having
> to modify the theme.json or having to create a child theme).
>
> Which works! :)
>
> However, it is presenting the following error ...
>
> [27-Jun-2022 14:08:45 UTC] PHP Warning:  Array to string conversion in
> /wp-includes/script-loader.php on line 3100
>
> I suspect this is because on line 3100 of script-loader.php ...
>
> {{{#!php
> <?php
>                                 $settings['typography']['fontFamilies']
> = array_unique( $settings['typography']['fontFamilies'] );
> }}}
>

> ... is being used to make sure the font families are not duplicated ...
> however, you can only use array_unique with an array of string values,
> but "fontFamilies" is an array of arrays. I believe this line should be
> changed to ...
>
> {{{#!php
> <?php
>                                 $settings['typography']['fontFamilies']
> = array_unique( $settings['typography']['fontFamilies'], SORT_REGULAR);
> }}}
>

> Please confirm and I'll create a patch file if you like.
>
> Thanks,
>
> Oliver

New description:

 I am injecting additional Google Fonts to the Full Site Editor global
 styles by adding elements to `['settings']['typography']['fontFamilies']`
 of the **wp_global_styles** post type in the database (rather than users
 having to modify the theme.json or having to create a child theme).

 Which works! :)

 However, it is presenting the following error ...

 [27-Jun-2022 14:08:45 UTC] PHP Warning:  Array to string conversion in
 /wp-includes/script-loader.php on line 3100

 I suspect this is because on line 3100 of script-loader.php ...

 {{{#!php
 <?php
                                 $settings['typography']['fontFamilies']
 = array_unique( $settings['typography']['fontFamilies'] );
 }}}


 ... is being used to make sure the font families are not duplicated ...
 however, you can only use array_unique with an array of string values, but
 "fontFamilies" is an array of arrays. I believe this line should be
 changed to ...

 {{{#!php
 <?php
                                 $settings['typography']['fontFamilies']
 = array_unique( $settings['typography']['fontFamilies'], SORT_REGULAR);
 }}}


 Please confirm and I'll create a patch file if you like.

 Thanks,

 Oliver

--

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


More information about the wp-trac mailing list