Skip to content

fix: replace date() with gmdate() and rand() with wp_rand() - #211

Open
masteradhoc wants to merge 2 commits into
woocommerce:trunkfrom
masteradhoc:FunctionChanges
Open

fix: replace date() with gmdate() and rand() with wp_rand()#211
masteradhoc wants to merge 2 commits into
woocommerce:trunkfrom
masteradhoc:FunctionChanges

Conversation

@masteradhoc

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Replace PHP native date() with WordPress's gmdate() and rand() with wp_rand() across Settings.php and Order.php.

  • date() is affected by the server's runtime timezone and can produce inconsistent timestamps depending on the environment. gmdate() always outputs UTC, which is what WordPress expects internally.
  • rand() is PHP's native PRNG and is flagged by WordPress coding standards. wp_rand() is the recommended drop-in replacement.

These changes resolve 12 PHPCS errors (WordPress.DateTime.RestrictedFunctions.date_date and WordPress.WP.AlternativeFunctions.rand_rand) and move towards resolving #209.

Related to #209.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changelog entry

Replace date() with gmdate() and rand() with wp_rand() to comply with WordPress coding standards and ensure timezone-safe date output.

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant