Editor: PHP backports for Client Side Media#10868
Editor: PHP backports for Client Side Media#10868adamsilverstein wants to merge 49 commits intoWordPress:trunkfrom
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
westonruter
left a comment
There was a problem hiding this comment.
Sorry for what may be an unsolicited early review, as the PR is still a draft.
No worries, happy to have your feedback. Indeed I started working on this pr before the Gutenberg work had merged to get ahead and be more prepared - so it may change a bit, but probably not much at this point. |
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
| // Add media processing settings for users who can upload files. | ||
| if ( current_user_can( 'upload_files' ) ) { |
There was a problem hiding this comment.
Not a blocker (can be changed post-beta), but maybe the attachments controller is a better place for these settings.
We had a similar discussion for template-related settings during WP 6.8 - https://core.trac.wordpress.org/ticket/62574#comment:29
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
|
Just a quick comment: it looks like this accidentally removes the |
oh, i thought i had added that file. will fix. Also figured out why this isn't working, fix incoming. |
Add filename and filesize REST fields to the attachments endpoint for client-side media processing. The filename returns the original attachment file name, and filesize returns the file size in bytes.
Rename $tags to $cross_origin_tag_attributes and restructure it as a mapping of tag name to attributes with boolean values indicating whether each is a srcset. This replaces the hardcoded IMG srcset special case with a generic loop, making it easier to extend (e.g. for imagesrcset on LINK).
LINK elements can have imagesrcset for preloading responsive images, and VIDEO elements can have a poster image URL. Both need cross-origin handling.
WASM files are now inlined as base64 data URLs at build time, so the .htaccess AddType rule is no longer needed.
Skip setting crossorigin when already present, and document why the simpler approach (vs wp_add_crossorigin_attributes) is needed for Underscore.js template placeholders. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The $ext, $unique_filename_callback, and $alt_filenames parameters were not used in the method body. The closure still receives all 6 filter args positionally but now only passes the 4 that are needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@westonruter I believe I have addressed all outstanding feedback (except the output mapping one I will work on in a follow up). Can you give it another spin? |
Instead of using a separate wp_override_media_templates function that removes and re-adds the admin_footer action with an anonymous closure, add the crossorigin attribute processing directly within wp_print_media_templates itself. This simplifies the approach and eliminates the indirection of action hook manipulation.
|
@adamsilverstein have you checked why unit tests are failed? |
looking now... |
looks like I just needed to update the wp-api fixtures which i did in 57c4f00 (by running the |
The previous fixture regeneration included spurious meta fields (footnotes, _wp_note_status) and changed authentication format, causing both QUnit and PHPUnit CI failures. Reset to trunk's fixture and re-apply only the legitimate CSM changes (sideload endpoint, generate_sub_sizes, convert_format, image_sizes, filename, filesize). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… avoid duplicate routes (#75782) * REST API: Make `filter_wp_unique_filename()` static to match core After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Avoid duplicate sideload route registration when core already has it Since core trunk now registers the sideload route in `WP_REST_Attachments_Controller::register_routes()`, only register it in the Gutenberg subclass when the parent class doesn't already have the `sideload_item` method. Updates the test accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
… avoid duplicate routes (#75782) * REST API: Make `filter_wp_unique_filename()` static to match core After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Avoid duplicate sideload route registration when core already has it Since core trunk now registers the sideload route in `WP_REST_Attachments_Controller::register_routes()`, only register it in the Gutenberg subclass when the parent class doesn't already have the `sideload_item` method. Updates the test accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Source: WordPress/gutenberg@03a4bf9
… avoid duplicate routes (#75782) * REST API: Make `filter_wp_unique_filename()` static to match core After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Avoid duplicate sideload route registration when core already has it Since core trunk now registers the sideload route in `WP_REST_Attachments_Controller::register_routes()`, only register it in the Gutenberg subclass when the parent class doesn't already have the `sideload_item` method. Updates the test accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
… avoid duplicate routes (#75782) * REST API: Make `filter_wp_unique_filename()` static to match core After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Avoid duplicate sideload route registration when core already has it Since core trunk now registers the sideload route in `WP_REST_Attachments_Controller::register_routes()`, only register it in the Gutenberg subclass when the parent class doesn't already have the `sideload_item` method. Updates the test accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
… avoid duplicate routes (#75782) * REST API: Make `filter_wp_unique_filename()` static to match core After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Avoid duplicate sideload route registration when core already has it Since core trunk now registers the sideload route in `WP_REST_Attachments_Controller::register_routes()`, only register it in the Gutenberg subclass when the parent class doesn't already have the `sideload_item` method. Updates the test accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Source: WordPress/gutenberg@f6e37c0
… avoid duplicate routes (#75782) * REST API: Make `filter_wp_unique_filename()` static to match core After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Avoid duplicate sideload route registration when core already has it Since core trunk now registers the sideload route in `WP_REST_Attachments_Controller::register_routes()`, only register it in the Gutenberg subclass when the parent class doesn't already have the `sideload_item` method. Updates the test accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
… avoid duplicate routes (#75782) * REST API: Make `filter_wp_unique_filename()` static to match core After WordPress/wordpress-develop#10868 (r61703), the core `WP_REST_Attachments_Controller::filter_wp_unique_filename()` method was changed to `private static`. This causes a fatal error in the Gutenberg subclass which declares it as non-static. Aligns the Gutenberg method signature with core by making it static and simplifying the parameters to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Avoid duplicate sideload route registration when core already has it Since core trunk now registers the sideload route in `WP_REST_Attachments_Controller::register_routes()`, only register it in the Gutenberg subclass when the parent class doesn't already have the `sideload_item` method. Updates the test accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Source: WordPress/gutenberg@21b607c
This PR contains the PHP backports for the client-side media processing feature, enabling the editor to perform client-side image resizing, thumbnail generation, and format conversion using WebAssembly.
Preloaded Settings
The following site settings are now preloaded in both the post editor and site editor:
image_sizes- Available image size configurationsimage_size_threshold- Big image size threshold (default 2560px)image_output_formats- Output format mappings for image conversionjpeg_interlaced- Whether to use progressive/interlaced JPEG encodingpng_interlaced- Whether to use interlaced PNG encodinggif_interlaced- Whether to use interlaced GIF encodingREST API: Index Endpoint
Added media processing settings to the REST API index (
/wp-json/wp/v2/):image_sizes- All registered image sizes with dimensions and crop settingsimage_size_threshold- Big image size thresholdimage_output_formats- Format conversion mappingsREST API: Attachments Endpoint
New Fields
filename- Original attachment file namefilesize- File size in bytesexif_orientation- EXIF orientation value (1-8) for client-side rotation handlingNew Parameters
generate_sub_sizes- When false, disables server-side sub-size generation and EXIF rotationconvert_format- When false, disables automatic image format conversionNew Sideload Endpoint
Added
/wp/v2/media/{id}/sideloadendpoint for uploading sub-sized images to an existing attachment. Used by client-side media processing to upload generated image sizes without creating new attachments. Supports both images and PDFs.PDF Improvements
Improved
missing_image_sizesfield handling for PDFs, which use thefallback_intermediate_image_sizesfilter instead ofwp_get_missing_image_subsizes().Cross-Origin Isolation
Added COOP (Cross-Origin-Opener-Policy) and COEP (Cross-Origin-Embedder-Policy) headers in the block editor to enable SharedArrayBuffer for WebAssembly-based processing. Includes:
crossorigin="anonymous"attributes to external resourcesWASM Support
Added
AddTypedirective for WebAssembly files to.htaccessrules, enabling serving.wasmfiles for client-side media processing libraries like wasm-vips.Tests
Updated REST API tests for the new attachment fields and sideload endpoint.
Gutenberg PRs:
Gutenberg tracking issue: WordPress/gutenberg#75062
Trac ticket: https://core.trac.wordpress.org/ticket/62243
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.