-
Notifications
You must be signed in to change notification settings - Fork 0
/
innstats.php
76 lines (62 loc) · 1.9 KB
/
innstats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Plugin Name: Innstats
* Description: Collects statistics through Plausible and shows analytics in admin panel. Also, provides API for developers to retrieve data.
* Version: 1.2.0
* Author: SMFB Dinamo
* Author URI: https://www.smfb-dinamo.com/
* Tested up to: 6.2
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
}
use WPD\Statistics;
define( 'INNSTATS_FILE', __FILE__ );
define( 'INNSTATS_VERSION', '1.2.0' );
$GLOBALS['innstats'] = new Statistics\Plugin(
[
Statistics\Plugin::PROVIDER_PLAUSIBLE, // @TODO: move to constant in case if more providers will be added
]
);
if ( ! defined( 'INNSTATS_QUERY_ARG' ) ) {
define( 'INNSTATS_QUERY_ARG', 'innstats' );
}
$GLOBALS['innstats']->get_query()->set_name( INNSTATS_QUERY_ARG );
if ( $GLOBALS['innstats']->has_provider( Statistics\Plugin::PROVIDER_PLAUSIBLE ) ) {
if ( ! defined( 'PLAUSIBLE_API_ROOT' ) ) {
define( 'PLAUSIBLE_API_ROOT', 'https://plausible.io' );
}
$GLOBALS['innstats']
->get_provider( Statistics\Plugin::PROVIDER_PLAUSIBLE )
->get_api()
->set_root( PLAUSIBLE_API_ROOT );
if ( defined( 'PLAUSIBLE_API_KEY' ) ) {
$GLOBALS['innstats']
->get_provider( Statistics\Plugin::PROVIDER_PLAUSIBLE )
->get_api()
->get_stats()
->set_token( PLAUSIBLE_API_KEY );
}
if ( defined( 'PLAUSIBLE_SITES_API_KEY' ) ) {
$GLOBALS['innstats']
->get_provider( Statistics\Plugin::PROVIDER_PLAUSIBLE )
->get_api()
->get_site_provisioning()
->set_token( PLAUSIBLE_SITES_API_KEY );
}
}
if ( defined( 'INNSTATS_PLAN' ) ) {
$GLOBALS['innstats']->set_current_plan( INNSTATS_PLAN );
}
$GLOBALS['innstats']->run();
if ( ! function_exists( 'innstats' ) ) {
/**
* @return Statistics\Plugin|null
*/
function innstats() : ?Statistics\Plugin {
global $innstats;
return $innstats;
}
}