Skip to content

Commit

Permalink
dashboard widget should show today only, hide if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Nov 1, 2023
1 parent 681d7fe commit eedf5a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public function register_dashboard_widget(): void
public function dashboard_widget(): void
{
$stats = new Stats();
$dateStart = create_local_datetime('-1 days');
$dateEnd = create_local_datetime('now');
$dateStart = create_local_datetime('today, midnight');
$dateEnd = create_local_datetime('tomorrow, midnight');
$realtime = get_realtime_pageview_count('-1 hour');
$posts = $stats->get_posts($dateStart->format('Y-m-d'), $dateEnd->format('Y-m-d'), 0, 3);
$referrers = $stats->get_referrers($dateStart->format('Y-m-d'), $dateEnd->format('Y-m-d'), 0, 3);
Expand Down
4 changes: 4 additions & 0 deletions src/views/dashboard-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</div>
</div>

<?php if (count($posts) > 0) { ?>
<div id="ka-dashboard-widget-top-pages">
<h3 style="margin-top: 2em;">
<?php echo esc_html__('Most viewed pages today', 'koko-analytics'); ?>
Expand All @@ -44,7 +45,9 @@
<?php } ?>
</ul>
</div>
<?php } ?>

<?php if (count($referrers) > 0) { ?>
<div id="ka-dashboard-widget-top-referrers">
<h3 style="margin-top: 2em;">
<?php echo esc_html__('Top referrers today', 'koko-analytics'); ?>
Expand All @@ -59,6 +62,7 @@
<?php } ?>
</ul>
</div>
<?php } ?>

<p style="margin-top: 2em;">
<a href="<?php echo esc_attr(admin_url('index.php?page=koko-analytics')); ?>">
Expand Down

0 comments on commit eedf5a6

Please sign in to comment.