Improve handling of fetching external stylesheets#4257
Merged
westonruter merged 2 commits intodevelopfrom Feb 9, 2020
Merged
Conversation
Contributor
|
Testing instructions: Create a new post and a Custom HTML block with the following content: <link rel="stylesheet" href="bad://example.com/foo.css">
<link rel="stylesheet" href="http://not-existing.example.com/foo.css">
<link rel="stylesheet" href="https://make.wordpress.org/notfound.css">
<link rel="stylesheet" href="//make.wordpress.org/core/wp-content/plugins/o2/modules/follow/css/style.css">The following set of validation errors should be raised: With the:
And no issue should be reported for |
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.


Summary
I discovered that an external stylesheet with a schemeless URL fails to be fetched because
wp_remote_get()does not support such URLs.For example, given this plugin:
The result is an error like so:
Not only should the URL be fetchable but the error message displayed here is not helpful.
So this PR ensures that a URL scheme is supplied when fetching an external stylesheet to prevent
wp_remote_get()from failing. It uses the same URL scheme as the scheme for thehome_url(), as this is the behavior of a schemeless URL.Additionally, when the URL is actually invalid the error messages are now much more helpful (resolving some code todos), as the WP HTTP error message is passed through. For example:
Relates to #1420.
Fixes #2449.
Checklist