WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#18947 assigned enhancement

get_intermediate_image_sizes() should also contain width/height/crop values as sub array

Reported by: F J Kaiser Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.2.1
Component: Media Keywords: has-patch dev-feedback
Focuses: Cc:

Description

Currently the function get_intermediate_image_sizes() only displays a combined list of built-in/default & (via add_image_size()) registered image size names. In lot's of cases it would be pretty handy to also have the height, width & crop values attached as sub array as you can see it in $GLOBALS['_wp_additional_image_sizes'].

I currently do not have a working dev version of wp installed, so I put it here as plain code:

Change for get_intermediate_image_sizes():

function get_intermediate_image_sizes() {
	global $_wp_additional_image_sizes;
	$image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
	foreach ( $image_sizes as $size ) {
		$image_sizes[ $size ]['width']	= intval( get_option( "{$size}_size_w") );
		$image_sizes[ $size ]['height'] = intval( get_option( "{$size}_size_h") );
		// Crop false per default if not set
		$image_sizes[ $size ]['crop']	= get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false;
	}
	if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
		$image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes );

	return apply_filters( 'intermediate_image_sizes', $image_sizes );
}

The only two other affected lines in core are pretty a simple fix: Use the array_keys() only:

wp_generate_attachment_metadata()
and
wp_delete_attachment():

foreach ( array_keys( get_intermediate_image_sizes() ) as $s ) {

I'm not really shure how the crop works, so this could maybe add additional DB calls if the option wasn't set - currently I only see thumbnail_crop added to the autoloaded options.

The links are to the 3.2 branch of the repo.

Attachments (5)

18947.patch (2.2 KB) - added by F J Kaiser 3 years ago.
18947_2.patch (5.3 KB) - added by F J Kaiser 2 years ago.
Adds a boolean argument to the function that switches between a flat numerical indexed array or a an associative array containing the complete image size data. Added to provide backwards compability to not break existsing plugins using the function.
18947_3.patch (1.2 KB) - added by F J Kaiser 2 years ago.
Removed code (belonging to some other ticket) that was accidently still in the patch.
18947_4.patch (1.3 KB) - added by F J Kaiser 15 months ago.
Updated to current nightly build trunk
18947_5.patch (1.3 KB) - added by F J Kaiser 5 months ago.
The new 3.8 compatible patch from DrupalCamp Vienna 2013

Download all attachments as: .zip

Change History (12)

comment:1 F J Kaiser3 years ago

  • Cc 24-7@… added

F J Kaiser3 years ago

comment:2 F J Kaiser3 years ago

  • Keywords has-patch added
  • Version changed from 3.2.1 to 3.3

comment:3 follow-up: SergeyBiryukov3 years ago

  • Version changed from 3.3 to 3.2.1

Version field indicates when the enhancement was initially suggested, let's keep it at 3.2.1.

Wouldn't this break a lot of plugins currently using it? Probably should be implemented as another function.

F J Kaiser2 years ago

Adds a boolean argument to the function that switches between a flat numerical indexed array or a an associative array containing the complete image size data. Added to provide backwards compability to not break existsing plugins using the function.

F J Kaiser2 years ago

Removed code (belonging to some other ticket) that was accidently still in the patch.

comment:4 in reply to: ↑ 3 F J Kaiser2 years ago

Replying to SergeyBiryukov:

Wouldn't this break a lot of plugins currently using it? Probably should be implemented as another function.

Current patch avoids breaking.

comment:5 F J Kaiser2 years ago

  • Owner set to F J Kaiser
  • Status changed from new to assigned

comment:6 F J Kaiser2 years ago

  • Keywords dev-feedback added

comment:7 F J Kaiser2 years ago

  • Owner F J Kaiser deleted

F J Kaiser15 months ago

Updated to current nightly build trunk

F J Kaiser5 months ago

The new 3.8 compatible patch from DrupalCamp Vienna 2013

Note: See TracTickets for help on using tickets.