-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathHooks.php
173 lines (160 loc) · 4.24 KB
/
Hooks.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* Plausible Analytics | Settings Page Hooks.
*
* @since 2.1.0
* @package WordPress
* @subpackage Plausible Analytics
*
* @noinspection HtmlUnknownTarget
*/
namespace Plausible\Analytics\WP\Admin\Settings;
use Plausible\Analytics\WP\Helpers;
/**
* @codeCoverageIgnore
*/
class Hooks extends API {
/**
* Build class properties.
*/
public function __construct( $init = true ) {
if ( $init ) {
$this->init_hooks();
}
}
/**
* Init action hooks.
*
* @return void
*/
private function init_hooks() {
add_filter( 'plausible_analytics_toggle_option_success_message', [ $this, 'maybe_modify_success_message' ], 10, 3 );
add_action( 'plausible_analytics_settings_api_token_missing', [ $this, 'missing_api_token_warning' ] );
add_action( 'plausible_analytics_settings_enable_analytics_dashboard_notice', [ $this, 'enable_analytics_dashboard_notice' ] );
add_action( 'plausible_analytics_settings_option_disabled_by_missing_api_token', [ $this, 'option_disabled_by_missing_api_token' ] );
add_action( 'plausible_analytics_settings_option_disabled_by_proxy', [ $this, 'option_disabled_by_proxy' ] );
add_action( 'plausible_analytics_settings_option_not_available_in_ce', [ $this, 'option_na_in_ce' ] );
add_action( 'plausible_analytics_settings_proxy_warning', [ $this, 'proxy_warning' ] );
}
/**
* Modifies "Enable proxy enabled" to "Proxy enabled", etc.
*
* @param $message
* @param $option_name
* @param $status
*
* @return string
*/
public function maybe_modify_success_message( $message, $option_name, $status ) {
if ( $option_name !== 'proxy_enabled' ) {
return $message;
}
if ( ! $status ) {
return __( 'Proxy disabled.', 'plausible-analytics' );
}
return __( 'Proxy enabled.', 'plausible-analytics' );
}
/**
* Renders the warning for the Enable Proxy option.
*
* @since 1.3.0
* @output HTML
*/
public function proxy_warning() {
if ( ! empty( Helpers::get_settings()[ 'self_hosted_domain' ] ) ) {
$this->option_na_in_ce();
} else {
echo sprintf(
wp_kses(
__(
'After enabling this option, please check your Plausible dashboard to make sure stats are being recorded. Are stats not being recorded? Do <a href="%s" target="_blank">reach out to us</a>. We\'re here to help!',
'plausible-analytics'
),
'post'
),
'https://plausible.io/contact'
);
}
}
/**
* Show notice when Plugin Token notice is disabled.
*
* @output HTML
*/
public function option_na_in_ce() {
echo wp_kses(
__(
'This feature is not available in Plausible Community Edition.',
'plausible-analytics'
),
'post'
);
}
/**
* Renders the analytics dashboard link if the option is enabled.
*
* @since 2.0.0
* @output HTML
*/
public function enable_analytics_dashboard_notice() {
if ( ! empty( Helpers::get_settings()[ 'enable_analytics_dashboard' ] ) ) {
echo sprintf(
wp_kses(
__(
'Your analytics dashboard is available <a href="%s">here</a>.',
'plausible-analytics'
),
'post'
),
admin_url( 'index.php?page=plausible_analytics_statistics' )
);
}
}
/**
* Renders the Self-hosted warning if the Proxy is enabled.
*
* @since 1.3.3
* @output HTML
*/
public function option_disabled_by_proxy() {
if ( Helpers::proxy_enabled() ) {
echo wp_kses(
__(
'This option is disabled, because the <strong>Proxy</strong> setting is enabled under <em>Settings</em>.',
'plausible-analytics'
),
'post'
);
}
}
/**
* Display missing Plugin Token warning.
*
* @output HTML
*/
public function missing_api_token_warning() {
echo sprintf(
wp_kses(
__(
'Please <a class="plausible-create-api-token hover:cursor-pointer underline">create a Plugin Token</a> and insert it into the Plugin Token field above.',
'plausible-analytics'
),
'post'
)
);
}
/**
* Display option disabled by missing Plugin Token warning.
*
* @output HTML
*/
public function option_disabled_by_missing_api_token() {
echo wp_kses(
__(
'Please <a class="plausible-create-api-token hover:cursor-pointer underline">create a Plugin Token</a> and insert it into the Plugin Token field above to enable this option.',
'plausible-analytics'
),
'post'
);
}
}