Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#26768 closed enhancement (fixed)

Add remove_image_size()

Reported by: daedalon's profile Daedalon Owned by: nacin's profile nacin
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.8
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

There have been numerous requests for a remove_image_size() function in WordPress. add_image_size() needs such a counterpart to let child themes fully define what media they support and to avoid creating unnecessary resized images.

For example the Elbee Elgee theme defines a 640px * 9999px image size. Our child theme doesn't use this size anywhere. However, as long as that image size if defined, an image of that size will be generated for each larger image that is uploaded.

Without remove_image_size() it's not possible to avoid generating those unnecessary images in an update-safe way.

Attachments (2)

26768.diff (700 bytes) - added by markoheijnen 10 years ago.
26768-tests.patch (1.2 KB) - added by mordauk 10 years ago.
Adds unit tests for add_image_size(), has_image_size(), and remove_image_size()

Download all attachments as: .zip

Change History (14)

#1 @SergeyBiryukov
10 years ago

  • Component changed from Themes to Media

@markoheijnen
10 years ago

#2 @markoheijnen
10 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 3.9

It makes totally sense to have something like this. Added a patch. Not sure if there should be a message when it's called to late.

#3 @Daedalon
10 years ago

Thanks, Marko! Tested in 3.8. Works like a charm. It's now possible to remove and/or redefine image sizes upon init:

function my_custom_image_sizes( ) {
	remove_image_size( 'theme-image-size' ); // Removing default size
	add_image_size( 'theme-image-size', 400, 300 ); // Re-adding with a custom size
}
add_action( 'init', 'my_custom_image_sizes' );
Last edited 10 years ago by Daedalon (previous) (diff)

#4 @Frank Klein
10 years ago

  • Cc contact@… added

#5 @mordauk
10 years ago

Works perfectly for me.

#6 @nacin
10 years ago

  • Keywords commit needs-unit-tests added

Maybe some basic unit tests? :-)

#7 follow-up: @markoheijnen
10 years ago

Curious if we also should add has_image_size() then ;)

#8 in reply to: ↑ 7 @mordauk
10 years ago

Replying to markoheijnen:

Curious if we also should add has_image_size() then ;)

I've wanted to have that a few times. I'll write up a quick patch and new ticket.

#9 @mordauk
10 years ago

#26951 related for has_image_size()

@mordauk
10 years ago

Adds unit tests for add_image_size(), has_image_size(), and remove_image_size()

#10 @nacin
10 years ago

  • Keywords needs-unit-tests removed

Looks great. I'll get this in.

#11 @nacin
10 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27129:

Add remove_image_size() and tests for it and has_image_size(), added in [27128].

props mordauk, markoheijnen.
fixes #26768. see #26951.

#12 @nacin
10 years ago

  • Type changed from feature request to enhancement
Note: See TracTickets for help on using tickets.