#28277 closed enhancement (fixed)
Add ability to apply image edits to custom image sizes
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.0 | Priority: | normal |
| Severity: | normal | Version: | 4.0 |
| Component: | Media | Keywords: | has-patch commit needs-dev-note needs-user-docs |
| Focuses: | administration | Cc: |
Description
This patch allows developers to add custom image sizes to the "Edit Image" -> "Apply changes to:" setting so that image edits may be set to only affect a custom image size.
This can now be accomplished using the 'edit_custom_thumbnail_sizes' filter and passing it an array of 'Label' => 'size' elements.
And this is my first contribution so please go easy on me (administratively speaking)!
Attachments (2)
Change History (20)
This ticket was mentioned in IRC in #wordpress-dev by gordian. View the logs.
12 years ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
4 years ago
#7
@
4 years ago
- Milestone changed from Future Release to 6.0
- Owner set to joedolson
- Status changed from new to accepted
This ticket was mentioned in Slack in #core-media by joedolson. View the logs.
4 years ago
#9
@
4 years ago
Updated patch fixes some issues with inappropriate use of translation functions, adds escaping, and updates the patch.
The original patch required a user to return an array of image sizes to use in custom size editing; I changed that so a value of 'true' can return the value of get_intermediate_image_sizes(), though it can be overridden to customize the values.
Not requiring a custom array does mean that we don't have any custom labels for the sizes, which was a benefit to passing a custom array; but also makes it harder to turn on.
#12
@
4 years ago
To test:
- This patch does not enable the feature; it adds a filter to enable it. Before applying the patch, you can switch the value
$edit_custom_sizes = false;totrue. - Go to edit a media item and select an option to apply sizes to.
- Verify that the edits were applied to the expected sizes.
This ticket was mentioned in Slack in #core by chaion07. View the logs.
4 years ago
#14
@
4 years ago
- Keywords commit added; needs-testing removed
Test Report
Environment
- Server: Apache (Linux)
- WordPress: 6.0-alpha-52448-src
- Browser: Chrome 100.0.4896.75
- OS: Windows 10
- Theme: Twenty Twenty
- Plugins:
- Test 'edit_custom_thumbnail_sizes' filter. 1.0.0
Steps
- Apply 28277.2.diff.
- Add the following to
wp-content/plugins/test-edit-custom-thumbnail-sizes/test-edit-custom-thumbnail-sizes.php:
<?php /** * Plugin Name: Test 'edit_custom_thumbnail_sizes' filter. * Description: A test for the 'edit_custom_thumbnail_sizes' filter. * Author: WordPress Core Contributors * Version: 1.0.0 */ add_action( 'after_setup_theme', function() { add_image_size( 'my-custom-size', 123, 123 ); add_filter( 'edit_custom_thumbnail_sizes', '__return_true' ); if ( ! is_admin() ) { $latest_image = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => 1, ) ); echo wp_get_attachment_image( $latest_image->posts[0]->ID, 'my-custom-size' ); echo wp_get_attachment_image( $latest_image->posts[0]->ID, 'thumbnail' ); } } );
- Navigate to
Plugins > Installed Plugins. - Activate the
Test 'edit_custom_thumbnail_sizes' filter.plugin. - Navigate to
Media > Add New. - Upload a new image.
- Click
Edit. - Click
Edit Image. See that themy-custom-sizeis shown under theThumbnail Settings > Apply changes tosection. ✅ - Select
my-custom-sizeunderThumbnail Settings > Apply changes tosection. - At the top, click the
Flip Verticallybutton. - Click
Save. - Click
Update. - Navigate to the frontend. See that two images are shown:
- The
my-custom-sizesize, flipped vertically. ✅ - The
thumbnailsize, not flipped vertically. ✅
- The
- In the plugin file from step 2, change
__return_trueto__return_false. - Navigate to
Media > Library. - Click
Editon the image you uploaded. - Click
Edit Image. See thatmy-custom-sizeis not shown under theThumbnail Settings > Apply changes tosection. ✅
Results
- 28277.2.diff works as expected.
Notes
- Adding for
commitconsideration.
#15
@
4 years ago
Thanks, @costdev! I'm going to go ahead and commit this. I'm still not 100% thrilled with the use of size keys for labels, but I think that can be tweaked during beta, if it's seen as necessary. Since this is all behind a filter, anyway, it's not going to have a profound impact on most users.
Add ability to apply image edits to custom image sizes only