Opened 3 years ago
Last modified 4 days ago
#56887 accepted defect (bug)
wp_exif_date2ts throws notice on slash formatted date
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | 5.2.3 |
| Component: | Date/Time | Keywords: | has-patch has-unit-tests has-test-info |
| Focuses: | Cc: |
Description (last modified by )
When an image has an exif date in the format ...
YYYY/MM/DD HH:MM:SS
... rather than ...
YYYY:MM:DD HH:MM:SS
... which is happening more and more I have noticed, the following PHP notices are thrown ...
PHP Notice: Undefined offset: 1 in /.../wp-admin/includes/image.php on line 710
PHP Notice: Undefined offset: 2 in /.../wp-admin/includes/image.php on line 710
I think there are a lot of assumptions being made in wp_exif_date2ts() and I believe that a preg_match check like ...
<?php if (preg_match('/^(?>\d){4}[:|\/](?>\d){2}[:|\/](?>\d){2} (?>\d){2}:(?>\d){2}:(?>\d){2}$/', $str)) { // Process and return exif date } else { return false; }
... should be done instead.
This is related to ticket 48204
Change History (9)
This ticket was mentioned in PR #8884 on WordPress/wordpress-develop by @pbearne.
9 months ago
#2
- Keywords has-patch has-unit-tests added
#3
@
9 months ago
- Milestone changed from Awaiting Review to 6.9
- Owner set to pbearne
- Status changed from new to accepted
This fixes https://core.trac.wordpress.org/ticket/48204 as well
#4
@
4 months ago
- Keywords needs-testing added
PR 8884 needs to be tested. Furthermore, since this pull request introduces a new wp_exif_datetime() function, I suggest changing the milestone to 7.0.
This ticket was mentioned in Slack in #core-test by krupajnanda. View the logs.
4 months ago
This ticket was mentioned in Slack in #core-test by nikunj8866. View the logs.
3 months ago
#8
@
3 months ago
- Keywords has-test-info added; needs-testing removed
Test Report
Description
✅ This report validates that the indicated patch works as expected. The patch ensures that EXIF dates using slash-formatted values (e.g., YYYY/MM/DD HH:MM:SS) no longer trigger PHP warnings in wp_exif_date2ts().
Patch tested: https://github.com/WordPress/wordpress-develop/pull/8884
Steps to Reproduce
- Add the following test code to your site (mu-plugin or snippet):
add_action( 'init', function () {
if ( isset( $_GET['testing'] ) && '56887' === $_GET['testing'] ) {
require_once ABSPATH . 'wp-admin/includes/image.php';
$date = '2025/11/12 14:30:00';
echo 'Input: ' . $date . '<br>';
$timestamp = wp_exif_date2ts( $date );
echo 'Formatted: ' . date( 'Y-m-d H:i:s', $timestamp );
exit;
}
});
- Visit: https://YOUR-SITE.COM/?testing=56887
- Compare the behavior before and after applying the patch.
Environment
- WordPress: 6.8.3
- PHP: 8.4.10
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.4.10)
- Browser: Chrome 142.0.0.0
- OS: Windows 10/11
- Theme: Astra 4.11.13
- MU Plugins:
- Plugins:
- Test Reports 1.0.0
Actual Results
- ✅ The issue is resolved with the patch.
- Slash-formatted EXIF dates (2025/11/12 14:30:00) no longer trigger warnings.
Additional Notes
🐞 The formatted output shows a 2-hour difference:
Input: 2025/11/12 14:30:00 Formatted: 2025-11-12 12:30:00
Not sure whether this is expected behavior after the patch.
Supplemental Artifacts
Before: https://prnt.sc/V-DuRxcqEoZR
After: https://prnt.sc/G3X38HcCKNC-
Replaced
wp_exif_date2tslogic with the newwp_exif_datetimefunction for cleaner and reusable code. Enhanced metadata to store RFC3339 formatted dates while maintaining backward compatibility. Added comprehensive PHPUnit tests for EXIF date validation and edge cases.Fixes 48204 as well
Trac ticket: 56887