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
Get_Compliance_Summary_Ability.php
88 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Get_Compliance_Summary_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 get compliance summary. |
| 15 | * |
| 16 | * @since 4.8.0 |
| 17 | */ |
| 18 | class Get_Compliance_Summary_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/get-compliance-summary'; |
| 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' => __( 'Get Compliance Summary', 'cookiebot' ), |
| 41 | 'description' => __( 'Returns the privacy regulations covered by Cookiebot CMP on this site, plus the current scan status and plan type.', 'cookiebot' ), |
| 42 | 'category' => 'cookiebot', |
| 43 | 'output_schema' => array( |
| 44 | 'type' => 'object', |
| 45 | 'properties' => array( |
| 46 | 'regulations_covered' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ), 'description' => 'Privacy regulations covered by Cookiebot CMP.' ), |
| 47 | 'scan_status' => array( 'type' => 'string', 'description' => 'Current cookie scan status.' ), |
| 48 | 'consent_log_available' => array( 'type' => 'boolean', 'description' => 'Whether a consent log exists (requires CBID to be configured).' ), |
| 49 | 'plan_type' => array( 'type' => 'string', 'description' => 'Detected plan type: free, premium, or unknown.' ), |
| 50 | ), |
| 51 | 'additionalProperties' => false, |
| 52 | ), |
| 53 | 'execute_callback' => function() { |
| 54 | $cbid = Cookiebot_WP::get_cbid(); |
| 55 | $user_data = Cookiebot_WP::get_user_data(); |
| 56 | $plan_type = 'unknown'; |
| 57 | |
| 58 | if ( ! empty( $user_data ) ) { |
| 59 | // get_user_data() may return a string (raw JSON) or an array (already-decoded option value). |
| 60 | $data = is_string( $user_data ) ? json_decode( $user_data, true ) : $user_data; |
| 61 | if ( is_array( $data ) && isset( $data['subscription']['plan'] ) ) { |
| 62 | $plan = strtolower( $data['subscription']['plan'] ); |
| 63 | if ( false !== strpos( $plan, 'free' ) ) { |
| 64 | $plan_type = 'free'; |
| 65 | } elseif ( false !== strpos( $plan, 'premium' ) || false !== strpos( $plan, 'pro' ) ) { |
| 66 | $plan_type = 'premium'; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return array( |
| 72 | 'regulations_covered' => array( 'GDPR', 'ePrivacy', 'CCPA/CPRA', 'LGPD', 'PDPA', 'PIPEDA', 'IAB TCF 2.2', 'Google Consent Mode v2' ), |
| 73 | 'scan_status' => (string) get_option( 'cookiebot-scan-status', '' ), |
| 74 | 'consent_log_available' => ! empty( $cbid ), |
| 75 | 'plan_type' => $plan_type, |
| 76 | ); |
| 77 | }, |
| 78 | 'permission_callback' => function() { |
| 79 | return current_user_can( 'manage_options' ); |
| 80 | }, |
| 81 | 'meta' => array( |
| 82 | 'annotations' => array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ), |
| 83 | 'show_in_rest' => true, |
| 84 | ), |
| 85 | ); |
| 86 | } |
| 87 | } |
| 88 |