Make WordPress Core

Changeset 56540


Ignore:
Timestamp:
09/07/2023 05:28:59 PM (19 months ago)
Author:
hellofromTonya
Message:

Fonts: Removes static instance in wp_print_font_faces().

The static instance of WP_Font_Face is not needed. It was an unnecessary carryover from the experimental Fonts API (which was not introduced into Core).

Whereas the Fonts API needed to persist its data (i.e. to maintain the registered and enqueued fonts throughout the web request), Font Face does not have data to persist.

Font Face processes the fonts it receives when WP_Font_Face::generate_and_print( $fonts ) is invoked. Thus, a singleton is not needed.

Removing the static reduces the amount of the code in the function and eliminates running its tests in separate processes to ensure a different instance is always used.

References:

Follow-up to [56500].

Props hellofromTonya, costdev.
Fixes #59165.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/fonts.php

    r56500 r56540  
    4040 */
    4141function wp_print_font_faces( $fonts = array() ) {
    42     static $wp_font_face = null;
    4342
    4443    if ( empty( $fonts ) ) {
     
    5049    }
    5150
    52     if ( null === $wp_font_face ) {
    53         $wp_font_face = new WP_Font_Face();
    54     }
    55 
     51    $wp_font_face = new WP_Font_Face();
    5652    $wp_font_face->generate_and_print( $fonts );
    5753}
  • trunk/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php

    r56500 r56540  
    77 *
    88 * @since 6.4.0
    9  */
    10 require_once __DIR__ . '/base.php';
    11 
    12 /**
     9 *
    1310 * @group fonts
    1411 * @group fontface
    1512 *
    1613 * @covers wp_print_font_faces
    17  *
    18  * @runTestsInSeparateProcesses
    19  * @preserveGlobalState disabled
    2014 */
    2115class Tests_Fonts_WpPrintFontFaces extends WP_Font_Face_UnitTestCase {
Note: See TracChangeset for help on using the changeset viewer.