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 / Set_Cbid_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
Set_Cbid_Ability.php
130 lines
1 <?php
2 /**
3 * Set_Cbid_Ability class.
4 *
5 * @package cookiebot
6 * @subpackage abilities
7 */
8
9 namespace cybot\cookiebot\abilities;
10
11 use cybot\cookiebot\lib\Cookiebot_WP;
12
13 /**
14 * Ability to set the Cookiebot Domain Group ID.
15 *
16 * @since 4.8.0
17 */
18 class Set_Cbid_Ability implements Cookiebot_Ability_Interface {
19
20 const CBID_PATTERN = '^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|[a-zA-Z0-9]{9}|[a-zA-Z0-9]{14})$';
21
22 /**
23 * Audit logger instance.
24 *
25 * @var Ability_Audit_Logger
26 */
27 private $logger;
28
29 /**
30 * Constructor.
31 *
32 * @param Ability_Audit_Logger $logger Audit logger instance.
33 *
34 * @since 4.8.0
35 */
36 public function __construct( Ability_Audit_Logger $logger ) {
37 $this->logger = $logger;
38 }
39
40 /**
41 * Returns the ability name.
42 *
43 * @return string
44 *
45 * @since 4.8.0
46 */
47 public function get_name() {
48 return 'cookiebot/set-cbid';
49 }
50
51 /**
52 * Returns the ability arguments.
53 *
54 * @return array
55 *
56 * @since 4.8.0
57 */
58 public function get_args() {
59 $logger = $this->logger;
60
61 return array(
62 'label' => __( 'Set Domain Group ID', 'cookiebot' ),
63 'description' => __( 'Sets the Domain Group ID (CBID). For Cookiebot accounts this is a UUID (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) found under Implementation in the Cookiebot Admin. For Usercentrics accounts this is a Settings ID (9 or 14 characters) found in the Usercentrics Admin. Changes take effect immediately.', 'cookiebot' ),
64 'category' => 'cookiebot',
65 'input_schema' => array(
66 'type' => 'object',
67 'properties' => array(
68 'cbid' => array(
69 'type' => 'string',
70 'pattern' => self::CBID_PATTERN,
71 'description' => __( 'The Domain Group ID: a UUID for Cookiebot accounts (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) or a Settings ID for Usercentrics accounts (9 or 14 alphanumeric characters).', 'cookiebot' ),
72 ),
73 ),
74 'required' => array( 'cbid' ),
75 'additionalProperties' => false,
76 ),
77 'output_schema' => array(
78 'type' => 'object',
79 'properties' => array(
80 'old_cbid_set' => array(
81 'type' => 'boolean',
82 'description' => 'Whether a Domain Group ID was configured before this call.',
83 ),
84 'new_cbid_set' => array(
85 'type' => 'boolean',
86 'description' => 'Whether a Domain Group ID is now configured.',
87 ),
88 'success' => array(
89 'type' => 'boolean',
90 'description' => 'Whether the update succeeded.',
91 ),
92 ),
93 'additionalProperties' => false,
94 ),
95 'execute_callback' => function( $input ) use ( $logger ) {
96 $cbid = isset( $input['cbid'] ) ? $input['cbid'] : '';
97
98 if ( empty( $cbid ) || ! preg_match( '/' . self::CBID_PATTERN . '/', $cbid ) ) {
99 return new \WP_Error(
100 'cookiebot_invalid_cbid',
101 __( 'Invalid ID. Provide a Cookiebot Domain Group ID (UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) or a Usercentrics Settings ID (9 or 14 alphanumeric characters).', 'cookiebot' )
102 );
103 }
104
105 $old_cbid = (string) Cookiebot_WP::get_cbid();
106 update_option( 'cookiebot-cbid', $cbid );
107 // Log only whether a value existed before/after — never log the CBID value itself.
108 $logger->log( 'cookiebot/set-cbid', $old_cbid !== '' ? 'was_set' : 'was_unset', 'set' );
109
110 return array(
111 'old_cbid_set' => $old_cbid !== '',
112 'new_cbid_set' => true,
113 'success' => true,
114 );
115 },
116 'permission_callback' => function() {
117 return current_user_can( 'manage_options' );
118 },
119 'meta' => array(
120 'annotations' => array(
121 'readonly' => false,
122 'destructive' => false,
123 'idempotent' => true,
124 ),
125 'show_in_rest' => true,
126 ),
127 );
128 }
129 }
130