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
Verify_Setup_Ability.php
89 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Verify_Setup_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 verify Cookiebot CMP setup. |
| 15 | * |
| 16 | * @since 4.8.0 |
| 17 | */ |
| 18 | class Verify_Setup_Ability implements Cookiebot_Ability_Interface { |
| 19 | |
| 20 | /** |
| 21 | * Returns the ability name. |
| 22 | * |
| 23 | * @return string |
| 24 | * |
| 25 | * @since 4.8.0 |
| 26 | */ |
| 27 | public function get_name() { |
| 28 | return 'cookiebot/verify-setup'; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Returns the ability arguments. |
| 33 | * |
| 34 | * @return array |
| 35 | * |
| 36 | * @since 4.8.0 |
| 37 | */ |
| 38 | public function get_args() { |
| 39 | return array( |
| 40 | 'label' => __( 'Verify Cookiebot Setup', 'cookiebot' ), |
| 41 | 'description' => __( 'Checks that the Domain Group ID is configured, Google Consent Mode v2 is enabled, and cookie blocking mode is set to auto. Returns an issues[] list — empty means all checks passed.', 'cookiebot' ), |
| 42 | 'category' => 'cookiebot', |
| 43 | 'output_schema' => array( |
| 44 | 'type' => 'object', |
| 45 | 'properties' => array( |
| 46 | 'cbid_configured' => array( 'type' => 'boolean', 'description' => 'Whether a Domain Group ID is configured.' ), |
| 47 | 'configured_domain' => array( 'type' => 'string', 'description' => 'The WordPress site home URL.' ), |
| 48 | 'gcm_enabled' => array( 'type' => 'boolean', 'description' => 'Whether Google Consent Mode v2 is enabled.' ), |
| 49 | 'blocking_mode_automatic' => array( 'type' => 'boolean', 'description' => 'Whether cookie blocking mode is set to auto.' ), |
| 50 | 'issues' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ), 'description' => 'Configuration issues found. Empty = setup complete.' ), |
| 51 | ), |
| 52 | 'additionalProperties' => false, |
| 53 | ), |
| 54 | 'execute_callback' => function() { |
| 55 | $cbid = Cookiebot_WP::get_cbid(); |
| 56 | $gcm_enabled = Cookiebot_WP::get_gcm_enabled() === '1'; |
| 57 | $is_automatic = Cookiebot_WP::get_cookie_blocking_mode() === 'auto'; |
| 58 | $cbid_configured = ! empty( $cbid ); |
| 59 | $issues = array(); |
| 60 | |
| 61 | if ( ! $cbid_configured ) { |
| 62 | $issues[] = 'Domain Group ID is not configured. Go to Cookiebot > Settings > General and paste your Domain Group ID.'; |
| 63 | } |
| 64 | if ( ! $gcm_enabled ) { |
| 65 | $issues[] = 'Google Consent Mode v2 is disabled. Go to Cookiebot > Settings > Google Consent Mode and enable the toggle.'; |
| 66 | } |
| 67 | if ( ! $is_automatic ) { |
| 68 | $issues[] = 'Cookie blocking mode is manual. Go to Cookiebot > Settings > General and switch to automatic mode for GDPR compliance.'; |
| 69 | } |
| 70 | |
| 71 | return array( |
| 72 | 'cbid_configured' => $cbid_configured, |
| 73 | 'configured_domain' => home_url(), |
| 74 | 'gcm_enabled' => $gcm_enabled, |
| 75 | 'blocking_mode_automatic' => $is_automatic, |
| 76 | 'issues' => $issues, |
| 77 | ); |
| 78 | }, |
| 79 | 'permission_callback' => function() { |
| 80 | return current_user_can( 'manage_options' ); |
| 81 | }, |
| 82 | 'meta' => array( |
| 83 | 'annotations' => array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ), |
| 84 | 'show_in_rest' => true, |
| 85 | ), |
| 86 | ); |
| 87 | } |
| 88 | } |
| 89 |