Fix remote featured images with query-string URLs failing import - #8063
Merged
Merged
Conversation
basename() on a URL with a query string includes the query string in the filename, causing wp_upload_bits() to reject the file as an unknown type. Strip the query string by deriving the filename from the URL path only. Also fix pre-existing lint violations in the modified file. Fixes #8059 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous commit accidentally corrupted the left curly quote character (U+201C) to a right curly quote (U+201D) during the parameter rename. Restore the original bytes by re-applying only the identifier rename. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Cast the parsed URL path before basename() to avoid a PHP 8.1+ deprecation when the URL has no path, and drop the extensionless 'import-<md5>' fallback: it produced a filename wp_upload_bits() would reject with the same "not allowed file type" error, so an empty filename now fails through naturally as a per-row warning. Use assertIsInt() in the query-string test for a clearer failure message and to drop the print_r() debug call flagged by PHPCS. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Restore replace_curly_quotes and split_list_safely to their trunk form so this PR touches only the attachment filename fix. The two PHPCS findings this re-introduces (function-keyword spacing, "string" param name) are pre-existing on trunk and sit outside this PR's diff, so the changed-line CI linter does not flag them. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Assert only that a query-string URL yields an attachment id — the behavior this fix restores. Post-type and source-key-meta checks cover pre-existing behavior already exercised by neighbouring attachment tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Sensei’s data-port remote featured-image import when the source URL includes a query string (e.g. Jetpack Photon URLs), by ensuring the uploaded filename is derived from the URL path instead of including the query string (which breaks wp_upload_bits() extension checks).
Changes:
- Update
Sensei_Data_Port_Utilities::create_attachment_from_url()to derive the upload filename fromwp_parse_url( ..., PHP_URL_PATH ). - Add a unit test covering a query-string image URL import flow.
- Add a changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| includes/data-port/class-sensei-data-port-utilities.php | Adjusts filename derivation for remote attachment uploads to avoid query strings breaking filetype checks. |
| tests/unit-tests/data-port/test-class-sensei-data-port-utilites.php | Adds regression coverage for query-string URLs in get_attachment_from_source(). |
| changelog/fix-query-string-remote-image-import | Documents the user-facing fix as a patch “fixed” entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
donnapep
approved these changes
Jul 6, 2026
2 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.
Summary
basename( $external_url )on a URL likehttps://i0.wp.com/example.com/image.png?fit=2560%2C1440&ssl=1returnsimage.png?fit=2560%2C1440&ssl=1— the query string becomes part of the filename, sowp_upload_bits()rejects it with "Sorry, you are not allowed to upload this file type." Every remote featured image referenced with a query-string URL (Photon/Jetpack, signed CDN URLs, etc.) fails to attach.basename( (string) wp_parse_url( $external_url, PHP_URL_PATH ) ). The cast avoids a PHP 8.1+basename( null )deprecation for path-less URLs; the subsequentwp_check_filetype_and_ext()still validates the actual file contents.Fixes #8059
Test plan
https://i0.wp.com/example.com/image.png?fit=800%2C600&ssl=1) and confirm the image attaches to the imported lesson/course without warnings.🤖 Generated with Claude Code