fix: replace date() with WordPress Date/Time API in 14 files#3196
Closed
faisalahammad wants to merge 2 commits into
Closed
fix: replace date() with WordPress Date/Time API in 14 files#3196faisalahammad wants to merge 2 commits into
faisalahammad wants to merge 2 commits into
Conversation
Fixes 40 WordPress.DateTime.RestrictedFunctions.date_date violations
flagged by the Plugin Check scanner across 14 files. Uses gmdate() for
deterministic UTC storage and SQL boundaries, wp_date() for site-local
display and site-timezone boundaries, and current_time('mysql') for
'now' timestamps. Removes the project-wide PHPCS exclusion for the
date_date sniff so future regressions are caught.
Contributor
|
Some of these changes from date() to wp_date() introduce potential off-by-one-date errors when the timezone is taken into account. Same with the switch from date() to We'll need to plan this through more carefully, likely just replacing date() with gmdate() across the board. Closing for now. |
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.
Summary
Replace date() calls with WordPress-compliant alternatives (gmdate, wp_date, current_time) across 14 files. Remove PHPCS exclusion for WordPress.DateTime.RestrictedFunctions.date_date sniff so future violations are caught by check-cs.
Fixes 40 PCP date_date violations.
Changes
Core date class (includes/class.llms.date.php)
Before:
After:
Why: wp_date() respects site timezone for display. gmdate() for DB storage. current_time('Y/m') for upload paths.
Voucher timestamps (includes/class.llms.voucher.php)
All date('Y-m-d H:i:s') for created_at/updated_at/redemption_date replaced with current_time('mysql').
Administative views (includes/admin/views/dashboard.php)
date(get_option('date_format'), …) changed to wp_date() for locale-aware display. Date boundaries use gmdate().
Config (phpcs.xml)
Removed the
WordPress.DateTime.RestrictedFunctions.date_dateexclusion that skipped this sniff project-wide. The @todo note about WP 5.3 is no longer relevant as the minimum WP version is 5.9.Testing