PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.0.2
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.0.2
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 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 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.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 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.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / addons / controller / plugin-controller.php
cookiebot / addons / controller Last commit date
addons 4 years ago plugin-controller.php 4 years ago
plugin-controller.php
130 lines
1 <?php
2
3 namespace cookiebot_addons\controller;
4
5 use cookiebot_addons\controller\addons\Cookiebot_Addons_Interface;
6 use cookiebot_addons\lib\buffer\Buffer_Output_Interface;
7 use cookiebot_addons\lib\Settings_Service_Interface;
8 use Cookiebot_WP;
9 use Cybot\Dependencies\DI;
10 use Exception;
11
12 /**
13 * Class Plugin_Controller
14 * @package cookiebot_addons\controller
15 */
16 class Plugin_Controller {
17
18 /**
19 * IoC container - Dependency Injection
20 *
21 * @var Settings_Service_Interface
22 *
23 * @since 1.1.0
24 */
25 private $settings_service;
26
27 /**
28 * Plugin_Controller constructor.
29 *
30 * @param $settings_service Settings_Service_Interface IoC Container
31 *
32 * @since 1.2.0
33 */
34 public function __construct( Settings_Service_Interface $settings_service ) {
35 $this->settings_service = $settings_service;
36 $this->load_init_files();
37 }
38
39 /**
40 * Load init files to use 'validate_plugin' and 'is_plugin_active'
41 *
42 * @since 1.3.0
43 */
44 protected function load_init_files() {
45 if ( ! function_exists( 'is_plugin_active' ) ) {
46 require_once ABSPATH . '/wp-admin/includes/plugin.php';
47 require_once ABSPATH . '/wp-includes/l10n.php';
48 require_once ABSPATH . '/wp-admin/includes/translation-install.php';
49 }
50 }
51
52 /**
53 * Load addon configuration if the plugin is activated
54 *
55 * @throws Exception
56 * @since 1.2.0
57 * @version 1.3.0
58 */
59 public function load_active_addons() {
60 /**
61 * Check if Cookiebot is activated and active. Return if cookiebot is inactive
62 */
63 if ( ! function_exists( 'cookiebot_active' ) || ! cookiebot_active() ) {
64 return;
65 }
66
67 if ( Cookiebot_WP::cookiebot_disabled_in_admin() === true && is_admin() ) {
68 return;
69 }
70
71 /**
72 * Check plugins one by one and load configuration if it is active
73 *
74 * @var $plugin Cookiebot_Addons_Interface
75 */
76 $addons_enabled_counter = 0;
77 foreach ( $this->settings_service->get_active_addons() as $plugin ) {
78 if ( ! $plugin->cookie_consent->are_cookie_states_accepted( $plugin->get_cookie_types() )
79 || cookiebot_addons_enabled_cache_plugin() ) {
80 $plugin->load_configuration();
81 $addons_enabled_counter++;
82 }
83 }
84
85 /**
86 * After WordPress is fully loaded
87 *
88 * Run buffer output actions - this runs after scanning of every addons
89 */
90 add_action( 'parse_request', array( $this, 'run_buffer_output_manipulations' ) );
91
92 /**
93 * Add notice for the user if any addons is enabled and cookie
94 * blocking mode is set to auto.
95 */
96 if ( $addons_enabled_counter > 0 && Cookiebot_WP::get_cookie_blocking_mode() === 'auto' ) {
97 //phpcs:ignore WordPress.Security.NonceVerification.Recommended
98 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'cookiebot', 'cookiebot-addons' ), true ) ) {
99 add_action(
100 'admin_notices',
101 function() {
102 echo '<div class="notice notice-warning">
103 <p>
104 <strong>' . esc_html__( 'You enabled Cookiebot auto blocking mode but still using addons' ) . '</strong><br>
105 ' . esc_html__( 'In some occasions this may cause client side errors. If you notice any errors please try to disable Cookiebot addons or contact Cookiebot support.' ) . '
106 </p>
107 </div>';
108 }
109 );
110 }
111 }
112 }
113
114 /**
115 * Runs every added action hooks to manipulate script tag
116 *
117 * @since 1.3.0
118 */
119 public function run_buffer_output_manipulations() {
120 /**
121 * @var $buffer_output Buffer_Output_Interface
122 */
123 $buffer_output = $this->settings_service->container->get( 'Buffer_Output_Interface' );
124
125 if ( $buffer_output->has_action() ) {
126 $buffer_output->run_actions();
127 }
128 }
129 }
130