Make WordPress Core

Opened 10 years ago

Closed 2 years ago

Last modified 2 years ago

#28277 closed enhancement (fixed)

Add ability to apply image edits to custom image sizes

Reported by: silb3r's profile silb3r Owned by: joedolson's profile joedolson
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)

image-edit.diff (2.0 KB) - added by silb3r 10 years ago.
Add ability to apply image edits to custom image sizes only
28277.2.diff (2.6 KB) - added by joedolson 2 years ago.
Update & refresh patch.

Download all attachments as: .zip

Change History (20)

@silb3r
10 years ago

Add ability to apply image edits to custom image sizes only

This ticket was mentioned in IRC in #wordpress-dev by gordian. View the logs.


10 years ago

#2 @SergeyBiryukov
10 years ago

#22990 was marked as a duplicate.

#3 @wonderboymusic
10 years ago

  • Milestone changed from Awaiting Review to Future Release

#4 @chriscct7
8 years ago

  • Keywords has-patch needs-refresh added

#5 @WraithKenny
7 years ago

This would certainly fill a hole in the incomplete edit feature.

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


2 years ago

#7 @joedolson
2 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.


2 years ago

#9 @joedolson
2 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.

@joedolson
2 years ago

Update & refresh patch.

#10 @joedolson
2 years ago

  • Keywords needs-refresh removed

#11 @joedolson
2 years ago

  • Keywords needs-testing added

#12 @joedolson
2 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; to true.
  • 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.


2 years ago

#14 @costdev
2 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

  1. Apply 28277.2.diff.
  2. 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' );
                }
        }
);
  1. Navigate to Plugins > Installed Plugins.
  2. Activate the Test 'edit_custom_thumbnail_sizes' filter. plugin.
  3. Navigate to Media > Add New.
  4. Upload a new image.
  5. Click Edit.
  6. Click Edit Image. See that the my-custom-size is shown under the Thumbnail Settings > Apply changes to section. ✅
  7. Select my-custom-size under Thumbnail Settings > Apply changes to section.
  8. At the top, click the Flip Vertically button.
  9. Click Save.
  10. Click Update.
  11. Navigate to the frontend. See that two images are shown:
    • The my-custom-size size, flipped vertically. ✅
    • The thumbnail size, not flipped vertically. ✅
  12. In the plugin file from step 2, change __return_true to __return_false.
  13. Navigate to Media > Library.
  14. Click Edit on the image you uploaded.
  15. Click Edit Image. See that my-custom-size is not shown under the Thumbnail Settings > Apply changes to section. ✅

Results

  1. 28277.2.diff works as expected.

Notes

  • Adding for commit consideration.
Last edited 2 years ago by costdev (previous) (diff)

#15 @joedolson
2 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.

#16 @joedolson
2 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 53161:

Media: Enable edits to custom image sizes.

Add a filter edit_custom_thumbnail_sizes to allow users to enable editing individual custom image sizes.

Props silb3r, joedolson, costdev.
Fixes #28277.

#17 @milana_cap
2 years ago

  • Keywords needs-dev-note needs-docs added

#18 @milana_cap
2 years ago

  • Keywords needs-user-docs added; needs-docs removed
Note: See TracTickets for help on using tickets.