Make WordPress Core

Opened 8 weeks ago

Last modified 8 weeks 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 8 weeks ago.
Use "selected" function for weekdays dropdown selected
60640-v2.diff (619 bytes) - added by bhargavbhandari90 8 weeks ago.
Use "selected" function for weekdays dropdown selected

Download all attachments as: .zip

Change History (7)

@bhargavbhandari90
8 weeks ago

Use "selected" function for weekdays dropdown selected

#1 @swissspidy
8 weeks 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
8 weeks ago

Thanks @swissspidy. Updating patch

@bhargavbhandari90
8 weeks ago

Use "selected" function for weekdays dropdown selected

@mukesh27 commented on PR #6181:


8 weeks 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:


8 weeks ago
#5

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

Note: See TracTickets for help on using tickets.