Plugin Directory

Changeset 3384845


Ignore:
Timestamp:
10/26/2025 09:05:39 PM (4 months ago)
Author:
digitload330
Message:

MAJ Audit

Location:
fitconsent-cmp/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fitconsent-cmp/trunk/fitconsent-cmp.php

    r3360183 r3384845  
    44 * Plugin URI:        https://app.fitconsent.com
    55 * Description:       Integrates the FitConsent Consent Management Platform with WordPress and the WP Consent API for Google Site Kit compatibility.
    6  * Version:           1.0.1
     6 * Version:           1.0.2
    77 * Author:            FitConsent
    88 * Author URI:        https://fitconsent.com
     
    1616}
    1717
    18 define( 'FITCONSENT_VERSION', '1.0.1' );
     18define( 'FITCONSENT_VERSION', '1.0.2' );
    1919define( 'FITCONSENT_PLUGIN_FILE', __FILE__ );
    2020define( 'FITCONSENT_PLUGIN_PATH', plugin_dir_path( FITCONSENT_PLUGIN_FILE ) );
     
    4949            'fitconsent-wp-integration',
    5050            plugins_url( 'js/integration.js', FITCONSENT_PLUGIN_FILE ),
    51             [], // No dependencies, it will wait for the consent event
     51            [ 'wp-consent-api' ], // Explicitly depend on the WP Consent API.
    5252            FITCONSENT_VERSION,
    5353            true
  • fitconsent-cmp/trunk/js/integration.js

    r3360183 r3384845  
    22 * FitConsent - WP Consent API Integration
    33 *
    4  * This script listens for the FitConsent banner's consent event and translates it
    5  * into a WP Consent API update, ensuring compatibility with Google Site Kit.
     4 * This script sets a default consent state on page load and then listens for the
     5 * FitConsent banner's consent event to update the WP Consent API, ensuring
     6 * compatibility with Google Site Kit.
    67 */
    7 (function () {
     8(function (wp) {
    89    'use strict';
    910
     
    2122
    2223    /**
     24     * Creates a baseline consent state object, denying all optional categories.
     25     * @returns {Object} The baseline consent state.
     26     */
     27    function createBaselineConsentState() {
     28        const state = {};
     29        for (const key in categoryMap) {
     30            const wpCategory = categoryMap[key];
     31            state[wpCategory] = (wpCategory === 'necessary') ? 'allow' : 'deny';
     32        }
     33        return state;
     34    }
     35
     36    /**
     37     * Sets the default consent state before the user has interacted with the banner.
     38     */
     39    function setDefaultConsentState() {
     40        if (wp && wp.set_consent) {
     41            const defaultState = createBaselineConsentState();
     42            console.log('FitConsent cmp: Setting default WP Consent API state:', defaultState);
     43            wp.set_consent('page', defaultState);
     44        }
     45    }
     46
     47    /**
    2348     * Handles the consent update from the FitConsent banner.
    2449     * @param {Event} event The custom event fired by the banner.
     
    3156
    3257        const choices = event.detail.choices;
    33         const consentType = 'page'; // 'page' or 'session'
    34         const consentState = {};
    35        
    36         let allAccepted = true;
     58        const consentType = 'page';
     59
     60        const consentState = createBaselineConsentState();
    3761
    3862        for (const fitconsentCategory in choices) {
    3963            if (Object.prototype.hasOwnProperty.call(choices, fitconsentCategory)) {
    40                 const wpCategory = categoryMap[fitconsentCategory] || fitconsentCategory;
    41                 const consentValue = choices[fitconsentCategory] ? 'allow' : 'deny';
     64                // Use the mapped category if it exists, otherwise fall back to the original name.
     65                // This ensures custom categories are passed through correctly.
     66                const wpCategory = categoryMap[fitconsentCategory] ?? fitconsentCategory;
    4267
    43                 if (consentValue === 'deny') {
    44                     allAccepted = false;
     68                if (choices[fitconsentCategory]) {
     69                    consentState[wpCategory] = 'allow';
    4570                }
    46                
    47                 consentState[wpCategory] = consentValue;
    4871            }
    4972        }
    50        
    51         // Ensure all standard categories have a defined state.
    52         if (allAccepted) {
    53             consentState.statistics = 'allow';
    54             consentState.marketing = 'allow';
    55         } else {
    56              if (typeof consentState.statistics === 'undefined') consentState.statistics = 'deny';
    57              if (typeof consentState.marketing === 'undefined') consentState.marketing = 'deny';
    58         }
    59 
    6073
    6174        // Use the WP Consent API to set the consent state.
    62         if (window.wp_set_consent) {
     75        if (wp && wp.set_consent) {
    6376            console.log('FitConsent cmp: Updating WP Consent API with state:', consentState);
    64             window.wp_set_consent(consentType, consentState);
     77            wp.set_consent(consentType, consentState);
    6578        } else {
    6679            console.warn('FitConsent cmp: WP Consent API (wp_set_consent) not found.');
    6780        }
    6881    }
    69    
    70     // Listen for the custom event dispatched by the FitConsent banner upon user interaction.
    71     // We assume the banner script will dispatch a `fitconsent:consentUpdated` event.
    72     // The banner script needs to be modified to do this.
     82
     83    // Set the default state as soon as this script runs.
     84    setDefaultConsentState();
     85
     86    // Listen for the custom event dispatched by the FitConsent banner.
    7387    document.addEventListener('fitconsent:consentUpdated', handleConsentUpdate);
    7488
    75 })();
     89})(window);
Note: See TracChangeset for help on using the changeset viewer.