PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.7.2
Independent Analytics – WordPress Analytics Plugin v2.7.2
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / IAWP / Dashboard_Widget.php
Dashboard_Widget.php
54 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IAWP;
4
5 use IAWP\Date_Range\Relative_Date_Range;
6 use IAWP\Statistics\Page_Statistics;
7 /** @internal */
8 class Dashboard_Widget
9 {
10 public function __construct()
11 {
12 if ($this->is_enabled()) {
13 \add_action('wp_dashboard_setup', [$this, 'add_dashboard_widget']);
14 }
15 }
16 public function add_dashboard_widget()
17 {
18 if (\IAWP\Migrations\Migrations::is_migrating() || !\IAWP\Capability_Manager::can_view()) {
19 return;
20 }
21 \ob_start();
22 ?>
23 <span><?php
24 \esc_html_e('Analytics', 'independent-analytics');
25 ?></span>
26 <span>
27 <a href="<?php
28 echo \esc_url(\IAWPSCOPED\iawp_dashboard_url());
29 ?>" class="iawp-button purple">
30 <?php
31 \esc_html_e('Open Dashboard', 'independent-analytics');
32 ?>
33 </a>
34 </span>
35 <?php
36 $title = \ob_get_contents();
37 \ob_end_clean();
38 \wp_add_dashboard_widget('iawp', $title, [$this, 'dashboard_widget']);
39 }
40 public function dashboard_widget()
41 {
42 $date_range = new Relative_Date_Range('LAST_THIRTY');
43 $statistics = new Page_Statistics($date_range);
44 $chart = new \IAWP\Chart($statistics, \true);
45 $stats = new \IAWP\Quick_Stats($statistics, \true);
46 echo $chart->get_html();
47 echo $stats->get_html();
48 }
49 private function is_enabled() : bool
50 {
51 return \get_option('iawp_disable_widget') !== '1';
52 }
53 }
54