Make WordPress Core

Opened 12 years ago

Closed 10 years ago

#19990 closed enhancement (worksforme)

Separate ID and display name for add_image_size

Reported by: garyj's profile GaryJ Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: Media Keywords: has-patch
Focuses: Cc:


Currently, the first argument in add_image_size() is used as both the id (and key in the global array _wp_additional_image_sizes, and as the displayed name, since nothing else is available.

As such, the $name, when it is displayed, is not translatable, since some other code might be hard-coded to use a specific image size.

Instead of adding a 5th argument to the function, one solution might be to allow the first argument to be a string or array, and if it is an array, passing that as a new item in the array that is set. Theme or plugin authors could then check for the existence of this array value item, before falling back to using the key as per now.

Current Usage:

add_image_size( 'primary-sidebar', 150, 100 );

New Optional Usage:

add_image_size( array( 'primary-sidebar' => __( 'Primary Sidebar', 'my-textdomain' ) ), 150, 100 );

Attachments (1)

19990.diff (1.2 KB) - added by GaryJ 12 years ago.
First pass

Download all attachments as: .zip

Change History (10)

12 years ago

First pass

#1 @GaryJ
12 years ago

  • Keywords has-patch added

19990.diff is a first pass at a solution. It should all be backwards compatible. Further improvements might be to change the $name to $id to help self-document the code a little better.

Obviously if a solution along these lines did go in, then it might be nice to make the default image sizes have a display name value too (post thumbnail registration, couple of calls in TwentyEleven, default image sizes).

#2 @nacin
12 years ago

Where are the display names used?

#3 @GaryJ
12 years ago

The Genesis Framework happens to use them for choosing a featured image size - and other themes and plugins (I know one widget plugin that does) may well use them too. This is one example.

Thinking ahead, image_size_input_fields() could make use of them if it were to automatically support showing images of all sizes.

This tutorial shows new image sizes being added, clearly with the name (spaces, capitals) being intended to be shown to a user. The fact that the variable is called $name instead of $id already makes it ambiguous in the eyes of some developers.

The Simple Image Sizes plugin would look better if it could use a display name. This particular plugin also excellent highlights how having the current name / ID not translatable makes it look odd for non-native users. Same for the screenshot halfway down the WPBeginner article that references it, and ditto for Helen's post.

Justin's tutorial could be improved by showing a display name alongside the image dimensions, this time on the front-end.

At this point, I'm only interested in getting the ID and a potential display name separated out, so that the latter could be made translatable. Clearly some themes and plugins that are already out there that do wish to show it to a user. My first pass solution is fully BC (I believe), and helps improve the UI where it's used for both same-language and different-language users.

#4 @GaryJ
12 years ago

Related: #20663

#5 @wpsmith
12 years ago

  • Cc t@… added

#7 @SergeyBiryukov
11 years ago

#20663 was marked as a duplicate.

#8 @SergeyBiryukov
11 years ago

#24681 was marked as a duplicate.

#9 @wonderboymusic
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Just filter here: 'image_size_names_choose'

Note: See TracTickets for help on using tickets.