PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.10.1
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.10.1
4.7.4 4.7.5 4.7.3 4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 All 95 releases
cookiebot / addons / controller / addons / google-site-kit / google-site-kit.php

google-site-kit.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 3.10.1, at addons/controller/addons/google-site-kit/google-site-kit.php

332 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace cookiebot_addons\controller\addons\google_site_kit;
4
5 use cookiebot_addons\controller\addons\Cookiebot_Addons_Interface;
6 use cookiebot_addons\lib\Cookie_Consent_Interface;
7 use cookiebot_addons\lib\Settings_Service_Interface;
8 use cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface;
9 use cookiebot_addons\lib\buffer\Buffer_Output_Interface;
10
11 class Google_Site_Kit implements Cookiebot_Addons_Interface {
12
13 /**
14 * @var Settings_Service_Interface
15 *
16 * @since 1.3.0
17 */
18 protected $settings;
19
20 /**
21 * @var Script_Loader_Tag_Interface
22 *
23 * @since 1.3.0
24 */
25 protected $script_loader_tag;
26
27 /**
28 * @var Cookie_Consent_Interface
29 *
30 * @since 1.3.0
31 */
32 public $cookie_consent;
33
34 /**
35 * @var Buffer_Output_Interface
36 *
37 * @since 1.3.0
38 */
39 protected $buffer_output;
40
41 /**
42 * Jetpack constructor.
43 *
44 * @param $settings Settings_Service_Interface
45 * @param $script_loader_tag Script_Loader_Tag_Interface
46 * @param $cookie_consent Cookie_Consent_Interface
47 * @param $buffer_output Buffer_Output_Interface
48 *
49 * @since 1.3.0
50 */
51 public function __construct(
52 Settings_Service_Interface $settings,
53 Script_Loader_Tag_Interface $script_loader_tag,
54 Cookie_Consent_Interface $cookie_consent,
55 Buffer_Output_Interface $buffer_output
56 ) {
57 $this->settings = $settings;
58 $this->script_loader_tag = $script_loader_tag;
59 $this->cookie_consent = $cookie_consent;
60 $this->buffer_output = $buffer_output;
61 }
62
63 /**
64 * Loads addon configuration
65 *
66 * @since 1.3.0
67 */
68 public function load_configuration() {
69 add_action( 'wp_loaded', array( $this, 'cookiebot_addon_google_site_kit' ), 5 );
70 }
71
72 /**
73 * Disable scripts if state not accepted
74 *
75 * @since 1.3.0
76 */
77 public function cookiebot_addon_google_site_kit() {
78 // Google Tag Manager
79 $this->script_loader_tag->add_tag( 'google_gtagjs', $this->get_cookie_types() );
80 }
81
82 /**
83 * Return addon/plugin name
84 *
85 * @return string
86 *
87 * @since 1.3.0
88 */
89 public function get_addon_name() {
90 return 'Google Site Kit';
91 }
92
93 /**
94 * Default placeholder content
95 *
96 * @return string
97 *
98 * @since 1.8.0
99 */
100 public function get_default_placeholder() {
101 return 'Please accept [renew_consent]%cookie_types[/renew_consent] cookies to enable Google Analytics.';
102 }
103
104 /**
105 * Get placeholder content
106 *
107 * This function will check following features:
108 * - Current language
109 *
110 * @param $src
111 *
112 * @return bool|mixed
113 *
114 * @since 1.8.0
115 */
116 public function get_placeholder( $src = '' ) {
117 return $this->settings->get_placeholder( $this->get_option_name(), $this->get_default_placeholder(),
118 cookiebot_addons_output_cookie_types( $this->get_cookie_types() ), $src );
119 }
120
121 /**
122 * Option name in the database
123 *
124 * @return string
125 *
126 * @since 1.3.0
127 */
128 public function get_option_name() {
129 return 'google_site_kit';
130 }
131
132 /**
133 * Plugin file name
134 *
135 * @return string
136 *
137 * @since 1.3.0
138 */
139 public function get_plugin_file() {
140 return 'google-site-kit/google-site-kit.php';
141 }
142
143 /**
144 * Returns checked cookie types
145 * @return mixed
146 *
147 * @since 1.3.0
148 */
149 public function get_cookie_types() {
150 return $this->settings->get_cookie_types( $this->get_option_name(), $this->get_default_cookie_types() );
151 }
152
153 /**
154 * Returns default cookie types
155 * @return array
156 *
157 * @since 1.5.0
158 */
159 public function get_default_cookie_types() {
160 return array( 'marketing', 'statistics' );
161 }
162
163 /**
164 * Check if plugin is activated and checked in the backend
165 *
166 * @since 1.3.0
167 */
168 public function is_addon_enabled() {
169 return $this->settings->is_addon_enabled( $this->get_option_name() );
170 }
171
172 /**
173 * Checks if addon is installed
174 *
175 * @since 1.3.0
176 */
177 public function is_addon_installed() {
178 return $this->settings->is_addon_installed( $this->get_plugin_file() );
179 }
180
181 /**
182 * Checks if addon is activated
183 *
184 * @since 1.3.0
185 */
186 public function is_addon_activated() {
187 return $this->settings->is_addon_activated( $this->get_plugin_file() );
188 }
189
190 /**
191 * Retrieves current installed version of the addon
192 *
193 * @return bool
194 *
195 * @since 2.2.1
196 */
197 public function get_addon_version() {
198 return $this->settings->get_addon_version( $this->get_plugin_file() );
199 }
200
201 /**
202 * Checks if it does have custom placeholder content
203 *
204 * @return mixed
205 *
206 * @since 1.8.0
207 */
208 public function has_placeholder() {
209 return $this->settings->has_placeholder( $this->get_option_name() );
210 }
211
212 /**
213 * returns all placeholder contents
214 *
215 * @return mixed
216 *
217 * @since 1.8.0
218 */
219 public function get_placeholders() {
220 return $this->settings->get_placeholders( $this->get_option_name() );
221 }
222
223 /**
224 * Return true if the placeholder is enabled
225 *
226 * @return mixed
227 *
228 * @since 1.8.0
229 */
230 public function is_placeholder_enabled() {
231 return $this->settings->is_placeholder_enabled( $this->get_option_name() );
232 }
233
234 /**
235 * Adds extra information under the label
236 *
237 * @return string
238 *
239 * @since 1.8.0
240 */
241 public function get_extra_information() {
242 return '<p>' . esc_html__( 'Blocks Google Analytics scripts', 'cookiebot-addons' ) . '</p>';
243 }
244
245 /**
246 * Returns the url of WordPress SVN repository or another link where we can verify the plugin file.
247 *
248 * @return string
249 *
250 * @since 1.8.0
251 */
252 public function get_svn_url() {
253 return 'http://plugins.svn.wordpress.org/google-site-kit/trunk/google-site-kit.php';
254 }
255
256 /**
257 * Placeholder helper overlay in the settings page.
258 *
259 * @return string
260 *
261 * @since 1.8.0
262 */
263 public function get_placeholder_helper() {
264 return '<p>Merge tags you can use in the placeholder text:</p><ul><li>%cookie_types - Lists required cookie types</li><li>[renew_consent]text[/renew_consent] - link to display cookie settings in frontend</li></ul>';
265 }
266
267
268 /**
269 * Returns parent class or false
270 *
271 * @return string|bool
272 *
273 * @since 2.1.3
274 */
275 public function get_parent_class() {
276 return get_parent_class( $this );
277 }
278
279 /**
280 * Action after enabling the addon on the settings page
281 *
282 * @since 2.2.0
283 */
284 public function post_hook_after_enabling() {
285 //do nothing
286 }
287
288 /**
289 * Cookiebot plugin is deactivated
290 *
291 * @since 2.2.0
292 */
293 public function plugin_deactivated() {
294 //do nothing
295 }
296
297 /**
298 * @return mixed
299 *
300 * @since 2.4.5
301 */
302 public function extra_available_addon_option() {
303 //do nothing
304 }
305
306 /**
307 * Returns boolean to enable/disable plugin by default
308 *
309 * @return bool
310 *
311 * @since 3.6.3
312 */
313 public function enable_by_default() {
314 return false;
315 }
316
317 /**
318 * Sets default settings for this addon
319 *
320 * @return array
321 *
322 * @since 3.6.3
323 */
324 public function get_default_enable_setting() {
325 return array(
326 'enabled' => 1,
327 'cookie_type' => $this->get_default_cookie_types(),
328 'placeholder' => $this->get_default_placeholder(),
329 );
330 }
331 }
332