forked from plausible/wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
111 lines (98 loc) · 2.5 KB
/
Plugin.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Plausible\Analytics\WP;
use Plausible\Analytics\WP\Admin;
use Plausible\Analytics\WP\Includes;
use Plausible\Analytics\WP\Includes\Helpers;
// Bailout, if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Loads and registers plugin functionality through WordPress hooks.
*
* @since 1.0.0
*/
final class Plugin {
/**
* Registers functionality with WordPress hooks.
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function register() {
// Handle plugin activation and deactivation.
register_activation_hook( PLAUSIBLE_ANALYTICS_PLUGIN_FILE, [ $this, 'activate' ] );
register_deactivation_hook( PLAUSIBLE_ANALYTICS_PLUGIN_FILE, [ $this, 'deactivate' ] );
// Register services used throughout the plugin.
add_action( 'plugins_loaded', [ $this, 'register_services' ] );
// Load text domain.
add_action( 'init', [ $this, 'load_plugin_textdomain' ] );
}
/**
* Registers the individual services of the plugin.
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function register_services() {
if ( is_admin() ) {
new Admin\Settings();
new Admin\Filters();
new Admin\Actions();
}
new Includes\Actions();
new Includes\Filters();
}
/**
* Loads the plugin's translated strings.
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'plausible-analytics',
false,
dirname( plugin_basename( PLAUSIBLE_ANALYTICS_PLUGIN_FILE ) ) . '/languages/'
);
}
/**
* Handles activation procedures during installation and updates.
*
* @since 1.0.0
* @access public
*
* @param bool $network_wide Optional. Whether the plugin is being enabled on
* all network sites or a single site. Default false.
*
* @return void
*/
public function activate( $network_wide = false ) {
$is_default_settings_saved = get_option( 'plausible_analytics_is_default_settings_saved', false );
if ( ! $is_default_settings_saved ) {
$default_settings = [
'domain_name' => Helpers::get_domain(),
'custom_domain' => false,
'custom_domain_prefix' => 'analytics',
'track_administrator' => false,
];
update_option( 'plausible_analytics_settings', $default_settings );
update_option( 'plausible_analytics_is_default_settings_saved', true );
}
}
/**
* Handles deactivation procedures.
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function deactivate() {}
}