Skip to content

Commit edbfaba

Browse files
allow calling get_realtime_pageview_count with null parameter
1 parent 75c9665 commit edbfaba

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/class-rest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ public function get_referrers(\WP_REST_Request $request): \WP_REST_Response
215215
public function get_realtime_pageview_count(\WP_REST_Request $request)
216216
{
217217
$params = $request->get_query_params();
218-
$since = isset($params['since']) ? strtotime($params['since']) : null;
219-
return get_realtime_pageview_count($since);
218+
return get_realtime_pageview_count($params['since'] ?? null);
220219
}
221220
}

src/functions.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace KokoAnalytics;
1010

11+
use ParagonIE\Sodium\Core\Curve25519\Ge\P2;
1112
use WP_Admin_Bar;
1213
use WP_Query;
1314
use WP_Post;
@@ -133,17 +134,20 @@ function widgets_init()
133134
}
134135

135136
/**
136-
* @param int|string $since Either an integer timestamp (in seconds since Unix epoch) or a relative time string that strtotime understands.
137+
* @param int|string|null $since Either an integer timestamp (in seconds since Unix epoch) or a relative time string that strtotime understands.
137138
* @return int
138139
*/
139-
function get_realtime_pageview_count($since = '-5 minutes'): int
140+
function get_realtime_pageview_count($since = null): int
140141
{
141-
if (is_numeric($since)) {
142+
if (is_numeric($since) || is_int($since)) {
142143
$since = (int) $since;
143-
} else {
144+
} elseif (is_string($since)) {
144145
// $since is relative time string
145146
$since = strtotime($since);
147+
} else {
148+
$since = strtotime('-5 minutes');
146149
}
150+
147151
$counts = (array) get_option('koko_analytics_realtime_pageview_count', []);
148152
$sum = 0;
149153
foreach ($counts as $timestamp => $pageviews) {

0 commit comments

Comments
 (0)