fix(attachment): suppress core IRI deprecation on external image requests - #230
Merged
Merged
Conversation
…ests Generating attachments logged repeated PHP 8.1+ 'Using null as an array offset is deprecated' notices from WordPress core's Requests/src/Iri.php while parsing the URLs FakerPress fetches from picsum.photos / placehold.co. Add without_iri_deprecations() (clears E_DEPRECATED, restored in finally) and a safe_remote_get() wrapper, and route download_url() and the Lorem Picsum metadata request through them. Adds regression coverage for the suppression and restoration behaviour. Fixes #188
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.
Fixes #188
Problem
With
WP_DEBUG_LOGon, generating attachments (especially with Lorem Picsum) floodsdebug.logwith:Root cause
A WordPress core bug in
Requests/src/Iri.php::scheme_normalization()uses a null$schemeas an array offset. It is triggered by the HTTP requests FakerPress makes to external image services while parsing their URLs.Fix
Since core files cannot be modified, the Attachment module now routes its external requests through helpers that temporarily disable
E_DEPRECATEDand always restore the previous level:without_iri_deprecations( callable )— clearsE_DEPRECATED, runs the callback, restores the level infinally.safe_remote_get( $url, $args )—esc_url_raw()+ the wrapper aroundwp_remote_get().Applied to
download_url()and the Lorem Picsum metadata request.Tests
AttachmentRemoteTest: E_DEPRECATED is disabled inside the callback and restored after (including when the callback throws), andsafe_remote_get()still performs the request (mocked viapre_http_request).Milestone: 0.9.2