Opened 3 weeks ago
Last modified 5 days ago
#65281 new defect (bug)
Custom Time & Date Format Fields Allow Empty Save Instead of Validation
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Date/Time | Keywords: | has-patch has-unit-tests has-test-info needs-testing |
| Focuses: | administration | Cc: |
Description
Title
Custom Time & Date Format Fields Allow Empty Save Instead of Validation
Description
During WordPress 7.0 release party testing, an issue was identified related to custom time and date format settings.
When the custom fields for Time Format and Date Format are cleared (left blank), WordPress still allows the settings to be saved successfully.
Although WordPress falls back to default formatting behavior internally, the system should validate these fields before saving.
Current Behavior
- User clears the custom Time Format and/or Date Format fields.
- WordPress accepts and saves the changes.
- WordPress automatically falls back to default formatting behavior.
Expected Behavior
- If custom Time Format or Date Format fields are empty or invalid: System should either save null values explicitly, OR Prevent saving and show a validation/error message.
- User should be prompted to enter valid format values before settings are saved.
Suggested Validation
- Restrict empty submissions for custom format fields.
- Display an admin notice such as:
<blockquote>
Please configure a valid date and time format.
</blockquote>
Steps to Reproduce
# Go to Settings → General.
# Navigate to Date Format / Time Format settings.
# Clear the custom format fields.
# Click Save Changes.
# Observe that WordPress still saves the settings without validation.
Impact
- May create confusion for users/admins.
- Blank or invalid custom settings can lead to inconsistent formatting behavior.
- No clear indication that configuration is incomplete.
Environment
- WordPress Version: 7.0
- Tested during: WordPress 7.0 Release Party Testing
Attachments (6)
Change History (21)
This ticket was mentioned in PR #11903 on WordPress/wordpress-develop by @khokansardar.
3 weeks ago
#2
- Keywords has-patch has-unit-tests added; needs-patch removed
Validate custom date and time format fields on the General Settings screen before saving. When either custom field is empty, restore the previous value, show an admin error, and reject empty values in sanitize_option() as well.
Fixes #65281.
#4
@
3 weeks ago
@ashirhabib Thanks for the details I am also able to replicate this issue.
Environment
WordPress: 7.0
PHP: 8.1.23
Server: nginx/1.16.0
Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.1.23)
Browser: Chrome 126.0.0.0 (macOS)
Theme: Twenty TwentyVersion: 2.7
#5
@
3 weeks ago
Test Report
I have tested latest patch and it is working as expected.
https://github.com/WordPress/wordpress-develop/pull/11903
Environment
WordPress: 7.0-alpha-58576-src
PHP: 8.1.23
Server: nginx/1.16.0
Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.1.23)
Browser: Chrome 126.0.0.0 (macOS)
Theme: Twenty TwentyVersion: 2.7
Expected Results
Getting the message "Please configure a valid date and time format." when we try to save empty Date format using custom.
#7
@
3 weeks ago
- Focuses coding-standards removed
- Version 6.9.4 deleted
I tested on the oldest available version on playground (6.3) and this issue was present then, so it certainly wasn't introduced in 6.9.4. I've opened issue with the playground team to support even older versions of WordPress in the hope of helping identify when this started to be an issue.
#8
@
3 weeks ago
I tested this issue on WordPress Playground 7.1 Alpha.
Previously, the General Settings page allowed saving the settings even when the custom Date Format and Time Format fields were left empty/null.
After testing the fix, the behavior now works as expected according to the ticket requirements:
When the custom date/time format fields are cleared, the settings are no longer saved.
A validation error message is displayed: “Please configure a valid date and time format.”
The issue appears to be fixed successfully.
#9
in reply to:
↑ 3
@
3 weeks ago
Replying to westonruter:
Adding client-side validation as well would be welcome.
Thanks for the feedback @westonruter. Added client-side validation on the PR.
The General Settings form now blocks submission when Custom is selected and the date or time format field is empty. Invalid rows use the standard admin form-invalid styling, focus moves to the first invalid field, and the error is announced via wp.a11y.speak().
This builds on the server-side validation in the first commit. PHPUnit tests for sanitize_option() continue to pass.
#10
in reply to:
↑ 3
@
2 weeks ago
Replying to westonruter:
Adding client-side validation as well would be welcome.
Here's a minimal patch which would address this:
-
src/wp-admin/options-general.php
diff --git a/src/wp-admin/options-general.php b/src/wp-admin/options-general.php index 6a9a6d2f38..5c2bae8731 100644
a b require_once ABSPATH . 'wp-admin/admin-header.php'; 67 67 <div class="wrap"> 68 68 <h1><?php echo esc_html( $title ); ?></h1> 69 69 70 <form method="post" action="options.php" novalidate="novalidate">70 <form method="post" action="options.php"> 71 71 <?php settings_fields( 'general' ); ?> 72 72 73 73 <table class="form-table" role="presentation"> … … foreach ( $date_formats as $format ) { 518 518 /* translators: Hidden accessibility text. */ 519 519 __( 'Custom date format:' ) . 520 520 '</label>' . 521 '<input type="text" name="date_format_custom" id="date_format_custom" value="' . esc_attr( get_option( 'date_format' ) ) . '" class="small-text" />' .521 '<input type="text" name="date_format_custom" id="date_format_custom" value="' . esc_attr( get_option( 'date_format' ) ) . '" class="small-text" required />' . 522 522 '<br />' . 523 523 '<p><strong>' . __( 'Preview:' ) . '</strong> <span class="example">' . date_i18n( get_option( 'date_format' ) ) . '</span>' . 524 524 "<span class='spinner'></span>\n" . '</p>'; … … foreach ( $time_formats as $format ) { 563 563 /* translators: Hidden accessibility text. */ 564 564 __( 'Custom time format:' ) . 565 565 '</label>' . 566 '<input type="text" name="time_format_custom" id="time_format_custom" value="' . esc_attr( get_option( 'time_format' ) ) . '" class="small-text" />' .567 566 '<br />' . 567 '<input type="text" name="time_format_custom" id="time_format_custom" value="' . esc_attr( get_option( 'time_format' ) ) . '" class="small-text" required />' . 568 568 '<p><strong>' . __( 'Preview:' ) . '</strong> <span class="example">' . date_i18n( get_option( 'time_format' ) ) . '</span>' . 569 569 "<span class='spinner'></span>\n" . '</p>';
No need for custom JS.
Related: The novalidate attribute was removed from the comments form in #47595.
#11
@
2 weeks ago
Thanks @westonruter for the minimal patch suggestion — that's a much cleaner approach. I've updated the PR to drop the custom JS validation entirely and instead:
- Removed novalidate="novalidate" from the <form> in options-general.php so the browser's built-in constraint validation fires.
- Added required to the date_format_custom and time_format_custom inputs.
This ticket was mentioned in Slack in #core by abdullahramzan. View the logs.
6 days ago
#14
@
5 days ago
Test Report
I have tested latest patch and it is working as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/11903
Environment
- WordPress: 7.1-alpha-20260529.035253
- Subdirectory: No
- PHP: 8.3.31
- Server: PHP.wasm
- Database: WP_SQLite_Driver (Server: 8.0.38 / Client: 3.51.0)
- Browser: Chrome 148.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.5
- MU Plugins: None activated
- Plugins:
- Test Reports 1.3.0
Actual Results
- ✅ Issue resolved with patch.
Additional Notes
- After applying the patch, the issue with the Custom Time & Date Format fields allowing empty values has been resolved.
Screenshots/Screencast with results
#15
@
5 days ago
I have tested on https://playground.wordpress.net/ and seems working fine for me. more information you can see mentioned screenshot.
@
5 days ago
tested on Playground using this link - https://playground.wordpress.net/wordpress.html?pr=11903


I have tested and able to generate this issue. So we need to implement validation here.