WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 4 months ago

Last modified 4 months ago

#16203 closed defect (bug) (duplicate)

Modifications of media doesn't generate alternatives added by add_image_size()

Reported by: andreaswedberg Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.4
Component: Media Keywords:
Focuses: Cc:

Description

Upload an image, then select "Edit Image".
Crop the image and Save.
Images with sizes added eith add_image_size() doesn't get alternatives generated as the standard sizes does.

Change History (3)

comment:1 aut0poietic2 years ago

Just to add more information here: add_image_size() only temporarily adds the image size to the $_wp_additional_image_sizes array ( in wp-includes/media.php ).

The admin panel does not use this array, and instead uses the options "{$size}_crop", "{$size}_size_w" and "{$size}_size_h" ( line 633 & 644 of wp-admin/includes/image-edit.php ). If those options don't exist, the theme/plugin added image size will not be updated.

I've worked around the issue by calling add_option() for these option names at the same time I add the image size:

if ( function_exists( 'add_theme_support' ) ) 
{ 
	add_theme_support( 'post-thumbnails' ) ; 
	add_image_size( 'my-custom-thumb', 478, 478, true );

	// add_image_size() edit patch
	add_option( 'my-custom-thumb_crop' , true  , '' , 'yes' ) ;
	add_option( 'my-custom-thumb_size_w' , 478 , '' , 'yes' ) ;
	add_option( 'my-custom-thumb_size_h' , 478 , '' , 'yes' ) ;
}

I'm not sure what the repercussions would be if similar code was added to add_image_size().

comment:2 markoheijnen4 months ago

  • Keywords add_image_size removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

More discussion on #19889 about this.

comment:3 SergeyBiryukov4 months ago

To clarify, #17475 attempted to fix this, but the fix was incomplete.

Note: See TracTickets for help on using tickets.