Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#26768 closed enhancement (fixed)

Add remove_image_size()

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

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 13 years ago.
26768-tests.patch (1.2 KB ) - added by mordauk 13 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
13 years ago

  • Component ThemesMedia

@markoheijnen
13 years ago

#2 @markoheijnen
13 years ago

  • Keywords has-patch added
  • Milestone Awaiting Review3.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
13 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 13 years ago by Daedalon (previous) (diff)

#4 @anonymized_8769252
13 years ago

  • Cc contact@… added

#5 @mordauk
13 years ago

Works perfectly for me.

#6 @nacin
13 years ago

  • Keywords commit needs-unit-tests added

Maybe some basic unit tests? :-)

#7 follow-up: @markoheijnen
13 years ago

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

#8 in reply to: ↑ 7 @mordauk
13 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
13 years ago

#26951 related for has_image_size()

@mordauk
13 years ago

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

#10 @nacin
13 years ago

  • Keywords needs-unit-tests removed

Looks great. I'll get this in.

#11 @nacin
13 years ago

  • Owner set to nacin
  • Resolutionfixed
  • Status newclosed

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
12 years ago

  • Type feature requestenhancement
Note: See TracTickets for help on using tickets.