Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#31024 closed enhancement (fixed)

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

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

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 10 years ago.
31024.patch (1.4 KB) - added by SergeyBiryukov 10 years ago.
31024.diff (1.5 KB) - added by westonruter 10 years ago.

Download all attachments as: .zip

Change History (11)

#1 @floriansimeth
10 years ago

  • Keywords has-patch added

#2 @joedolson
10 years ago

  • Focuses accessibility removed

#3 @obenland
10 years ago

  • Milestone changed from Awaiting Review to Future Release

That makes sense.

We should filter the localized version of the string though.

#4 @westonruter
10 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
10 years ago

  • Milestone changed from Future Release to 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.

@westonruter
10 years ago

#6 @westonruter
10 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
10 years ago

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

#8 @SergeyBiryukov
10 years ago

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

[31241] missed the ticket.

Note: See TracTickets for help on using tickets.