Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#31024 closed enhancement (fixed)

Add a new hook to the first <option>-element of the archive widget dropdown

Reported by: floriansimeth Owned by:
Priority: normal Milestone: 4.2
Component: Widgets Version: 4.1
Severity: normal Keywords: has-patch
Cc: Focuses: template

Description

Hey WP-Community,

I would kindly ask if it's possible to integrate a new filter into the default-widgets.php.

It should allow us to change the title of the first <option> element.

The problem is that if I hook into the ​widget_archives_dropdown_args and change the argument type from monthly to yearly the script would always output "Select Month" instead of "Select Year".

Of course it's possible to hook into the gettext filter but I think this is not the ideal solution as translated texts could be used elsewhere, too.

So what I mean is to change the following line:

<option value=""><?php esc_attr_e( 'Select Month' ); ?></option>

into something like this:

<option value=""><?php esc_attr_e( apply_filters( 'widget_archives_dropdown_first', 'Select Month' ) ); ?></option>

Thanks

Attachments (3)

default-widgets.php.patch​ (569 bytes ) - added by floriansimeth 12 years ago.
31024.patch​ (1.4 KB ) - added by SergeyBiryukov 12 years ago.
31024.diff​ (1.5 KB ) - added by westonruter 12 years ago.

Download all attachments as: .zip

Change History (11)

#1 @floriansimeth
12 years ago

  • Keywords has-patch added

#2 @joedolson
12 years ago

  • Focuses accessibility removed

#3 @obenland
12 years ago

  • Milestone Awaiting Review → Future Release

That makes sense.

We should filter the localized version of the string though.

#4 @westonruter
12 years ago

Instead of:

<option value=""><?php esc_attr_e( apply_filters( 'widget_archives_dropdown_first', 'Select Month' ) ); ?></option> 

It should actually do something like:

<option value=""><?php echo esc_attr( apply_filters( 'widget_archives_dropdown_first', __( 'Select Month' ) ) ); ?></option> 

As otherwise the string won't get translated properly.

And the filter would probably be better named widget_archives_dropdown_first_option_label.

#5 in reply to: ↑ description @SergeyBiryukov
12 years ago

  • Milestone Future Release → 4.2

Replying to floriansimeth:

The problem is that if I hook into the ​widget_archives_dropdown_args and change the argument type from monthly to yearly the script would always output "Select Month" instead of "Select Year".

Instead of introducing a new filter, can we set the label contextually based on the passed type value?

See 31024.patch​.

#6 @westonruter
12 years ago

Hah. SergeyBiryukov and I had the same idea. 31024.patch​ and 31024.diff​ eliminate the need for the filter by selecting a title by switching on the $args['type']

#7 @SergeyBiryukov
12 years ago

Note that $args is an existing variable that contains the arguments passed to the widget.

#8 @SergeyBiryukov
12 years ago

  • Resolution → fixed
  • Status new → closed

[31241] missed the ticket.

Note: See TracTickets for help on using tickets.