Normalize date-type user field values to Y-m-d on import - #84
Merged
andrewlimaza merged 2 commits intoAug 25, 2026
Conversation
Date user fields render as <input type="date">, which requires the stored meta to be exactly YYYY-MM-DD. Values imported in other formats (e.g. 7/26/22) were stored raw, rendering blank on profile edit screens and risking silent data wipe on the next profile save. Parseable values are reformatted via strtotime(); unparseable values are left unchanged so they stay visible and correctable, matching the existing option-key mapping philosophy in pmproiucsv_normalize_user_field_meta_value(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Council review caught that strtotime() silently normalizes invalid dates
(2/30/2022 becomes 2022-03-02), corrupting typos into plausible wrong values.
Switch to date_parse() + checkdate() so only calendar-valid absolute dates
are reformatted; everything else is stored unchanged. Relative strings
("+1 week") are now also rejected. Docblock updated for the wider scope.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Ran this through the review council; one Major confirmed and fixed in the follow-up commit: Calendar-invalid dates no longer silently roll forward. On the review's open questions:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extends
pmproiucsv_normalize_user_field_meta_value()(added in #78 for multi-value fields) to also normalize date-type user fields during import:YYYY-MM-DDpass through unchanged.7/26/22,07/26/2022, etc.) are reformatted viastrtotime()→Y-m-d.25/01/2026) are stored unchanged so they stay visible and correctable — same philosophy as the existing option-key mapping in this function.Why
PMPro date user fields render as
<input type="date">, which requires stored meta to be exactlyYYYY-MM-DD. Anything else silently renders blank on Edit User / profile screens even though the value is in the database — and saving that profile submits the empty input, wiping the stored value.Real-world case (LBCA migration, 2026-08): 1,275 members imported with
m/d/yyjoin dates via this plugin. The field appeared blank in admin profiles and via[pmpro_member], while CSV export (raw meta) still showed values — a confusing symptom set. Several users' dates were wiped by subsequent profile saves before diagnosis.Notes
membership_startdate/enddate) already run throughstrtotime()inpmproiucsv_pmp_import_usermeta()processing; their stricter validation is tracked separately in Validate date format on import — require YYYY-MM-DD, surface error for other formats #76. This PR scopes to custom user field meta only.00-69→ 20xx). The importer can't assume future dates are invalid (expiration-style date fields legitimately hold future dates), so no century heuristic is applied.7/26/22,2022-07-26,07/26/2022,6/1/68,garbage,25/01/2026,0, and non-date field passthrough.🤖 Generated with Claude Code