PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.4.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.4.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 / wpforms / wpforms.php

wpforms.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 3.4.0, at addons/controller/addons/wpforms/wpforms.php

370 lines 8.2 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\wpforms;
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 Wpforms 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( Settings_Service_Interface $settings, Script_Loader_Tag_Interface $script_loader_tag, Cookie_Consent_Interface $cookie_consent, Buffer_Output_Interface $buffer_output ) {
52 $this->settings = $settings;
53 $this->script_loader_tag = $script_loader_tag;
54 $this->cookie_consent = $cookie_consent;
55 $this->buffer_output = $buffer_output;
56 }
57
58 /**
59 * Loads addon configuration
60 *
61 * @since 1.3.0
62 */
63 public function load_configuration() {
64 add_action( 'wp_loaded', array( $this, 'cookiebot_addon_wpforms' ), 5 );
65 }
66
67 /**
68 * Disable scripts if state not accepted
69 *
70 * @since 1.3.0
71 */
72 public function cookiebot_addon_wpforms() {
73 add_filter( 'wpforms_disable_entry_user_ip', array( $this, 'gdpr_consent_is_given' ) );
74 add_action( 'wp_footer', array( $this, 'enqueue_script_for_adding_the_cookie_after_the_consent' ), 18 );
75 }
76
77 /**
78 * Create cookie when the visitor gives consent
79 */
80 public function enqueue_script_for_adding_the_cookie_after_the_consent() {
81 wp_enqueue_script( 'wpforms-gdpr-cookiebot',
82 COOKIEBOT_URL . 'addons/controller/addons/wpforms/cookie-after-consent.js',
83 array( 'jquery' ),
84 '',
85 true );
86 wp_localize_script( 'wpforms-gdpr-cookiebot', 'cookiebot_wpforms_settings', array( 'cookie_types' => $this->get_cookie_types() ) );
87 }
88
89 /**
90 * Retrieve if the cookie consent is given
91 *
92 * @return bool
93 *
94 * @since 2.1.4
95 */
96 public function gdpr_consent_is_given() {
97 if ( $this->cookie_consent->are_cookie_states_accepted( $this->get_cookie_types() ) ) {
98 return true;
99 }
100
101 return false;
102 }
103
104 /**
105 * Return addon/plugin name
106 *
107 * @return string
108 *
109 * @since 1.3.0
110 */
111 public function get_addon_name() {
112 return 'WPForms';
113 }
114
115 /**
116 * Default placeholder content
117 *
118 * @return string
119 *
120 * @since 1.8.0
121 */
122 public function get_default_placeholder() {
123 return 'Please accept [renew_consent]%cookie_types[/renew_consent] cookies to enable saving user information.';
124 }
125
126 /**
127 * Get placeholder content
128 *
129 * This function will check following features:
130 * - Current language
131 *
132 * @param $src
133 *
134 * @return bool|mixed
135 *
136 * @since 1.8.0
137 */
138 public function get_placeholder( $src = '' ) {
139 return $this->settings->get_placeholder( $this->get_option_name(), $this->get_default_placeholder(), cookiebot_addons_output_cookie_types( $this->get_cookie_types() ), $src );
140 }
141
142 /**
143 * Option name in the database
144 *
145 * @return string
146 *
147 * @since 1.3.0
148 */
149 public function get_option_name() {
150 return 'wpforms';
151 }
152
153 /**
154 * Plugin file name
155 *
156 * @return string
157 *
158 * @since 1.3.0
159 */
160 public function get_plugin_file() {
161 return 'wpforms/wpforms.php';
162 }
163
164 /**
165 * Returns checked cookie types
166 * @return mixed
167 *
168 * @since 1.3.0
169 */
170 public function get_cookie_types() {
171 return $this->settings->get_cookie_types( $this->get_option_name(), $this->get_default_cookie_types() );
172 }
173
174 /**
175 * Returns default cookie types
176 * @return array
177 *
178 * @since 1.5.0
179 */
180 public function get_default_cookie_types() {
181 return array( 'preferences' );
182 }
183
184 /**
185 * Check if plugin is activated and checked in the backend
186 *
187 * @since 1.3.0
188 */
189 public function is_addon_enabled() {
190 return $this->settings->is_addon_enabled( $this->get_option_name() );
191 }
192
193 /**
194 * Checks if addon is installed
195 *
196 * @since 1.3.0
197 */
198 public function is_addon_installed() {
199 $installed = $this->settings->is_addon_installed( $this->get_plugin_file() );
200
201 if ( $installed && version_compare( $this->get_addon_version(), '1.5.1', '<' ) ) {
202 $installed = false;
203 }
204
205 return $installed;
206 }
207
208 /**
209 * Checks if addon is activated
210 *
211 * @since 1.3.0
212 */
213 public function is_addon_activated() {
214 return $this->settings->is_addon_activated( $this->get_plugin_file() );
215 }
216
217 /**
218 * Retrieves current installed version of the addon
219 *
220 * @return bool
221 *
222 * @since 2.2.1
223 */
224 public function get_addon_version() {
225 return $this->settings->get_addon_version( $this->get_plugin_file() );
226 }
227
228 /**
229 * Checks if it does have custom placeholder content
230 *
231 * @return mixed
232 *
233 * @since 1.8.0
234 */
235 public function has_placeholder() {
236 return $this->settings->has_placeholder( $this->get_option_name() );
237 }
238
239 /**
240 * returns all placeholder contents
241 *
242 * @return mixed
243 *
244 * @since 1.8.0
245 */
246 public function get_placeholders() {
247 return $this->settings->get_placeholders( $this->get_option_name() );
248 }
249
250 /**
251 * Return true if the placeholder is enabled
252 *
253 * @return mixed
254 *
255 * @since 1.8.0
256 */
257 public function is_placeholder_enabled() {
258 return $this->settings->is_placeholder_enabled( $this->get_option_name() );
259 }
260
261 /**
262 * Adds extra information under the label
263 *
264 * @return string
265 *
266 * @since 1.8.0
267 */
268 public function get_extra_information() {
269 return '<p>' .
270 __( 'If the user gives correct consent, IP and Unique User ID will be saved on form submissions, otherwise not.', 'cookiebot-addons' ) .
271 '<br />' .
272 __( 'Increases opt-in rate compared to WPForms "GDPR mode".', 'cookiebot-addons' ) .
273 '</p>';
274 }
275
276 /**
277 * Returns the url of WordPress SVN repository or another link where we can verify the plugin file.
278 *
279 * @return string
280 *
281 * @since 1.8.0
282 */
283 public function get_svn_url() {
284 return false;
285 }
286
287 /**
288 * Placeholder helper overlay in the settings page.
289 *
290 * @return string
291 *
292 * @since 1.8.0
293 */
294 public function get_placeholder_helper() {
295 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>';
296 }
297
298 /**
299 * Returns parent class or false
300 *
301 * @return string|bool
302 *
303 * @since 2.1.3
304 */
305 public function get_parent_class() {
306 return get_parent_class( $this );
307 }
308
309 /**
310 * Action after enabling the addon on the settings page
311 *
312 * Clear gdpr settings in the wpforms
313 *
314 * @since 2.2.0
315 */
316 public function post_hook_after_enabling() {
317 $wpforms_settings = get_option( 'wpforms_settings' );
318
319 $wpforms_settings['gdpr'] = false;
320 $wpforms_settings['gdpr-disable-uuid'] = false;
321 $wpforms_settings['gdpr-disable-details'] = false;
322
323 update_option( 'wpforms_settings', $wpforms_settings );
324 }
325
326 /**
327 * Cookiebot plugin is deactivated
328 *
329 * @since 2.2.0
330 */
331 public function plugin_deactivated() {
332 // if the checkbox was checked and the cookiebot plugin is deactivated
333 // remove the setting so the default gdpr checkboxes are still visible
334 $this->wpforms_set_setting( 'gdpr-cookiebot', false );
335 }
336
337 /**
338 * Set the value of a specific WPForms setting.
339 *
340 * @since 1.5.0.4
341 *
342 * @param string $key
343 * @param mixed $new_value
344 * @param string $option
345 *
346 * @return mixed
347 */
348 public function wpforms_set_setting( $key, $new_value, $option = 'wpforms_settings' ) {
349
350 $key = wpforms_sanitize_key( $key );
351 $options = get_option( $option, false );
352 $option_value = is_array( $options ) && ! empty( $options[ $key ] ) ? $options[ $key ] : false;
353
354 if ( $new_value !== $option_value ) {
355 $options[ $key ] = $new_value;
356 }
357
358 update_option( $option, $options );
359 }
360
361 /**
362 * @return mixed
363 *
364 * @since 2.4.5
365 */
366 public function extra_available_addon_option() {
367 //do nothing
368 }
369 }
370