PluginProbe ʕ •ᴥ•ʔ
GDPR Cookie Compliance – Cookie Banner, Cookie Consent, Cookie Notice for CCPA, EU Cookie Law / 4.9.1
GDPR Cookie Compliance – Cookie Banner, Cookie Consent, Cookie Notice for CCPA, EU Cookie Law v4.9.1
5.0.14 5.0.13 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.10.0 4.10.1 4.10.2 4.10.3 4.10.4 4.10.5 4.10.6 4.11.0 4.11.1 4.11.2 4.12.0 4.12.1 4.12.2 4.12.3 4.12.4 4.12.5 4.12.6 4.12.7 4.12.8 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.15.0 4.15.1 4.15.10 4.15.2 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.1 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.5.0 4.5.1 4.5.10 4.5.11 4.5.12 4.5.13 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.8.0 4.8.1 4.8.10 4.8.11 4.8.12 4.8.13 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 5.0.0 5.0.1 5.0.10 5.0.11 5.0.12 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2
gdpr-cookie-compliance / gdpr-functions.php
gdpr-cookie-compliance Last commit date
controllers 3 years ago dist 3 years ago gdpr-modules 3 years ago languages 3 years ago views 3 years ago class-gdpr-modules-view.php 3 years ago class-gdpr-modules.php 3 years ago class-gdpr-view.php 3 years ago class-moove-gdpr-actions.php 3 years ago class-moove-gdpr-content.php 3 years ago class-moove-gdpr-options.php 3 years ago gdpr-functions.php 3 years ago moove-gdpr.php 3 years ago readme.txt 3 years ago
gdpr-functions.php
536 lines
1 <?php
2 /**
3 * Moove_Functions File Doc Comment
4 *
5 * @category Moove_Functions
6 * @package gdpr-cookie-compliance
7 * @author Moove Agency
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 } // Exit if accessed directly
13
14 if ( ! function_exists( 'moove_gdpr_get_plugin_directory_url' ) ) :
15 /**
16 * Relative path of the GDPR cookie plugin
17 */
18 function moove_gdpr_get_plugin_directory_url() {
19 return plugin_dir_url( __FILE__ );
20 }
21 endif;
22
23 if ( ! function_exists( 'gdpr_get_site_id' ) ) :
24 /**
25 * Returns the current blog id as site_id
26 */
27 function gdpr_get_site_id() {
28 return function_exists( 'get_current_blog_id' ) ? get_current_blog_id() : 1;
29 }
30 endif;
31
32
33 if ( ! function_exists( 'gdpr_get_field' ) ) :
34 /**
35 * Get simple value from gdpr database by option_key
36 */
37 function gdpr_get_field( $option_key = false, $site_id = false ) {
38 $results = false;
39 if ( $option_key ) :
40 $site_id = $site_id && intval( $site_id ) ? $site_id : gdpr_get_site_id();
41 $database_controller = new Moove_GDPR_DB_Controller();
42 $results = $database_controller->get( $option_key, $site_id );
43 $results = $results && isset( $results->option_value ) ? maybe_unserialize( $results->option_value ) : false;
44 endif;
45 return $results;
46 }
47
48 endif;
49
50 if ( ! function_exists( 'gdpr_get_options' ) ) :
51 /**
52 * Get simple value from gdpr database by option_key
53 */
54 function gdpr_get_options( $site_id = false ) {
55 $site_id = $site_id && intval( $site_id ) ? $site_id : gdpr_get_site_id();
56 $database_controller = new Moove_GDPR_DB_Controller();
57 $results = $database_controller->get_options( $site_id );
58 $results_filtered = array();
59 if ( is_array( $results ) && ! empty( $results ) ) :
60 foreach ( $results as $key => $value ) :
61 $results_filtered[$key] = maybe_unserialize( $value->option_value );
62 endforeach;
63 endif;
64 $results_filtered = $results_filtered && ! empty( $results_filtered ) ? $results_filtered : false;
65 return $results_filtered;
66 }
67
68 endif;
69
70 if ( ! function_exists( 'gdpr_update_field' ) ) :
71 /**
72 * Get simple value from gdpr database by option_key
73 */
74 function gdpr_update_field( $option_key = false, $option_value = false, $site_id = false ) {
75 $results = false;
76 if ( $option_key ) :
77 $site_id = $site_id && intval( $site_id ) ? $site_id : gdpr_get_site_id();
78 $database_controller = new Moove_GDPR_DB_Controller();
79 $results = $database_controller->update(
80 array(
81 'option_key' => $option_key,
82 'option_value' => maybe_serialize( $option_value ),
83 'site_id' => $site_id
84 )
85 );
86 endif;
87 return $results;
88 }
89
90 endif;
91
92 if ( ! function_exists( 'gdpr_delete_option' ) ) :
93 /**
94 * Get simple value from gdpr database by option_key
95 */
96 function gdpr_delete_option() {
97 $database_controller = new Moove_GDPR_DB_Controller();
98 $results = $database_controller->delete_option();
99 return $results;
100 }
101
102 endif;
103
104
105
106 add_filter( 'plugin_action_links', 'moove_gdpr_plugin_settings_link', 10, 2 );
107 /**
108 * Extension to display support, premium and settings links in the plugin listing page
109 *
110 * @param array $links Links.
111 * @param string $file File.
112 */
113 function moove_gdpr_plugin_settings_link( $links, $file ) {
114 if ( plugin_basename( dirname( __FILE__ ) . '/moove-gdpr.php' ) === $file ) {
115 /*
116 * Insert the Settings page link at the beginning
117 */
118 $in = '<a href="'.esc_url( admin_url( 'admin.php' ) ).'?page=moove-gdpr" target="_blank">' . __( 'Settings', 'gdpr-cookie-compliance' ) . '</a>';
119 array_unshift( $links, $in );
120
121 /*
122 * Insert the Support page link at the end
123 */
124 $in = '<a href="https://support.mooveagency.com/forum/gdpr-cookie-compliance/" target="_blank">' . __( 'Support', 'gdpr-cookie-compliance' ) . '</a>';
125 array_push( $links, $in );
126
127 /*
128 * Insert the Premium Upgrade link at the end
129 */
130 if ( ! function_exists( 'moove_gdpr_addon_get_plugin_dir' ) ) :
131 $in = '<a href="https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/" class="gdpr_admin_link gdpr_premium_buy_link" target="_blank">' . __( 'Buy Premium', 'gdpr-cookie-compliance' ) . '</a>';
132 array_push( $links, $in );
133 endif;
134 }
135 return $links;
136 }
137
138 /**
139 * Get an attachment ID given a URL.
140 *
141 * @param string $url URL.
142 * @return int Attachment ID on success, 0 on failure
143 */
144 function gdpr_get_attachment_id( $url ) {
145 $attachment_id = 0;
146 $dir = wp_upload_dir();
147 if ( false !== strpos( $url, $dir['baseurl'] . '/' ) ) { // Is URL in uploads directory?
148 $file = basename( $url );
149 $query_args = array(
150 'post_type' => 'attachment',
151 'post_status' => 'inherit',
152 'fields' => 'ids',
153 'meta_query' => array(
154 array(
155 'value' => $file,
156 'compare' => 'LIKE',
157 'key' => '_wp_attachment_metadata',
158 ),
159 ),
160 );
161 $query = new WP_Query( $query_args );
162 if ( $query->have_posts() ) {
163 while ( $query->have_posts() ) :
164 $query->the_post();
165 $post_id = get_the_ID();
166 $meta = wp_get_attachment_metadata( $post_id );
167 if ( $meta && isset( $meta['file'] ) && isset( $meta['sizes'] ) ) :
168 $original_file = basename( $meta['file'] );
169 $cropped_image_files = wp_list_pluck( $meta['sizes'], 'file' );
170 if ( $original_file === $file || in_array( $file, $cropped_image_files, false ) ) {
171 $attachment_id = $post_id;
172 break;
173 }
174 endif;
175 endwhile;
176 wp_reset_postdata();
177 }
178 }
179 return $attachment_id;
180 }
181
182 /**
183 * Get image alt text by image URL or ID
184 *
185 * @param String $image_url Image URL or ID.
186 *
187 * @return Bool | String
188 */
189 function gdpr_get_logo_alt( $image_url, $options = array() ) {
190 if ( isset( $options['moove_gdpr_company_logo_id'] ) && intval( $options['moove_gdpr_company_logo_id'] ) ) :
191 $image_alt = get_post_meta( $options['moove_gdpr_company_logo_id'], '_wp_attachment_image_alt', true );
192 else :
193 $image_alt = get_bloginfo( 'name' );
194 endif;
195 return apply_filters( 'gdpr_cc_custom_logo_alt', $image_alt, $image_url );
196 }
197
198 /**
199 * Get image widht & height by image URL
200 *
201 * @param string $image_url Image URL
202 */
203 function gdpr_get_logo_details( $image_url, $options = array() ) {
204 $image_details = array(
205 'width' => false,
206 'height' => false,
207 );
208 $image_size = apply_filters('gdpr_cc_company_logo_image_size', 'medium');
209 if ( $image_url && apply_filters( 'gdpr_cc_logo_details_enabled', true ) ) :
210
211 if ( strpos( $image_url, 'gdpr-cookie-compliance/dist/images/gdpr-logo.png' ) !== false ) :
212 $image_details = array(
213 'width' => 350,
214 'height' => 233,
215 );
216 else :
217 if ( isset( $options['moove_gdpr_company_logo_id'] ) && intval( $options['moove_gdpr_company_logo_id'] ) ) :
218 $attachment_id = intval( $options['moove_gdpr_company_logo_id'] );
219 else :
220 $attachment_id = attachment_url_to_postid( $image_url );
221 endif;
222 if ( $attachment_id ) :
223 $_image = wp_get_attachment_image_src( $attachment_id, $image_size );
224 if ( ! isset( $options['moove_gdpr_company_logo_id'] ) ) :
225 $gdpr_default_content = new Moove_GDPR_Content();
226 $option_name = $gdpr_default_content->moove_gdpr_get_option_name();
227 $gdpr_options = get_option( $option_name );
228 $gdpr_options['moove_gdpr_company_logo_id'] = $attachment_id;
229 update_option( $option_name, $gdpr_options );
230 endif;
231 if ( $_image ) :
232 $image_details = array(
233 'logo_url' => $_image[0],
234 'width' => $_image[1],
235 'height' => $_image[2],
236 );
237 endif;
238 endif;
239 endif;
240 endif;
241 $image_details = apply_filters( 'gdpr_cc_logo_details_filter', $image_details );
242 return $image_details;
243 }
244
245 /**
246 * GDPR Module manager, introduced in version 1.1.5
247 *
248 * @param string $module Module.
249 */
250 function gdpr_get_module( $module = '' ) {
251 if ( $module ) :
252 $module_controller = new GDPR_Modules();
253 $response = false;
254 switch ( $module ) :
255 case 'floating-button':
256 $response = apply_filters( 'gdpr_floating_button_module', $module_controller->get_floating_button() );
257 break;
258 case 'infobar-base':
259 $response = apply_filters( 'gdpr_infobar_base_module', $module_controller->get_infobar_base() );
260 break;
261 case 'infobar-content':
262 $response = apply_filters( 'gdpr_infobar_content_module', $module_controller->get_infobar_content() );
263 break;
264 case 'infobar-buttons':
265 $response = apply_filters( 'gdpr_infobar_buttons_module', $module_controller->get_infobar_buttons() );
266 break;
267 case 'company-logo':
268 $response = apply_filters( 'gdpr_company_logo_module', $module_controller->get_company_logo() );
269 break;
270 case 'gdpr-branding':
271 $response = apply_filters( 'gdpr_branding_module', $module_controller->get_gdpr_branding() );
272 break;
273 case 'modal-base':
274 $response = apply_filters( 'gdpr_modal_base_module', $module_controller->get_modal_base() );
275 break;
276 case 'tab-navigation':
277 $response = apply_filters( 'gdpr_tab_navigation_module', $module_controller->get_tab_navigation() );
278 break;
279 case 'modal-footer-buttons':
280 $response = apply_filters( 'gdpr_modal_footer_buttons_module', $module_controller->get_tab_footer_buttons() );
281 break;
282 case 'section-overview':
283 $response = apply_filters( 'gdpr_section_overview_module', $module_controller->get_section_overview() );
284 break;
285 case 'section-strictly':
286 $response = apply_filters( 'gdpr_section_strictly_module', $module_controller->get_section_strictly() );
287 break;
288 case 'section-advanced':
289 $response = apply_filters( 'gdpr_section_advanced_module', $module_controller->get_section_advanced() );
290 break;
291 case 'section-third_party':
292 $response = apply_filters( 'gdpr_section_third_party_module', $module_controller->get_section_third_party() );
293 break;
294 case 'section-cookiepolicy':
295 $response = apply_filters( 'gdpr_section_cookiepolicy_module', $module_controller->get_section_cookiepolicy() );
296 break;
297 case 'branding-styles':
298 $response = apply_filters( 'gdpr_branding_styles_module', $module_controller->get_branding_styles() );
299 break;
300 default:
301 endswitch;
302 endif;
303 return $response;
304 }
305
306
307 if ( ! function_exists( 'gdpr_cookie_is_accepted' ) ) :
308 /**
309 * Checking accepted cookie values by type
310 *
311 * @param string $type Type.
312 */
313 function gdpr_cookie_is_accepted( $type = '' ) {
314 $response = false;
315 $type = sanitize_text_field( $type );
316 $accepted_types = array( 'strict', 'thirdparty', 'advanced' );
317 if ( $type && in_array( $type, $accepted_types ) ) :
318 $gdpr_content = new Moove_GDPR_Content();
319 $php_cookies = $gdpr_content->gdpr_get_php_cookies();
320 $response = $php_cookies && isset( $php_cookies[ $type ] ) && $php_cookies[ $type ] ? true : false;
321 endif;
322 return $response;
323 }
324 endif;
325
326 if ( ! function_exists( 'gdpr_get_display_language_by_locale' ) ) :
327 /**
328 * Language locale
329 *
330 * @param string $locale Locale.
331 */
332 function gdpr_get_display_language_by_locale( $locale ) {
333 $locale_lang = explode( '-', $locale );
334 $_locale = isset( $locale_lang[0] ) ? $locale_lang[0] : $locale;
335 $language_codes = array(
336 'aa' => 'Afar',
337 'ab' => 'Abkhazian',
338 'ae' => 'Avestan',
339 'af' => 'Afrikaans',
340 'ak' => 'Akan',
341 'am' => 'Amharic',
342 'an' => 'Aragonese',
343 'ar' => 'Arabic',
344 'as' => 'Assamese',
345 'av' => 'Avaric',
346 'ay' => 'Aymara',
347 'az' => 'Azerbaijani',
348 'ba' => 'Bashkir',
349 'be' => 'Belarusian',
350 'bg' => 'Bulgarian',
351 'bh' => 'Bihari',
352 'bi' => 'Bislama',
353 'bm' => 'Bambara',
354 'bn' => 'Bengali',
355 'bo' => 'Tibetan',
356 'br' => 'Breton',
357 'bs' => 'Bosnian',
358 'ca' => 'Catalan',
359 'ce' => 'Chechen',
360 'ch' => 'Chamorro',
361 'co' => 'Corsican',
362 'cr' => 'Cree',
363 'cs' => 'Czech',
364 'cu' => 'Church Slavic',
365 'cv' => 'Chuvash',
366 'cy' => 'Welsh',
367 'da' => 'Danish',
368 'de' => 'German',
369 'dv' => 'Divehi',
370 'dz' => 'Dzongkha',
371 'ee' => 'Ewe',
372 'el' => 'Greek',
373 'en' => 'English',
374 'eo' => 'Esperanto',
375 'es' => 'Spanish',
376 'et' => 'Estonian',
377 'eu' => 'Basque',
378 'fa' => 'Persian',
379 'ff' => 'Fulah',
380 'fi' => 'Finnish',
381 'fj' => 'Fijian',
382 'fo' => 'Faroese',
383 'fr' => 'French',
384 'fy' => 'Western Frisian',
385 'ga' => 'Irish',
386 'gd' => 'Scottish Gaelic',
387 'gl' => 'Galician',
388 'gn' => 'Guarani',
389 'gu' => 'Gujarati',
390 'gv' => 'Manx',
391 'ha' => 'Hausa',
392 'he' => 'Hebrew',
393 'hi' => 'Hindi',
394 'ho' => 'Hiri Motu',
395 'hr' => 'Croatian',
396 'ht' => 'Haitian',
397 'hu' => 'Hungarian',
398 'hy' => 'Armenian',
399 'hz' => 'Herero',
400 'ia' => 'Interlingua (International Auxiliary Language Association)',
401 'id' => 'Indonesian',
402 'ie' => 'Interlingue',
403 'ig' => 'Igbo',
404 'ii' => 'Sichuan Yi',
405 'ik' => 'Inupiaq',
406 'io' => 'Ido',
407 'is' => 'Icelandic',
408 'it' => 'Italian',
409 'iu' => 'Inuktitut',
410 'ja' => 'Japanese',
411 'jv' => 'Javanese',
412 'ka' => 'Georgian',
413 'kg' => 'Kongo',
414 'ki' => 'Kikuyu',
415 'kj' => 'Kwanyama',
416 'kk' => 'Kazakh',
417 'kl' => 'Kalaallisut',
418 'km' => 'Khmer',
419 'kn' => 'Kannada',
420 'ko' => 'Korean',
421 'kr' => 'Kanuri',
422 'ks' => 'Kashmiri',
423 'ku' => 'Kurdish',
424 'kv' => 'Komi',
425 'kw' => 'Cornish',
426 'ky' => 'Kirghiz',
427 'la' => 'Latin',
428 'lb' => 'Luxembourgish',
429 'lg' => 'Ganda',
430 'li' => 'Limburgish',
431 'ln' => 'Lingala',
432 'lo' => 'Lao',
433 'lt' => 'Lithuanian',
434 'lu' => 'Luba-Katanga',
435 'lv' => 'Latvian',
436 'mg' => 'Malagasy',
437 'mh' => 'Marshallese',
438 'mi' => 'Maori',
439 'mk' => 'Macedonian',
440 'ml' => 'Malayalam',
441 'mn' => 'Mongolian',
442 'mr' => 'Marathi',
443 'ms' => 'Malay',
444 'mt' => 'Maltese',
445 'my' => 'Burmese',
446 'na' => 'Nauru',
447 'nb' => 'Norwegian Bokmal',
448 'nd' => 'North Ndebele',
449 'ne' => 'Nepali',
450 'ng' => 'Ndonga',
451 'nl' => 'Dutch',
452 'nn' => 'Norwegian Nynorsk',
453 'no' => 'Norwegian',
454 'nr' => 'South Ndebele',
455 'nv' => 'Navajo',
456 'ny' => 'Chichewa',
457 'oc' => 'Occitan',
458 'oj' => 'Ojibwa',
459 'om' => 'Oromo',
460 'or' => 'Oriya',
461 'os' => 'Ossetian',
462 'pa' => 'Panjabi',
463 'pi' => 'Pali',
464 'pl' => 'Polish',
465 'ps' => 'Pashto',
466 'pt' => 'Portuguese',
467 'qu' => 'Quechua',
468 'rm' => 'Raeto-Romance',
469 'rn' => 'Kirundi',
470 'ro' => 'Romanian',
471 'ru' => 'Russian',
472 'rw' => 'Kinyarwanda',
473 'sa' => 'Sanskrit',
474 'sc' => 'Sardinian',
475 'sd' => 'Sindhi',
476 'se' => 'Northern Sami',
477 'sg' => 'Sango',
478 'si' => 'Sinhala',
479 'sk' => 'Slovak',
480 'sl' => 'Slovenian',
481 'sm' => 'Samoan',
482 'sn' => 'Shona',
483 'so' => 'Somali',
484 'sq' => 'Albanian',
485 'sr' => 'Serbian',
486 'ss' => 'Swati',
487 'st' => 'Southern Sotho',
488 'su' => 'Sundanese',
489 'sv' => 'Swedish',
490 'sw' => 'Swahili',
491 'ta' => 'Tamil',
492 'te' => 'Telugu',
493 'tg' => 'Tajik',
494 'th' => 'Thai',
495 'ti' => 'Tigrinya',
496 'tk' => 'Turkmen',
497 'tl' => 'Tagalog',
498 'tn' => 'Tswana',
499 'to' => 'Tonga',
500 'tr' => 'Turkish',
501 'ts' => 'Tsonga',
502 'tt' => 'Tatar',
503 'tw' => 'Twi',
504 'ty' => 'Tahitian',
505 'ug' => 'Uighur',
506 'uk' => 'Ukrainian',
507 'ur' => 'Urdu',
508 'uz' => 'Uzbek',
509 've' => 'Venda',
510 'vi' => 'Vietnamese',
511 'vo' => 'Volapuk',
512 'wa' => 'Walloon',
513 'wo' => 'Wolof',
514 'xh' => 'Xhosa',
515 'yi' => 'Yiddish',
516 'yo' => 'Yoruba',
517 'za' => 'Zhuang',
518 'zh' => 'Chinese',
519 'zu' => 'Zulu',
520 );
521 return isset( $language_codes[ $_locale ] ) ? $language_codes[ $_locale ] . ' [' . $locale . ']' : $locale;
522 }
523 endif;
524
525 add_action( 'gdpr_modal_base_module', 'gdpr_copyscape_cc_remove_hidden_elements', 10, 1 );
526 add_action( 'gdpr_infobar_base_module', 'gdpr_copyscape_cc_remove_hidden_elements', 10, 1 );
527 add_action( 'gdpr_branding_styles_module', 'gdpr_copyscape_cc_remove_hidden_elements', 10, 1 );
528 add_action( 'gdpr_floating_button_module', 'gdpr_copyscape_cc_remove_hidden_elements', 10, 1 );
529
530 /**
531 * Disable showing HTML content if ?justtext=1 query parameter is part of the URL
532 * @param string $modal_html Modal HTML.
533 */
534 function gdpr_copyscape_cc_remove_hidden_elements( $modal_html ) {
535 return isset( $_GET['justtext'] ) && sanitize_text_field( wp_unslash( $_GET['justtext'] ) ) ? '' : $modal_html;
536 };