fix(settings): wp_date() respects WP timezone; clarify counter is not atomic
- Replace date('Y-m-d') with wp_date('Y-m-d') in increment_drop_counter and
default_drop_counters to respect WordPress timezone settings.
- Update corresponding test assertions to use wp_date() for consistency.
- Clarify in docblock that increment_drop_counter is not atomic under concurrent
submissions; read-modify-write pattern via update_option is acceptable for
low-volume dashboard counters.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -125,15 +125,18 @@ final class Settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically increments the drop counter. `$mode` must be 'real' or 'dry_run';
|
||||
* Increments the drop counter. `$mode` must be 'real' or 'dry_run';
|
||||
* any other value is a no-op (defensive — guards against typos in callers).
|
||||
* Performs rolling today→yesterday on date change.
|
||||
*
|
||||
* Note: not atomic under concurrent CF7 submissions — `update_option` is a
|
||||
* read-modify-write. Acceptable for low-volume dashboard counters.
|
||||
*/
|
||||
public static function increment_drop_counter(string $mode): void
|
||||
{
|
||||
if (!in_array($mode, ['real', 'dry_run'], true)) return;
|
||||
$c = self::get_drop_counters();
|
||||
$today = date('Y-m-d');
|
||||
$today = wp_date('Y-m-d');
|
||||
if ($c['today_date'] !== $today) {
|
||||
$c['real_yesterday'] = $c['real_today'];
|
||||
$c['dry_yesterday'] = $c['dry_today'];
|
||||
@@ -157,7 +160,7 @@ final class Settings
|
||||
|
||||
private static function default_drop_counters(): array
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$today = wp_date('Y-m-d');
|
||||
return [
|
||||
'total' => 0,
|
||||
'real_today' => 0,
|
||||
|
||||
Reference in New Issue
Block a user