Conversation
Contributor
TestingRequirements
wp_register_webfont(
array(
'font-family' => 'Roboto',
'font-style' => 'normal',
'font-stretch' => 'normal',
"font-weight" => "900",
'src' => array( 'file:./assets/fonts/Roboto-Regular.ttf' ),
)
);
wp_enqueue_webfont('Roboto');
wp_enqueue_webfont('Roboto'); |
Member
|
Should we instead expect devs to use something along the lines of |
Contributor
|
Good idea @zaguiini! I can see how this would happen and be super annoying. There's no harm in attempting to enqueue more than 1 time. The API knows if it's already enqueued and can return a positive indication to flag the state. No need for the warning. |
hellofromtonya
approved these changes
Apr 7, 2022
Contributor
hellofromtonya
left a comment
There was a problem hiding this comment.
Great idea! Thanks for flagging this annoyance. I agree in removing it and returning true as it's already enqueued. LGTM 👍
Member
Author
|
I think we can have both, @simison. The warning is useless as trying to re-enqueue is a noop. |
37 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Do not trigger an error if trying to enqueue a font family that was already enqueued.
Why?
It's super annoying. If the font family is already enqueued, let's just move on with our lives.
When implementing a web font scanning logic for example, the same font might be referenced by multiple blocks, and having to check whether the font was already enqueued before just to avoid the warning is redundant -- we do have guards inside the enqueueing method.
Testing Instructions
Notice we're calling
wp_enqueue_webfonttwice. When opening the site, it should not yell at you because you called enqueue twice for the same family.