PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / trunk
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode vtrunk
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 / src / abilities / Toggle_Gcm_Ability.php
cookiebot / src / abilities Last commit date
Ability_Audit_Logger.php 1 month ago Cookiebot_Abilities_Registrar.php 1 month ago Cookiebot_Ability_Interface.php 1 month ago Get_Compliance_Summary_Ability.php 1 month ago Get_Status_Ability.php 1 month ago Install_Ppg_Ability.php 1 month ago Set_Cbid_Ability.php 1 month ago Toggle_Gcm_Ability.php 1 month ago Verify_Setup_Ability.php 1 month ago
Toggle_Gcm_Ability.php
102 lines
1 <?php
2 /**
3 * Toggle_Gcm_Ability class.
4 *
5 * @package cookiebot
6 * @subpackage abilities
7 */
8
9 namespace cybot\cookiebot\abilities;
10
11 /**
12 * Ability to toggle Google Consent Mode v2.
13 *
14 * @since 4.8.0
15 */
16 class Toggle_Gcm_Ability implements Cookiebot_Ability_Interface {
17
18 /**
19 * Audit logger instance.
20 *
21 * @var Ability_Audit_Logger
22 */
23 private $logger;
24
25 /**
26 * Constructor.
27 *
28 * @param Ability_Audit_Logger $logger Audit logger instance.
29 *
30 * @since 4.8.0
31 */
32 public function __construct( Ability_Audit_Logger $logger ) {
33 $this->logger = $logger;
34 }
35
36 /**
37 * Returns the ability name.
38 *
39 * @return string
40 *
41 * @since 4.8.0
42 */
43 public function get_name() {
44 return 'cookiebot/toggle-gcm';
45 }
46
47 /**
48 * Returns the ability arguments.
49 *
50 * @return array
51 *
52 * @since 4.8.0
53 */
54 public function get_args() {
55 $logger = $this->logger;
56
57 return array(
58 'label' => __( 'Toggle Google Consent Mode v2', 'cookiebot' ),
59 'description' => __( 'Enables or disables Google Consent Mode v2. GCM v2 is required for Google Ads and Analytics in the EU/EEA and is enabled by default. Only disable if explicitly requested by the user.', 'cookiebot' ),
60 'category' => 'cookiebot',
61 'input_schema' => array(
62 'type' => 'object',
63 'properties' => array(
64 'enabled' => array(
65 'type' => 'boolean',
66 'description' => __( 'True to enable Google Consent Mode v2, false to disable.', 'cookiebot' ),
67 ),
68 ),
69 'required' => array( 'enabled' ),
70 'additionalProperties' => false,
71 ),
72 'output_schema' => array(
73 'type' => 'object',
74 'properties' => array(
75 'old_value' => array( 'type' => 'boolean', 'description' => 'Previous GCM enabled state.' ),
76 'new_value' => array( 'type' => 'boolean', 'description' => 'New GCM enabled state.' ),
77 'success' => array( 'type' => 'boolean', 'description' => 'Whether the update succeeded.' ),
78 ),
79 'additionalProperties' => false,
80 ),
81 'execute_callback' => function( $input ) use ( $logger ) {
82 $enabled = isset( $input['enabled'] ) ? (bool) $input['enabled'] : true;
83 $old_value = get_option( 'cookiebot-gcm', '1' ) === '1';
84 update_option( 'cookiebot-gcm', $enabled ? '1' : '0' );
85 $logger->log( 'cookiebot/toggle-gcm', $old_value, $enabled );
86 return array(
87 'old_value' => $old_value,
88 'new_value' => $enabled,
89 'success' => true,
90 );
91 },
92 'permission_callback' => function() {
93 return current_user_can( 'manage_options' );
94 },
95 'meta' => array(
96 'annotations' => array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ),
97 'show_in_rest' => true,
98 ),
99 );
100 }
101 }
102