PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.10.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.10.0
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 3.5.0 3.6.0 All 93 releases
cookiebot / addons / controller / addons / wp-rocket / wp-rocket.php

wp-rocket.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 3.10.0, at addons/controller/addons/wp-rocket/wp-rocket.php

344 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\wp_rocket;
4
5 use cookiebot_addons\controller\addons\Cookiebot_Addons_Interface;
6 use cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface;
7 use cookiebot_addons\lib\Cookie_Consent_Interface;
8 use cookiebot_addons\lib\buffer\Buffer_Output_Interface;
9 use cookiebot_addons\lib\Settings_Service_Interface;
10
11 class Wp_Rocket 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 /**
70 * Exclude Cookiebot files from defer setting
71 */
72 add_filter( 'rocket_exclude_defer_js', array( $this, 'exclude_files' ) );
73 }
74
75 /**
76 * Exclude scripts from WP Rocket’s defer JS option.
77 *
78 * @param array $excluded_files Array of script URLs to be excluded
79 *
80 * @return array Extended array script URLs to be excluded
81 *
82 * @author Caspar Hübinger
83 * @since 3.6.2
84 */
85 public function exclude_files( $excluded_files = array() ) {
86 $excluded_files[] = 'consent.cookiebot.com';
87
88 return $excluded_files;
89 }
90
91 /**
92 * Check if plugin is activated and checked in the backend
93 *
94 * @since 1.3.0
95 */
96 public function is_addon_enabled() {
97 return $this->settings->is_addon_enabled( $this->get_option_name() );
98 }
99
100 /**
101 * Option name in the database
102 *
103 * @return string
104 *
105 * @since 1.3.0
106 */
107 public function get_option_name() {
108 return 'wp_rocket';
109 }
110
111 /**
112 * Returns checked cookie types
113 * @return mixed
114 *
115 * @since 1.3.0
116 */
117 public function get_cookie_types() {
118 return $this->settings->get_cookie_types( $this->get_option_name(), $this->get_default_cookie_types() );
119 }
120
121 /**
122 * Returns default cookie types
123 * @return array
124 *
125 * @since 1.3.0
126 */
127 public function get_default_cookie_types() {
128 return array( 'statistics' );
129 }
130
131 /**
132 * Return addon/plugin name
133 *
134 * @return string
135 *
136 * @since 1.3.0
137 */
138 public function get_addon_name() {
139 return 'WP Rocket';
140 }
141
142 /**
143 * Checks if addon is installed
144 *
145 * @since 1.3.0
146 */
147 public function is_addon_installed() {
148 return $this->settings->is_addon_installed( $this->get_plugin_file() );
149 }
150
151 /**
152 * Plugin file name
153 *
154 * @return string
155 *
156 * @since 1.3.0
157 */
158 public function get_plugin_file() {
159 return 'wp-rocket/wp-rocket.php';
160 }
161
162 /**
163 * Checks if addon is activated
164 *
165 * @since 1.3.0
166 */
167 public function is_addon_activated() {
168 return $this->settings->is_addon_activated( $this->get_plugin_file() );
169 }
170
171 /**
172 * Retrieves current installed version of the addon
173 *
174 * @return bool
175 *
176 * @since 2.2.1
177 */
178 public function get_addon_version() {
179 return $this->settings->get_addon_version( $this->get_plugin_file() );
180 }
181
182 /**
183 * Default placeholder content
184 *
185 * @return string
186 *
187 * @since 1.8.0
188 */
189 public function get_default_placeholder() {
190 return '';
191 }
192
193 /**
194 * Get placeholder content
195 *
196 * This function will check following features:
197 * - Current language
198 *
199 * @param $src
200 *
201 * @return bool|mixed
202 *
203 * @since 1.8.0
204 */
205 public function get_placeholder( $src = '' ) {
206 return $this->settings->get_placeholder( $this->get_option_name(),
207 $this->get_default_placeholder(),
208 cookiebot_addons_output_cookie_types( $this->get_cookie_types() ),
209 $src );
210 }
211
212 /**
213 * Checks if it does have custom placeholder content
214 *
215 * @return mixed
216 *
217 * @since 1.8.0
218 */
219 public function has_placeholder() {
220 return $this->settings->has_placeholder( $this->get_option_name() );
221 }
222
223 /**
224 * returns all placeholder contents
225 *
226 * @return mixed
227 *
228 * @since 1.8.0
229 */
230 public function get_placeholders() {
231 return $this->settings->get_placeholders( $this->get_option_name() );
232 }
233
234 /**
235 * Return true if the placeholder is enabled
236 *
237 * @return mixed
238 *
239 * @since 1.8.0
240 */
241 public function is_placeholder_enabled() {
242 return $this->settings->is_placeholder_enabled( $this->get_option_name() );
243 }
244
245 /**
246 * Adds extra information under the label
247 *
248 * @return string
249 *
250 * @since 1.8.0
251 */
252 public function get_extra_information() {
253 return '<p>' . esc_html__( 'Excludes cookiebot javascript files when the WP-Rocket deter option is enabled.',
254 'cookiebot-addons' ) . '</p>';;
255 }
256
257 /**
258 * Returns the url of WordPress SVN repository or another link where we can verify the plugin file.
259 *
260 * @return boolean
261 *
262 * @since 1.8.0
263 */
264 public function get_svn_url() {
265 return false;
266 }
267
268 /**
269 * Placeholder helper overlay in the settings page.
270 *
271 * @return string
272 *
273 * @since 1.8.0
274 */
275 public function get_placeholder_helper() {
276 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>';
277 }
278
279
280 /**
281 * Returns parent class or false
282 *
283 * @return string|bool
284 *
285 * @since 2.1.3
286 */
287 public function get_parent_class() {
288 return get_parent_class( $this );
289 }
290
291 /**
292 * Action after enabling the addon on the settings page
293 *
294 * @since 2.2.0
295 */
296 public function post_hook_after_enabling() {
297 //do nothing
298 }
299
300 /**
301 * Cookiebot plugin is deactivated
302 *
303 * @since 2.2.0
304 */
305 public function plugin_deactivated() {
306 //do nothing
307 }
308
309 /**
310 * @return mixed
311 *
312 * @since 2.4.5
313 */
314 public function extra_available_addon_option() {
315 //do nothing
316 }
317
318 /**
319 * Returns boolean to enable/disable plugin by default
320 *
321 * @return bool
322 *
323 * @since 3.6.3
324 */
325 public function enable_by_default() {
326 return true;
327 }
328
329 /**
330 * Sets default settings for this addon
331 *
332 * @return array
333 *
334 * @since 3.6.3
335 */
336 public function get_default_enable_setting() {
337 return array(
338 'enabled' => 1,
339 'cookie_type' => $this->get_default_cookie_types(),
340 'placeholder' => $this->get_default_placeholder(),
341 );
342 }
343 }
344