Make WordPress Core

Opened 7 weeks ago

Last modified 6 weeks ago

#66142 new defect (bug)

Empty custom date/time fields are saved instead of remaining null in WordPress 7.1.1

Reported by: sanayasir Owned by:
Priority: normal Milestone: Awaiting Review
Component: Date/Time Version: 7.1.1
Severity: normal Keywords: needs-testing has-patch has-unit-tests close
Cc: Focuses:

Description

A regression appears to have been introduced in WordPress 7.1.1 involving the custom date and time format fields in Settings → General.

In WordPress 7.1, this behavior was resolved. However, after updating to WordPress 7.1.1, the issue appears again.

When the Custom date or time format option is selected and the custom input field is left blank, saving the General Settings still saves the empty value.

Ideally, when no custom date or time format has been entered, the corresponding setting should remain null rather than saving an empty custom value.

Steps to reproduce
Install WordPress 7.1.1.
Go to Settings → General.
Locate the Date Format or Time Format setting.
Select the Custom option.
Leave the custom date/time input field completely blank.
Click Save Changes.
Check the saved setting value.
Actual result

The settings are saved even though the custom date/time field is empty.

An empty custom value is stored instead of leaving the setting as null.

Expected result

If the custom date/time field is empty, WordPress should not save an empty custom value.

The corresponding setting should remain null until a valid custom date/time format is provided.

Regression

This behavior was resolved in WordPress 7.1, but appears to have regressed in WordPress 7.1.1.

Environment
WordPress: 7.1.1
Tested on: [Browser]
PHP: [PHP version]
Theme: [Theme]
Plugins: [Plugins / default installation]
Additional notes

The issue appears to be related to how the empty custom date/time fields are handled when the General Settings form is submitted.

The relevant handling is in wp-admin/options.php, where the custom date and time format values are processed before the options are updated.

Attachments (1)

Custom data&time format setting .mp4​ (7.7 MB ) - added by anntrauf 7 weeks ago.
Screen recording showing that the empty custom date/time format is still saved after applying the proposed patch.

Change History (6)

#1 @sanayasir
7 weeks ago

  • Keywords needs-patch added

#2 @sanayasir
7 weeks ago

  • Keywords needs-testing added

This ticket was mentioned in ​PR #13648 on ​WordPress/wordpress-develop by ​@irozum.


7 weeks ago
#3

  • Keywords has-patch has-unit-tests added; needs-patch removed

When "Custom" is selected for the Date Format or Time Format on Settings → General and the custom text field is left blank, WordPress saves the empty value as the option instead of leaving the existing setting untouched, so a user who accidentally clears the custom field and saves loses their previously configured format.

The fix extracts the resolution logic into a new small, unit-testable function, wp_get_submitted_date_time_format() in wp-admin/includes/misc.php, which returns null when "Custom" is selected with an empty value. wp-admin/options.php now uses that return value to skip saving date_format/time_format entirely in that case, leaving the previously stored option value in place, rather than overwriting it with an empty string.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Implementation, tests, and PR description. Reviewed by Igor Rozum.

#4 @anntrauf
7 weeks ago

Test Report

I tested this ticket using WordPress Playground and was able to reproduce the issue.

I also tested the proposed patch, but the issue still persists in my test environment.

Steps tested

  1. Navigated to Settings → General.
  2. Selected the Custom option under Date Format.
  3. Left the custom format field completely empty.
  4. Clicked Save Changes.

Actual Result

The empty custom date format is still saved after applying the patch.

Expected Result

When the Custom option is selected but the custom format field is left empty, the empty custom value should not be saved.

Test Result

The issue is still reproducible with the current patch.

Tested using WordPress Playground.

@anntrauf
7 weeks ago

Screen recording showing that the empty custom date/time format is still saved after applying the proposed patch.

Note: See TracTickets for help on using tickets.