Make WordPress Core

Opened 12 months ago

Last modified 10 months ago

#60640 new enhancement

Use of "selected" function for "Week Starts On" on General Setting page

Reported by: bhargavbhandari90's profile bhargavbhandari90 Owned by:
Milestone: Future Release Priority: normal
Severity: minor Version: 6.5
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

For the dropdown of weekdays for the "Week Starts On" field is using the following turnery operation for "selected=selectd"

$selected = ( get_option( 'start_of_week' ) == $day_index ) ? 'selected="selected"' : '';

We should use WP's selected function instead of turnery operation

Attachments (2)

60640.diff (620 bytes) - added by bhargavbhandari90 12 months ago.
Use "selected" function for weekdays dropdown selected
60640-v2.diff (619 bytes) - added by bhargavbhandari90 12 months ago.
Use "selected" function for weekdays dropdown selected

Download all attachments as: .zip

Change History (8)

@bhargavbhandari90
12 months ago

Use "selected" function for weekdays dropdown selected

#1 @swissspidy
12 months ago

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

Note that selected() does a strict comparison (===) whereas the existing code does a loose comparison (==). This would need to use (int) get_option( 'start_of_week' ) to be safe.

#2 @bhargavbhandari90
12 months ago

Thanks @swissspidy. Updating patch

@bhargavbhandari90
12 months ago

Use "selected" function for weekdays dropdown selected

@mukesh27 commented on PR #6181:


12 months ago
#4

It print additional selected='selected' in HTML. Check screenshot.
https://github.com/WordPress/wordpress-develop/assets/10103365/59a191e6-d5cb-4c2c-beb7-ccec0db001a8

@bhargavbhandari90 commented on PR #6181:


12 months ago
#5

Thank you @mukeshpanchal27 for pointing this out. I've improved the code. Should be fine now.

@audrasjb commented on PR #6181:


10 months ago
#6

I updated your PR to resolve some conflicts against trunk.

Note: See TracTickets for help on using tickets.