-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Media: Enable HEIC/HEIF uploads when server lacks image editor support #11323
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
Open
adamsilverstein
wants to merge
35
commits into
WordPress:trunk
Choose a base branch
from
adamsilverstein:add/heic-canvas-fallback
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
bf9f644
Media: Allow HEIC/HEIF uploads when server lacks support
adamsilverstein 71a9e8b
Merge remote-tracking branch 'origin/trunk' into add/heic-canvas-fall…
adamsilverstein 630266f
Merge remote-tracking branch 'origin/trunk' into add/heic-canvas-fall…
adamsilverstein b261f30
REST API: Add HEIC client-side support to the sideload route.
adamsilverstein c711280
Media: Delete HEIC companion file when its attachment is deleted.
adamsilverstein b20bbca
Tests: Cover the HEIC client-side sideload and companion-delete flow.
adamsilverstein eea07d2
Tests: Use HEIC fixture and convert_format=false for original-heic si…
adamsilverstein d976d2e
Tests: Refresh wp-api-generated.js fixture for the sideload route.
adamsilverstein d01bab6
Add void return type hints
westonruter f728cfb
Use non-deprecated factory
westonruter d6f69d6
Add assertions for successful attachment creation
westonruter beb9ffe
Add types and type assertions to tests
westonruter 9b6b768
Update src/wp-includes/media.php
adamsilverstein 7f976bb
REST API: Address review feedback on HEIC client-side sideload support.
adamsilverstein df33a07
Tests: Sync wp-api-generated.js fixture after dropping sideload gener…
adamsilverstein c3c02f9
Apply suggestions from code review
adamsilverstein ef1767d
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter a07580e
Fix Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
westonruter 9f40ed4
Incorporate file.php phpstan-return types from https://github.com/Wor…
westonruter b11a774
Add return types for wp_get_upload_dir() and wp_upload_dir()
westonruter 18cc9e3
Add types to get_file_params()/set_file_params() in WP_REST_Request
westonruter 509309f
Add return type for WP_REST_Attachments_Controller::upload_from_data(…
westonruter 546d470
Add return type definition for wp_get_attachment_metadata()
westonruter 08b4fa5
Add source_image to possible keys returned by wp_get_attachment_metad…
westonruter 46bccdb
Add phpstan/phpstan-phpunit for PHPUnit assertion type narrowing
westonruter 6dfdba3
Combine sideload route tests to avoid having to re-assert shape
westonruter 5b2b81b
Add assertions that response is array with id key
westonruter 1e42037
Restore return description
westonruter 707326c
Add missing nullable original_image to metadata array shape
westonruter 1b7c752
Indicate attachment metadata shape is unsealed (since filterable)
westonruter be9dd94
Fix unsealed array syntax
westonruter 24676d1
Make wp_get_attachment_metadata() return shape reflect all attachment…
westonruter e26b99d
Tests: Read sideload route args from the endpoint, not the endpoint i…
adamsilverstein 5f0c396
REST API: Extract PHPStan type-coverage changes to a separate PR.
adamsilverstein 4ff3b5b
Merge branch 'trunk' into add/heic-canvas-fallback
adamsilverstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
96 changes: 96 additions & 0 deletions
96
tests/phpunit/tests/media/wpDeleteAttachmentHeicCompanionFile.php
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests for the `wp_delete_attachment_heic_companion_file()` function. | ||
| * | ||
| * @group media | ||
| * @covers ::wp_delete_attachment_heic_companion_file | ||
| */ | ||
| class Tests_Media_wpDeleteAttachmentHeicCompanionFile extends WP_UnitTestCase { | ||
|
|
||
| public function tear_down(): void { | ||
| $this->remove_added_uploads(); | ||
|
|
||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 64915 | ||
| */ | ||
| public function test_deletes_companion_file_recorded_in_metadata_source_image(): void { | ||
| $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' ); | ||
| $this->assertIsInt( $attachment_id ); | ||
|
|
||
| $attached_file = get_attached_file( $attachment_id, true ); | ||
| $this->assertIsString( $attached_file ); | ||
| $dir = dirname( $attached_file ); | ||
| $heic_name = 'companion-' . wp_generate_password( 6, false ) . '.heic'; | ||
| $heic_path = $dir . '/' . $heic_name; | ||
|
|
||
| // Create a dummy companion file on disk. | ||
| file_put_contents( $heic_path, 'test' ); | ||
| $this->assertFileExists( $heic_path, 'Test fixture should be on disk.' ); | ||
|
|
||
| // Record the companion under metadata['source_image'] as the sideload route does. | ||
| $metadata = wp_get_attachment_metadata( $attachment_id, true ); | ||
| $this->assertIsArray( $metadata ); | ||
| $metadata['source_image'] = $heic_name; | ||
| wp_update_attachment_metadata( $attachment_id, $metadata ); | ||
|
|
||
| $this->assertTrue( | ||
| wp_delete_attachment_heic_companion_file( $attachment_id ), | ||
| 'Function should report that a companion file was deleted.' | ||
| ); | ||
| $this->assertFileDoesNotExist( $heic_path, 'Companion file should be deleted alongside the attachment.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 64915 | ||
| */ | ||
| public function test_noop_when_metadata_source_image_is_missing(): void { | ||
| $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' ); | ||
| $this->assertIsInt( $attachment_id ); | ||
|
|
||
| // Sanity: no 'source_image' key on freshly-created metadata. | ||
| $metadata = wp_get_attachment_metadata( $attachment_id, true ); | ||
| $this->assertIsArray( $metadata ); | ||
| $this->assertArrayNotHasKey( 'source_image', $metadata ); | ||
|
|
||
| // Should report no deletion and not raise even though the hook fires. | ||
| $this->assertFalse( wp_delete_attachment_heic_companion_file( $attachment_id ) ); | ||
|
|
||
| wp_delete_attachment( $attachment_id, true ); | ||
|
|
||
| $this->assertNull( get_post( $attachment_id ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Guards against $metadata['source_image'] holding a non-string value (e.g. | ||
| * the array form some flows write). Regression coverage for GB #78128. | ||
| * | ||
| * @ticket 64915 | ||
| */ | ||
| public function test_noop_when_metadata_source_image_is_not_a_string(): void { | ||
| $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' ); | ||
| $this->assertIsInt( $attachment_id ); | ||
| $attached_file = get_attached_file( $attachment_id, true ); | ||
| $this->assertIsString( $attached_file ); | ||
|
|
||
| // Place a real file that a buggy, guard-less implementation could try to | ||
| // delete after running wp_basename() over the array value below. | ||
| $bystander_path = dirname( $attached_file ) . '/should-not-delete.heic'; | ||
| file_put_contents( $bystander_path, 'test' ); | ||
| $this->assertFileExists( $bystander_path, 'Test fixture should be on disk.' ); | ||
|
|
||
| $metadata = wp_get_attachment_metadata( $attachment_id, true ); | ||
| $this->assertIsArray( $metadata ); | ||
| $metadata['source_image'] = array( 'file' => 'should-not-delete.heic' ); | ||
| wp_update_attachment_metadata( $attachment_id, $metadata ); | ||
|
|
||
| // Should report no deletion and not raise (no path_join() / file_exists() on an array). | ||
| $this->assertFalse( wp_delete_attachment_heic_companion_file( $attachment_id ) ); | ||
|
|
||
| $this->assertFileExists( $bystander_path, 'The non-string guard must prevent any file deletion.' ); | ||
| $this->assertFileExists( $attached_file, 'Attached file should still be on disk.' ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.