PluginProbe
Extendify / 3.2.0
Extendify v3.2.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Agent / Integrations / Iubenda.php

Iubenda.php in Extendify 3.2.0, at app/Agent/Integrations/Iubenda.php

85 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * iubenda Integration.
5 */
6
7 namespace Extendify\Agent\Integrations;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 /**
12 * Handles integration with the iubenda plugin.
13 */
14 class Iubenda
15 {
16 /**
17 * The Iubenda plugin slug.
18 *
19 * @var string
20 */
21 public static $slug = 'iubenda-cookie-law-solution/iubenda_cookie_solution.php';
22
23 public function __construct()
24 {
25 if (!self::isActive()) {
26 return;
27 }
28
29 \add_action('wp_print_footer_scripts', [$this, 'fixButtonZIndexScript']);
30 }
31
32 /**
33 * Add a JS script to fix the z-index position of the .iubenda-tp-btn element.
34 *
35 * @return void
36 */
37 public function fixButtonZIndexScript()
38 {
39 ?>
40 <script>
41 document.addEventListener('DOMContentLoaded', function() {
42 const buttonSelector = '.iubenda-tp-btn';
43
44 function applyToButton(button) {
45 button.style.zIndex = 99999; // same value as z-high class
46 }
47
48 const existing = document.querySelector(buttonSelector);
49 if (existing) {
50 applyToButton(existing);
51 return;
52 }
53
54 const observer = new MutationObserver(function(mutations) {
55 const button = document.querySelector(buttonSelector);
56 if (button) {
57 applyToButton(button);
58 observer.disconnect();
59 }
60 });
61
62 observer.observe(document.body, {
63 childList: true,
64 subtree: true
65 });
66 });
67 </script>
68 <?php
69 }
70
71 /**
72 * Check whether the iubenda plugin is active.
73 *
74 * @return bool
75 */
76 public static function isActive()
77 {
78 if (!function_exists('is_plugin_active')) {
79 require_once ABSPATH . 'wp-admin/includes/plugin.php';
80 }
81
82 return \is_plugin_active(self::$slug);
83 }
84 }
85