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

Add /wp-content/fonts/ directory to file paths #633

Conversation

ironprogrammer
Copy link
Contributor

What is this PR doing?

Adds support for the Font Library's font storage location, /wp-content/fonts/ as of WordPress/gutenberg#54122.

What problem is it solving?

Fonts uploaded into a Playgrounds instance do not have their paths resolved properly, resulting in a 404 for user-uploaded font files.

How is the problem addressed?

Adds /wp-content/fonts/ to the allowed file paths, so that user-uploaded font paths are rewritten for browser in-memory scope.

Testing Instructions

Run/compare the following Playgrounds instances, which include Gutenberg PR #53884:

  1. Open Styles > Typography.
  2. Activate the Font management dialog by clicking the "Aa" icon above the fonts list.
  3. Upload a font file (e.g. .woff2 or .ttf file). The font should activate automatically.
  4. Select the Headings element and assign the uploaded font from the picker.
  5. Click Activate & Save.
  6. Navigate to the frontend of the Playgrounds site.
  7. Observe the font applied to headings. The font file should load properly (no 404).
  8. Click "Edit Site" to navigate back to the editor.
  9. Observe the font applied to headings in the editor. It should load properly.

Note Regarding Initial Font Display in Editor

In Step 4, the new font may not display correctly on headings. This is due to an issue that will be addressed in WordPress/gutenberg#54313. Until this is merged, the editor will need to be reloaded in order to account for the newly added font file.

Copy link
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

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

Seems fine. Seeing this list makes it look ripe for replacing the 5x string comparison with a single check and a regex, but this is a good patch on its own.

Thanks for quickly updating it.

dmsnell pushed a commit to ironprogrammer/wordpress-playground that referenced this pull request Sep 11, 2023
The Playground resolves URLs based on their path to determine whether to load
the resource at the URL or reroute it to its in-memory storage, such as for
themes and plugin content.

In WordPress 6.4, user-uploaded fonts will be stored in a new top-level uploads
directory and the Playground will need to support this. Otherwise, the Font
paths won't resolve properly and the Playground will return 404 errors for
them.
ironprogrammer added a commit to ironprogrammer/wordpress-playground that referenced this pull request Sep 11, 2023
dmsnell added a commit that referenced this pull request Sep 11, 2023
This patch introduces a small change, where previously the detection for
user-uploaded content paths ran multiple checks against the path for possible
directories. Now, a single `RegExp` pattern checks in a single pass if the path
refers to one of the intended directories. Performance impact should be
negligible, but why do five times what can mostly be done once.

cc: @ironprogrammer whose work in #633 prompted this change.
@adamziel adamziel temporarily deployed to wordpress-assets September 12, 2023 08:03 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants