Skip to content

fix: replace date() with WordPress Date/Time API in 14 files#3196

Closed
faisalahammad wants to merge 2 commits into
gocodebox:devfrom
faisalahammad:fix/wordpress-datetime-date_date
Closed

fix: replace date() with WordPress Date/Time API in 14 files#3196
faisalahammad wants to merge 2 commits into
gocodebox:devfrom
faisalahammad:fix/wordpress-datetime-date_date

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

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:

return date( 'd/m/Y', strtotime( $date ) );
$today = current_time( 'Y-m-d' );
$current_month = date( 'm', strtotime( $today ) );
return date( 'd.m.Y H:i:s', get_user_meta( $user_id, 'llms_last_login', true ) );

After:

return wp_date( 'd/m/Y', strtotime( $date ) );
$today = current_time( 'Y-m-d' );
$current_month = wp_date( 'm', strtotime( $today ) );
return wp_date( 'd.m.Y H:i:s', get_user_meta( $user_id, 'llms_last_login', true ) );

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_date exclusion 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

  1. composer check-cs -- verify project PHPCS passes with date_date sniff active
  2. vendor/bin/phpcs --standard=WordPress --sniffs=WordPress.DateTime.RestrictedFunctions on modified files -- zero violations
  3. php -l on all 14 modified files -- no syntax errors

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.
@faisalahammad
faisalahammad requested a review from brianhogg as a code owner June 19, 2026 04:51
@brianhogg brianhogg moved this to Awaiting Review in Development Jun 19, 2026
@brianhogg

Copy link
Copy Markdown
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 current_time( 'mysql' ) modifies storage from UTC to local time, with no flag or indicator on which is which.

We'll need to plan this through more carefully, likely just replacing date() with gmdate() across the board. Closing for now.

@brianhogg brianhogg closed this Jul 20, 2026
@github-project-automation github-project-automation Bot moved this from Awaiting Review to Done in Development Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants