diff --git a/includes/class-settings.php b/includes/class-settings.php index dd3952b..b86426d 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -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, diff --git a/tests/SettingsCounterTest.php b/tests/SettingsCounterTest.php index eb195d0..b32ec27 100644 --- a/tests/SettingsCounterTest.php +++ b/tests/SettingsCounterTest.php @@ -49,7 +49,7 @@ final class SettingsCounterTest extends Cf7stgTestCase Settings::increment_drop_counter('real'); $c = Settings::get_drop_counters(); - self::assertSame(date('Y-m-d'), $c['today_date']); + self::assertSame(wp_date('Y-m-d'), $c['today_date']); self::assertSame(5, $c['real_yesterday']); self::assertSame(1, $c['real_today']); self::assertSame(6, $c['total']); @@ -64,7 +64,7 @@ final class SettingsCounterTest extends Cf7stgTestCase self::assertSame(0, $c['total']); self::assertSame(0, $c['real_today']); self::assertSame(0, $c['dry_today']); - self::assertSame(date('Y-m-d'), $c['reset_at']); + self::assertSame(wp_date('Y-m-d'), $c['reset_at']); } public function test_get_dry_run_drop_default_true_when_unset(): void