Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts API: Add missing files to lib/load.php #48108

Merged
merged 2 commits into from
Feb 15, 2023

Conversation

hellofromtonya
Copy link
Contributor

@hellofromtonya hellofromtonya commented Feb 15, 2023

Closed #48107.

What?

Load all of the deprecated files into memory.

Why?

To avoid fatal errors for sites that are actively using the non-deprecated architecture, i.e. before the API was renamed and redesigned.

How?

Add each file in lib/experimental/fonts-api/deprecations/ to the lib/load.php file.

Testing Instructions

  • Step 1: Activate the Twenty Twenty-Three theme.

  • Step 2: Activate the Gutenberg plugin.

  • Step 3: Upload this plugin file and then activate it.
    fonts-api-bc-tester.zip

  • Step 4: Reset the global styles to the default by:

    • Go to the Site Editor > Global Styles "Styles Beta" UI
    • Click on the 3 vertical dots
    • Select "Reset to defaults"
    • Click on the "Save" button
  • Step 5: Select a Playflair Display font for the headings. In the Google Styles UI

    • Select Typography.
    • Select Headings.
    • In FONT select Playflair Display (a Google Font).
    • In APPEARANCE, select Bold Italic. (Notice the heading should change)
    • Click on the "Save" button.
  • Step 6: Examine the dynamically generated @font-face stylings in the admin area by:

    • Open Dev Tools in your favorite browser
    • Search for wp-fonts-fonts-tester (which is in the <head>)
    • Expand the <style> element to inspect the CSS
    • The CSS should be:
<style id="wp-fonts-fonts-tester">
@font-face{font-family:"Playfair Display";font-style:normal;font-weight:100 900;font-display:fallback;src:local("Playfair Display"), url('/wp-content/plugins/fonts-api-bc-tester/fonts/PlayfairDisplay-VariableFont_wght.ttf') format('truetype');}@font-face{font-family:"Playfair Display";font-style:italic;font-weight:100 900;font-display:fallback;src:local("Playfair Display"), url('/wp-content/plugins/fonts-api-bc-tester/fonts/PlayfairDisplay-Italic-VariableFont_wght.ttf') format('truetype');}
</style>
  • Step 7: Examine the front-end by:
    • Go to the front-end of the website
    • Open Dev Tools in your favorite browser
    • Search for wp-fonts-fonts-tester
    • Expand the <style> element to inspect the CSS
    • The CSS should be the same as above.

@github-actions
Copy link

github-actions bot commented Feb 15, 2023

Flaky tests detected in 046fe87.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4187175706
📝 Reported issues:

@fullofcaffeine
Copy link
Member

Followed the test instructions, and tests well. I haven't verified the whole CSS, but the style element is present, and it starts with the @font-face for the Arvo font.

@fullofcaffeine
Copy link
Member

fullofcaffeine commented Feb 15, 2023

Tested again with the newly updated instructions. Seems to work fine. CSS in the backend and front is: https://gist.github.com/fullofcaffeine/9037402cd58f65cd29b9637df686cde2

Copy link
Member

@fullofcaffeine fullofcaffeine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@anton-vlasenko
Copy link
Contributor

anton-vlasenko commented Feb 15, 2023

When I examine the font-face stylings in the admin area and on FE, I get this (the order of the fonts is different). But, probably, that shouldn't affect anything.

<style id="wp-fonts-local">
@font-fa{font-family:"DM Sans";font-style:normal;font-weight:400;font-display:fallback;src:url('/wp-content/themes/twentytwentythree/assets/fonts/dm-sans/DMSans-Regular.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"DM Sans";font-style:italic;font-weight:400;font-display:fallback;src:url('/wp-content/themes/twentytwentythree/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"DM Sans";font-style:normal;font-weight:700;font-display:fallback;src:url('/wp-content/themes/twentytwentythree/assets/fonts/dm-sans/DMSans-Bold.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"DM Sans";font-style:italic;font-weight:700;font-display:fallback;src:url('/wp-content/themes/twentytwentythree/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"IBM Plex Mono";font-style:normal;font-weight:300;font-display:block;src:url('/wp-content/themes/twentytwentythree/assets/fonts/ibm-plex-mono/IBMPlexMono-Light.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"IBM Plex Mono";font-style:normal;font-weight:400;font-display:block;src:url('/wp-content/themes/twentytwentythree/assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"IBM Plex Mono";font-style:italic;font-weight:400;font-display:block;src:url('/wp-content/themes/twentytwentythree/assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"IBM Plex Mono";font-style:normal;font-weight:700;font-display:block;src:url('/wp-content/themes/twentytwentythree/assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:Inter;font-style:normal;font-weight:200 900;font-display:fallback;src:url('/wp-content/themes/twentytwentythree/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf') format('truetype');font-stretch:normal;}
@font-fa{font-family:"Source Serif Pro";font-style:normal;font-weight:200 900;font-display:fallback;src:url('/wp-content/themes/twentytwentythree/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2') format('woff2');font-stretch:normal;}
@font-fa{font-family:"Source Serif Pro";font-style:italic;font-weight:200 900;font-display:fallback;src:url('/wp-content/themes/twentytwentythree/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2') format('woff2');font-stretch:normal;}
</style>

Update: I've followed the test steps and everything works as described except for the order of font-face stylings. I don't know if that's important.

@hellofromtonya
Copy link
Contributor Author

Notes: The problem is not in the Google Fonts plugin. It's in a custom implementation that is using WP_Webfonts_Provider_Local. Let me see if I can create a test plugin to simulate it.

@hellofromtonya
Copy link
Contributor Author

@fullofcaffeine @anton-vlasenko @ironprogrammer The root of the problem is that a custom implementation is using WP_Webfonts_Provider_Local. I created a tester plugin that also uses that class. The tester instructions are updated in the description along with the zip of that plugin.

Can you please retest?

@ironprogrammer
Copy link
Contributor

Thanks for the patch, @hellofromtonya 🙌🏻

Test Report

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 12.6.3
  • Browser: Safari 16.3
  • Server: nginx/1.23.3
  • PHP: 7.4.33
  • WordPress: 6.2-beta2-55340-src
  • CLI: WP-CLI 2.7.1
  • Theme: twentytwentythree v1.0
  • Active Plugins:
    • debug-bar v1.1.4
    • gutenberg v15.2.0-rc.1
    • health-check v1.5.1
    • webfonts v1.0.0 (the test plugin provided here with the modification indicated below)

Actual Results

  • ✅ Fonts provided with the TT3 theme, emitted in the markup's <style> element #wp-fonts-local, are consistent when Global Styles are modified.
  • ✅ Fonts provided through the test plugin are selectable in the editor, emitted in the markup's <style> element #wp-fonts-jetpack-google-fonts, and display on the frontend with the assigned custom font face.
  • ✅ Referencing the deprecated class WP_Webfonts_Provider_Local in the test plugin no longer throws a fatal error, and logs the following: PHP Deprecated: Function WP_Webfonts_Provider_Local::__construct is <strong>deprecated</strong> since version GB 15.1! Use WP_Fonts_Provider_Local instead.

Additional Notes

  • To simulate the fatal error originally reported, the following was added to line 33 of the test plugin file:
$webfonts_provider = new WP_Webfonts_Provider_Local();

@hellofromtonya
Copy link
Contributor Author

Test Report

Env:

  • OS: macOS
  • Browser: Firefox, Edge, and Chrome
  • WordPress: 6.1.1
  • Theme: TT3
  • Active Plugins:
    • Gutenberg: 15.1.0
    • Fonts API BC Layer Tester: 1.0.0

Test Results

Before applying this PR

Upon activating the tester plugin, got a fatal error:

 Fatal error: Class 'WP_Webfonts_Provider_Local' not found in ../wp-content/plugins/fonts-api-bc-tester/class-fonts-provider.php on line 6

Yes, can reproduce the issue.

After applying this PR

  • Able to activate the tester plugin ✅
  • Following the test instructions:
    • Yes, <style id="wp-fonts-fonts-tester"> is in the HTML ✅
<style id="wp-fonts-fonts-tester">
@font-face{font-family:"Playfair Display";font-style:normal;font-weight:100 900;font-display:fallback;src:local("Playfair Display"), url('/wp-content/plugins/fonts-api-bc-tester/fonts/PlayfairDisplay-VariableFont_wght.ttf') format('truetype');}@font-face{font-family:"Playfair Display";font-style:italic;font-weight:100 900;font-display:fallback;src:local("Playfair Display"), url('/wp-content/plugins/fonts-api-bc-tester/fonts/PlayfairDisplay-Italic-VariableFont_wght.ttf') format('truetype');}
</style>
* Yes, the headings render properly to [`Playflair Display` font](https://fonts.google.com/specimen/Playfair+Display?query=Play) ✅ 

fonts-tester

Works as expected ✅

@hellofromtonya hellofromtonya merged commit 729efaa into trunk Feb 15, 2023
@hellofromtonya hellofromtonya deleted the fix/fonts-api/load-all-deprecated-files branch February 15, 2023 21:03
@github-actions github-actions bot added this to the Gutenberg 15.3 milestone Feb 15, 2023
@DaisyOlsen DaisyOlsen added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Feb 15, 2023
@hellofromtonya hellofromtonya added the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Feb 15, 2023
fullofcaffeine pushed a commit that referenced this pull request Feb 15, 2023
* Add missing files to lib/load.php`

* Guard loading the experimental files
DaisyOlsen pushed a commit that referenced this pull request Feb 16, 2023
* Add missing files to lib/load.php`

* Guard loading the experimental files
@DaisyOlsen DaisyOlsen added [Type] Bug An existing feature does not function as intended [Feature] Webfonts labels Feb 16, 2023
@DaisyOlsen DaisyOlsen removed Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) labels Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fonts API: Not all deprecated files are loaded into memory
5 participants