Plugin Directory

Changeset 3104855


Ignore:
Timestamp:
06/20/2024 05:58:04 AM (22 months ago)
Author:
termageddon
Message:

Bump version 1.4.1

Location:
termageddon-usercentrics
Files:
3 deleted
8 edited
66 copied

Legend:

Unmodified
Added
Removed
  • termageddon-usercentrics/tags/1.4.1/README.txt

    r3060868 r3104855  
    55Requires at least: 3.0.1
    66Tested up to: 6.4.3
    7 Stable tag: 1.4.0
     7Stable tag: 1.4.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2727== Changelog ==
    2828
     29= 1.4.1 =
     30
     31-   [FIX] Fixed an issue where the plugin with Ajax Mode would bust cache for every request for some providers such as Pressable.
     32
    2933= 1.4.0 =
    3034
    31 -   [ADD] Added ability to disable plugin for troubleshooting to all visitors unless ?enable-usercentrics is added as a query parameter to the URL.
     35-   [ADD] Added ability to turn off plugin for troubleshooting to all visitors unless ?enable-usercentrics is added as a query parameter to the URL.
    3236
    3337= 1.3.9 =
  • termageddon-usercentrics/tags/1.4.1/admin/class-termageddon-usercentrics-admin.php

    r3060868 r3104855  
    505505            array(
    506506                'label_for'   => 'termageddon_usercentrics_disable_troubleshooting',
    507                 'description' => __( 'When enabled, this feature allows you to disable the consent tool for all site visitors, however by adding <code>?enable-usercentrics</code> to the end of a URL, the consent tool will load, allowing you to troubleshoot any issues (or to reach out to Termageddon support to help assist with troubleshooting)', 'termageddon-usercentrics' ),
     507                'description' => __( 'When enabled, this feature allows you to turn off the consent tool for all site visitors, however by adding <code>?enable-usercentrics</code> to the end of a URL, the consent tool will load, allowing you to troubleshoot any issues (or to reach out to Termageddon support to help assist with troubleshooting)', 'termageddon-usercentrics' ),
    508508            )
    509509        );
  • termageddon-usercentrics/tags/1.4.1/includes/class-termageddon-usercentrics.php

    r3060868 r3104855  
    267267        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
    268268
    269         if ( self::is_geoip_enabled() && ! wp_doing_cron() ) {
     269        if ( self::is_geoip_enabled() && ! self::is_ajax_mode_enabled() && ! wp_doing_cron() ) {
    270270            $this->loader->add_action( 'init', $this, 'lookup_ip_address' );
    271271
     
    421421        // Check for fatal errors.
    422422        if ( self::check_for_download_errors() ) {
     423            return false;
     424        }
     425
     426        // If Geo IP is enabled, download.
     427        if ( ! self::is_geoip_enabled() ) {
    423428            return false;
    424429        }
     
    750755
    751756    }
    752    
    753    
     757
     758
    754759    /**
    755760     * Returns whether disabled for troubleshooting mode is enabled and not in the query params
     
    758763     */
    759764    public static function is_disabled_for_troubleshooting() {
    760         $enabled = ( get_option( 'termageddon_usercentrics_disable_troubleshooting', false ) ? true : false );
    761 
    762         if ($enabled && !isset($_GET['enable-usercentrics'])) return true;
    763         return false;
     765        return ( get_option( 'termageddon_usercentrics_disable_troubleshooting', false ) ? true : false );
     766
     767    }
     768
     769
     770    /**
     771     * Returns whether user wants to force enable via the query params.
     772     *
     773     * @return bool
     774     */
     775    public static function is_enabled_via_get_override() {
     776        return isset( $_GET['enable-usercentrics'] );
    764777
    765778    }
     
    834847        $cookie_title = self::get_cookie_title();
    835848
    836         // Validate Database && download database if needed.
    837         self::verify_maxmind_database();
    838 
    839         // If Email is not in blacklist, try to calculate geo ip location.
    840         if ( '::1' !== $ip_address ) {
    841             // Check for cached location via cookie, or check the geo ip database if no cookie found.
    842             if ( isset( $_COOKIE[ $cookie_title ] ) && ! self::is_debug_mode_enabled() ) {
    843                 @list('city' => $city, 'state' => $state, 'country' => $country) = json_decode( sanitize_text_field( wp_unslash( $_COOKIE[ $cookie_title ] ) ), true );
    844             } else {
    845                 try {
    846 
    847                     $reader = new Reader( self::get_maxmind_db_path() );
    848 
    849                     $record = $reader->City( $ip_address );
    850 
    851                     if ( isset( $record->city->names ) && isset( $record->city->names['en'] ) ) {
    852                         $city = $record->city->names['en'];
    853                     }
    854                     if ( isset( $record->subdivisions[0] ) && isset( $record->subdivisions[0]->names ) && isset( $record->subdivisions[0]->names['en'] ) ) {
    855                         $state = $record->subdivisions[0]->names['en'];
    856                     }
    857                     if ( isset( $record->country->names ) && isset( $record->country->names['en'] ) ) {
    858                         $country = $record->country->names['en'];
    859                     }
    860 
    861                     // If able to, set cookie to allow future page loads to simply use the cookie for processing.
    862                     if ( ! headers_sent() ) {
    863                         setcookie(
    864                             $cookie_title,
    865                             wp_json_encode(
     849        // If Geo IP is enabled, download.
     850        if ( self::is_geoip_enabled() ) {
     851            // Validate Database && download database if needed.
     852            self::verify_maxmind_database();
     853
     854            // If Email is not in blacklist, try to calculate geo ip location.
     855            if ( '::1' !== $ip_address ) {
     856                // Check for cached location via cookie, or check the geo ip database if no cookie found.
     857                if ( isset( $_COOKIE[ $cookie_title ] ) && ! self::is_debug_mode_enabled() ) {
     858                    @list('city' => $city, 'state' => $state, 'country' => $country) = json_decode( sanitize_text_field( wp_unslash( $_COOKIE[ $cookie_title ] ) ), true );
     859                } else {
     860                    try {
     861
     862                        $reader = new Reader( self::get_maxmind_db_path() );
     863
     864                        $record = $reader->City( $ip_address );
     865
     866                        if ( isset( $record->city->names ) && isset( $record->city->names['en'] ) ) {
     867                            $city = $record->city->names['en'];
     868                        }
     869                        if ( isset( $record->subdivisions[0] ) && isset( $record->subdivisions[0]->names ) && isset( $record->subdivisions[0]->names['en'] ) ) {
     870                            $state = $record->subdivisions[0]->names['en'];
     871                        }
     872                        if ( isset( $record->country->names ) && isset( $record->country->names['en'] ) ) {
     873                            $country = $record->country->names['en'];
     874                        }
     875
     876                        // If able to, set cookie to allow future page loads to simply use the cookie for processing.
     877                        if ( ! headers_sent() && ! isset( $_COOKIE[ $cookie_title ] ) ) {
     878                            $cookie_value = wp_json_encode(
    866879                                array(
    867880                                    'city'    => $city,
     
    869882                                    'country' => $country,
    870883                                )
    871                             ),
    872                             0,
    873                             COOKIEPATH,
    874                             COOKIE_DOMAIN
    875                         );
    876                     }
    877                 } catch ( \Throwable $th ) {
    878                     // Error with GEO IP.
    879                     // Display it IF debug via GET is enabled and administrator.
    880                     if ( current_user_can( 'administrator' ) || self::is_debug_mode_enabled() ) {
    881                         self::debug( 'Error Calculating Location', $th->getMessage() );
     884                            );
     885
     886                            setcookie(
     887                                $cookie_title,
     888                                $cookie_value,
     889                                0,
     890                                COOKIEPATH,
     891                                COOKIE_DOMAIN
     892                            );
     893                            $_COOKIE[ $cookie_title ] = $cookie_value;
     894                        }
     895                    } catch ( \Throwable $th ) {
     896                        // Error with GEO IP.
     897                        // Display it IF debug via GET is enabled and administrator.
     898                        if ( current_user_can( 'administrator' ) || self::is_debug_mode_enabled() ) {
     899                            self::debug( 'Error Calculating Location', $th->getMessage() );
     900                        }
    882901                    }
    883902                }
  • termageddon-usercentrics/tags/1.4.1/languages/termageddon-usercentrics.pot

    r3060868 r3104855  
    286286#: admin/class-termageddon-usercentrics-admin.php:507
    287287msgid ""
    288 "When enabled, this feature allows you to disable the consent tool for all "
     288"When enabled, this feature allows you to turn off the consent tool for all "
    289289"site visitors, however by adding <code>?enable-usercentrics</code> to the "
    290290"end of a URL, the consent tool will load, allowing you to troubleshoot any "
  • termageddon-usercentrics/tags/1.4.1/public/class-termageddon-usercentrics-public.php

    r3060868 r3104855  
    120120        echo wp_kses( $script, Termageddon_Usercentrics::ALLOWED_HTML );
    121121        echo '<!-- END TERMAGEDDON + USERCENTRICS -->';
     122    }
     123
     124    /**
     125     * Display debug information to console if applicable
     126     *
     127     * @return void
     128     */
     129    public function debug_display() {
     130        if ( ( Termageddon_Usercentrics::is_geoip_enabled() || Termageddon_Usercentrics::is_debug_mode_enabled() )
     131            &&
     132            ! Termageddon_Usercentrics::is_ajax_mode_enabled()
     133            ) {
     134                list('city' => $city, 'state' => $state, 'country' => $country) = Termageddon_Usercentrics::lookup_ip_address();
     135
     136                // Output debug message to console.
     137                Termageddon_Usercentrics::debug(
     138                    'IP Address: ' . Termageddon_Usercentrics::get_processed_ip_address(),
     139                    'City: ' . ( $city ?? 'Unknown' ),
     140                    'State: ' . ( $state ?? 'Unknown' ),
     141                    'Country: ' . ( $country ?? 'Unknown' ),
     142                    '--',
     143                    'Located in EU?: ' . ( Termageddon_Usercentrics::is_located_in_eu() ? 'Yes' : 'No' ),
     144                    'Located in UK?: ' . ( Termageddon_Usercentrics::is_located_in_uk() ? 'Yes' : 'No' ),
     145                    'Located in Canada?: ' . ( Termageddon_Usercentrics::is_located_in_canada() ? 'Yes' : 'No' ),
     146                    'Located in California?: ' . ( Termageddon_Usercentrics::is_located_in_california() ? 'Yes' : 'No' ),
     147                    'Located in Virginia?: ' . ( Termageddon_Usercentrics::is_located_in_virginia() ? 'Yes' : 'No' ),
     148                    '--',
     149                    'Geo-Location Mode?: ' . ( Termageddon_Usercentrics::is_geoip_enabled() ? 'Yes' : 'No' ),
     150                    'AJAX Mode?: ' . ( Termageddon_Usercentrics::is_ajax_mode_enabled() ? 'Yes' : 'No' ),
     151                );
     152        }
    122153    }
    123154
     
    155186        }
    156187
    157         // Check for Disable for troubleshooting while validating query param.
    158         if (Termageddon_Usercentrics::is_disabled_for_troubleshooting()) {
    159             return self::disable_termageddon_script();
    160         }
    161 
    162         // Debug Display to identify locations.
    163         if ( ( Termageddon_Usercentrics::is_geoip_enabled() || Termageddon_Usercentrics::is_debug_mode_enabled() )
    164                 &&
    165                 ! Termageddon_Usercentrics::is_ajax_mode_enabled()
    166             ) {
    167             list('city' => $city, 'state' => $state, 'country' => $country) = Termageddon_Usercentrics::lookup_ip_address();
    168 
    169             // Output debug message to console.
    170             Termageddon_Usercentrics::debug(
    171                 'IP Address: ' . Termageddon_Usercentrics::get_processed_ip_address(),
    172                 'City: ' . ( $city ?? 'Unknown' ),
    173                 'State: ' . ( $state ?? 'Unknown' ),
    174                 'Country: ' . ( $country ?? 'Unknown' ),
    175                 '--',
    176                 'Located in EU?: ' . ( Termageddon_Usercentrics::is_located_in_eu() ? 'Yes' : 'No' ),
    177                 'Located in UK?: ' . ( Termageddon_Usercentrics::is_located_in_uk() ? 'Yes' : 'No' ),
    178                 'Located in Canada?: ' . ( Termageddon_Usercentrics::is_located_in_canada() ? 'Yes' : 'No' ),
    179                 'Located in California?: ' . ( Termageddon_Usercentrics::is_located_in_california() ? 'Yes' : 'No' ),
    180                 'Located in Virginia?: ' . ( Termageddon_Usercentrics::is_located_in_virginia() ? 'Yes' : 'No' ),
    181                 '--',
    182                 'Geo-Location Mode?: ' . ( Termageddon_Usercentrics::is_geoip_enabled() ? 'Yes' : 'No' ),
    183                 'AJAX Mode?: ' . ( Termageddon_Usercentrics::is_ajax_mode_enabled() ? 'Yes' : 'No' ),
    184             );
    185         }
    186 
    187         $disable_on_logged_in = get_option( 'termageddon_usercentrics_disable_logged_in', false ) ? true : false;
    188         if ( $disable_on_logged_in && is_user_logged_in() ) {
    189             return self::disable_termageddon_script();
    190         }
    191 
    192         $disable_on_editor = get_option( 'termageddon_usercentrics_disable_editor', false ) ? true : false;
    193         if ( $disable_on_editor && current_user_can( 'editor' ) ) {
    194             return self::disable_termageddon_script();
    195         }
    196 
    197         $disable_on_admin = get_option( 'termageddon_usercentrics_disable_admin', false ) ? true : false;
    198         if ( $disable_on_admin && current_user_can( 'administrator' ) ) {
    199             return self::disable_termageddon_script();
    200         }
    201 
    202         if ( Termageddon_Usercentrics::is_geoip_enabled() && ! Termageddon_Usercentrics::is_ajax_mode_enabled() && Termageddon_Usercentrics::should_hide_due_to_location() ) {
    203             return self::disable_termageddon_script();
     188        // If forcibly enabled, bypass individual detections.
     189        if ( ! Termageddon_Usercentrics::is_enabled_via_get_override() ) {
     190            // Check for Disable for troubleshooting.
     191            if ( Termageddon_Usercentrics::is_disabled_for_troubleshooting() ) {
     192                return self::disable_termageddon_script();
     193            }
     194
     195            // Debug display to console if applicable.
     196            self::debug_display();
     197
     198            // Check for individual disable detections.
     199            $disable_on_logged_in = get_option( 'termageddon_usercentrics_disable_logged_in', false ) ? true : false;
     200            if ( $disable_on_logged_in && is_user_logged_in() ) {
     201                return self::disable_termageddon_script();
     202            }
     203
     204            $disable_on_editor = get_option( 'termageddon_usercentrics_disable_editor', false ) ? true : false;
     205            if ( $disable_on_editor && current_user_can( 'editor' ) ) {
     206                return self::disable_termageddon_script();
     207            }
     208
     209            $disable_on_admin = get_option( 'termageddon_usercentrics_disable_admin', false ) ? true : false;
     210            if ( $disable_on_admin && current_user_can( 'administrator' ) ) {
     211                return self::disable_termageddon_script();
     212            }
     213
     214            if ( Termageddon_Usercentrics::is_geoip_enabled() && ! Termageddon_Usercentrics::is_ajax_mode_enabled() && Termageddon_Usercentrics::should_hide_due_to_location() ) {
     215                return self::disable_termageddon_script();
     216            }
     217        } else {
     218            // Debug display to console if applicable.
     219            self::debug_display();
    204220        }
    205221
  • termageddon-usercentrics/tags/1.4.1/public/js/termageddon-usercentrics-ajax.js

    r2890756 r3104855  
    1010        const parts = value.split(`; ${name}=`);
    1111        if (parts.length === 2) return parts.pop().split(";").shift();
     12    };
     13
     14    const getQueryParams = (param) => {
     15        const params = new Proxy(new URLSearchParams(window.location.search), {
     16            get: (searchParams, prop) => searchParams.get(prop),
     17        });
     18
     19        return params[param];
    1220    };
    1321
     
    5765    if (typeof UC_UI === "undefined")
    5866        return console.error("Usercentrics not loaded");
     67
     68    //Check query variable from browser
     69    const query_hide =
     70        getQueryParams("enable-usercentrics") === "" ? true : false;
    5971
    6072    //Check for local cookie to use instead of calling.
     
    133145                }
    134146
     147                if (query_hide) {
     148                    if (tuDebug)
     149                        console.log(
     150                            "UC: Enabling due to query parameter override.",
     151                            "Showing Usercentrics"
     152                        );
     153                    return updateCookieConsent(false);
     154                }
     155
    135156                //If you are not supposed to be hiding, show the CMP.
    136157                setCookie(tuCookieHideName, data.hide ? "true" : "false");
  • termageddon-usercentrics/tags/1.4.1/public/js/termageddon-usercentrics-ajax.min.js

    r2890756 r3104855  
    1 const tuCookieHideName="tu-geoip-hide",tuDebug="true"===termageddon_usercentrics_obj.debug,tuPSLHide="true"===termageddon_usercentrics_obj.psl_hide;tuDebug&&console.log("UC: AJAX script initialized"),window.addEventListener("UC_UI_INITIALIZED",(function(){const getCookie=name=>{const value=`; ${document.cookie}`,parts=value.split(`; ${name}=`);if(2===parts.length)return parts.pop().split(";").shift()},setCookie=(name,value,days)=>{var expires="";if(days){var date=new Date;date.setTime(date.getTime()+24*days*60*60*1e3),expires="; expires="+date.toUTCString()}document.cookie=name+"="+(value||"")+expires+"; path=/"},updateCookieConsent=hide=>{if(!hide)return tuDebug&&console.log("UC: Showing consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").show(),jQuery("div#usercentrics-root").show(),UC_UI.isConsentRequired()?UC_UI.showFirstLayer():UC_UI.closeCMP();tuDebug&&console.log("UC: Hiding consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").hide(),jQuery("div#usercentrics-root").hide(),UC_UI.areAllConsentsAccepted()||UC_UI.acceptAllConsents().then(()=>{tuDebug&&console.log("UC: All consents have been accepted."),UC_UI.closeCMP().then(()=>{tuDebug&&console.log("UC: CMP Widget has been closed.")})})};if("undefined"==typeof UC_UI)return console.error("Usercentrics not loaded");const cookie_hide=getCookie("tu-geoip-hide");if(null==cookie_hide||tuDebug){tuDebug&&console.log("UC: Making AJAX Call");var data={action:"uc_geolocation_lookup",nonce:termageddon_usercentrics_obj.nonce};void 0!==termageddon_usercentrics_obj.location&&(data.location=termageddon_usercentrics_obj.location),jQuery.post(termageddon_usercentrics_obj.ajax_url,data).done((function(response){if(!response.success)return console.error("Unable to lookup location.",response.message||"");if(!response.data)return console.error("Location data was not provided.",response.data);const data=response.data;tuDebug&&console.log("TERMAGEDDON USERCENTRICS (AJAX)\nIP Address: "+data.ipAddress+"\nCity: "+(data.city||"Unknown")+"\nState: "+(data.state||"Unknown")+"\nCountry: "+(data.country||"Unknown")+"\n--\nLocated in EU?: "+(data.inEU?"Yes":"No")+"\nLocated in UK?: "+(data.inUK?"Yes":"No")+"\nLocated in Canada?: "+(data.inCanada?"Yes":"No")+"\nLocated in California?: "+(data.inCalifornia?"Yes":"No")+"\nLocated in Virginia?: "+(data.inVirginia?"Yes":"No")),setCookie("tu-geoip-hide",data.hide?"true":"false"),updateCookieConsent(data.hide)})).fail((function(response){console.error("Usercentrics: Invalid response returned. Showing widget as a default.",response),updateCookieConsent(!1)}))}else tuDebug&&console.log("UC: Cookie found.",(cookie_hide?"Showing":"Hiding")+" Usercentrics"),updateCookieConsent("true"===cookie_hide)}));
     1const tuCookieHideName="tu-geoip-hide",tuDebug="true"===termageddon_usercentrics_obj.debug,tuPSLHide="true"===termageddon_usercentrics_obj.psl_hide;tuDebug&&console.log("UC: AJAX script initialized"),window.addEventListener("UC_UI_INITIALIZED",(function(){const getCookie=name=>{const value=`; ${document.cookie}`,parts=value.split(`; ${name}=`);if(2===parts.length)return parts.pop().split(";").shift()},getQueryParams=param=>{const params=new Proxy(new URLSearchParams(window.location.search),{get:(searchParams,prop)=>searchParams.get(prop)});return params[param]},setCookie=(name,value,days)=>{var expires="";if(days){var date=new Date;date.setTime(date.getTime()+24*days*60*60*1e3),expires="; expires="+date.toUTCString()}document.cookie=name+"="+(value||"")+expires+"; path=/"},updateCookieConsent=hide=>{if(!hide)return tuDebug&&console.log("UC: Showing consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").show(),jQuery("div#usercentrics-root").show(),UC_UI.isConsentRequired()?UC_UI.showFirstLayer():UC_UI.closeCMP();tuDebug&&console.log("UC: Hiding consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").hide(),jQuery("div#usercentrics-root").hide(),UC_UI.areAllConsentsAccepted()||UC_UI.acceptAllConsents().then(()=>{tuDebug&&console.log("UC: All consents have been accepted."),UC_UI.closeCMP().then(()=>{tuDebug&&console.log("UC: CMP Widget has been closed.")})})};if("undefined"==typeof UC_UI)return console.error("Usercentrics not loaded");const query_hide=""===getQueryParams("enable-usercentrics"),cookie_hide=getCookie("tu-geoip-hide");if(null==cookie_hide||tuDebug){tuDebug&&console.log("UC: Making AJAX Call");var data={action:"uc_geolocation_lookup",nonce:termageddon_usercentrics_obj.nonce};void 0!==termageddon_usercentrics_obj.location&&(data.location=termageddon_usercentrics_obj.location),jQuery.post(termageddon_usercentrics_obj.ajax_url,data).done((function(response){if(!response.success)return console.error("Unable to lookup location.",response.message||"");if(!response.data)return console.error("Location data was not provided.",response.data);const data=response.data;if(tuDebug&&console.log("TERMAGEDDON USERCENTRICS (AJAX)\nIP Address: "+data.ipAddress+"\nCity: "+(data.city||"Unknown")+"\nState: "+(data.state||"Unknown")+"\nCountry: "+(data.country||"Unknown")+"\n--\nLocated in EU?: "+(data.inEU?"Yes":"No")+"\nLocated in UK?: "+(data.inUK?"Yes":"No")+"\nLocated in Canada?: "+(data.inCanada?"Yes":"No")+"\nLocated in California?: "+(data.inCalifornia?"Yes":"No")+"\nLocated in Virginia?: "+(data.inVirginia?"Yes":"No")),query_hide)return tuDebug&&console.log("UC: Enabling due to query parameter override.","Showing Usercentrics"),updateCookieConsent(!1);setCookie("tu-geoip-hide",data.hide?"true":"false"),updateCookieConsent(data.hide)})).fail((function(response){console.error("Usercentrics: Invalid response returned. Showing widget as a default.",response),updateCookieConsent(!1)}))}else tuDebug&&console.log("UC: Cookie found.",(cookie_hide?"Showing":"Hiding")+" Usercentrics"),updateCookieConsent("true"===cookie_hide)}));
  • termageddon-usercentrics/tags/1.4.1/termageddon-usercentrics.php

    r3060868 r3104855  
    1515 * Plugin Name:       Termageddon + Usercentrics
    1616 * Description:       Easily integrate the Usercentrics consent solution into your website while controlling visibility for logged in users and admins.
    17  * Version:           1.4.0
     17 * Version:           1.4.1
    1818 * Author:            Termageddon
    1919 * Author URI:        https://termageddon.com
     
    3434 * Rename this for your plugin and update it as you release new versions.
    3535 */
    36 define( 'TERMAGEDDON_COOKIE_VERSION', '1.4.0' );
     36define( 'TERMAGEDDON_COOKIE_VERSION', '1.4.1' );
    3737
    3838define( 'TERMAGEDDON_COOKIE_PLUGIN_PATH', dirname( __FILE__ ) );// No trailing slash.
  • termageddon-usercentrics/trunk/README.txt

    r3060868 r3104855  
    55Requires at least: 3.0.1
    66Tested up to: 6.4.3
    7 Stable tag: 1.4.0
     7Stable tag: 1.4.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2727== Changelog ==
    2828
     29= 1.4.1 =
     30
     31-   [FIX] Fixed an issue where the plugin with Ajax Mode would bust cache for every request for some providers such as Pressable.
     32
    2933= 1.4.0 =
    3034
    31 -   [ADD] Added ability to disable plugin for troubleshooting to all visitors unless ?enable-usercentrics is added as a query parameter to the URL.
     35-   [ADD] Added ability to turn off plugin for troubleshooting to all visitors unless ?enable-usercentrics is added as a query parameter to the URL.
    3236
    3337= 1.3.9 =
  • termageddon-usercentrics/trunk/admin/class-termageddon-usercentrics-admin.php

    r3060868 r3104855  
    505505            array(
    506506                'label_for'   => 'termageddon_usercentrics_disable_troubleshooting',
    507                 'description' => __( 'When enabled, this feature allows you to disable the consent tool for all site visitors, however by adding <code>?enable-usercentrics</code> to the end of a URL, the consent tool will load, allowing you to troubleshoot any issues (or to reach out to Termageddon support to help assist with troubleshooting)', 'termageddon-usercentrics' ),
     507                'description' => __( 'When enabled, this feature allows you to turn off the consent tool for all site visitors, however by adding <code>?enable-usercentrics</code> to the end of a URL, the consent tool will load, allowing you to troubleshoot any issues (or to reach out to Termageddon support to help assist with troubleshooting)', 'termageddon-usercentrics' ),
    508508            )
    509509        );
  • termageddon-usercentrics/trunk/includes/class-termageddon-usercentrics.php

    r3060868 r3104855  
    267267        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
    268268
    269         if ( self::is_geoip_enabled() && ! wp_doing_cron() ) {
     269        if ( self::is_geoip_enabled() && ! self::is_ajax_mode_enabled() && ! wp_doing_cron() ) {
    270270            $this->loader->add_action( 'init', $this, 'lookup_ip_address' );
    271271
     
    421421        // Check for fatal errors.
    422422        if ( self::check_for_download_errors() ) {
     423            return false;
     424        }
     425
     426        // If Geo IP is enabled, download.
     427        if ( ! self::is_geoip_enabled() ) {
    423428            return false;
    424429        }
     
    750755
    751756    }
    752    
    753    
     757
     758
    754759    /**
    755760     * Returns whether disabled for troubleshooting mode is enabled and not in the query params
     
    758763     */
    759764    public static function is_disabled_for_troubleshooting() {
    760         $enabled = ( get_option( 'termageddon_usercentrics_disable_troubleshooting', false ) ? true : false );
    761 
    762         if ($enabled && !isset($_GET['enable-usercentrics'])) return true;
    763         return false;
     765        return ( get_option( 'termageddon_usercentrics_disable_troubleshooting', false ) ? true : false );
     766
     767    }
     768
     769
     770    /**
     771     * Returns whether user wants to force enable via the query params.
     772     *
     773     * @return bool
     774     */
     775    public static function is_enabled_via_get_override() {
     776        return isset( $_GET['enable-usercentrics'] );
    764777
    765778    }
     
    834847        $cookie_title = self::get_cookie_title();
    835848
    836         // Validate Database && download database if needed.
    837         self::verify_maxmind_database();
    838 
    839         // If Email is not in blacklist, try to calculate geo ip location.
    840         if ( '::1' !== $ip_address ) {
    841             // Check for cached location via cookie, or check the geo ip database if no cookie found.
    842             if ( isset( $_COOKIE[ $cookie_title ] ) && ! self::is_debug_mode_enabled() ) {
    843                 @list('city' => $city, 'state' => $state, 'country' => $country) = json_decode( sanitize_text_field( wp_unslash( $_COOKIE[ $cookie_title ] ) ), true );
    844             } else {
    845                 try {
    846 
    847                     $reader = new Reader( self::get_maxmind_db_path() );
    848 
    849                     $record = $reader->City( $ip_address );
    850 
    851                     if ( isset( $record->city->names ) && isset( $record->city->names['en'] ) ) {
    852                         $city = $record->city->names['en'];
    853                     }
    854                     if ( isset( $record->subdivisions[0] ) && isset( $record->subdivisions[0]->names ) && isset( $record->subdivisions[0]->names['en'] ) ) {
    855                         $state = $record->subdivisions[0]->names['en'];
    856                     }
    857                     if ( isset( $record->country->names ) && isset( $record->country->names['en'] ) ) {
    858                         $country = $record->country->names['en'];
    859                     }
    860 
    861                     // If able to, set cookie to allow future page loads to simply use the cookie for processing.
    862                     if ( ! headers_sent() ) {
    863                         setcookie(
    864                             $cookie_title,
    865                             wp_json_encode(
     849        // If Geo IP is enabled, download.
     850        if ( self::is_geoip_enabled() ) {
     851            // Validate Database && download database if needed.
     852            self::verify_maxmind_database();
     853
     854            // If Email is not in blacklist, try to calculate geo ip location.
     855            if ( '::1' !== $ip_address ) {
     856                // Check for cached location via cookie, or check the geo ip database if no cookie found.
     857                if ( isset( $_COOKIE[ $cookie_title ] ) && ! self::is_debug_mode_enabled() ) {
     858                    @list('city' => $city, 'state' => $state, 'country' => $country) = json_decode( sanitize_text_field( wp_unslash( $_COOKIE[ $cookie_title ] ) ), true );
     859                } else {
     860                    try {
     861
     862                        $reader = new Reader( self::get_maxmind_db_path() );
     863
     864                        $record = $reader->City( $ip_address );
     865
     866                        if ( isset( $record->city->names ) && isset( $record->city->names['en'] ) ) {
     867                            $city = $record->city->names['en'];
     868                        }
     869                        if ( isset( $record->subdivisions[0] ) && isset( $record->subdivisions[0]->names ) && isset( $record->subdivisions[0]->names['en'] ) ) {
     870                            $state = $record->subdivisions[0]->names['en'];
     871                        }
     872                        if ( isset( $record->country->names ) && isset( $record->country->names['en'] ) ) {
     873                            $country = $record->country->names['en'];
     874                        }
     875
     876                        // If able to, set cookie to allow future page loads to simply use the cookie for processing.
     877                        if ( ! headers_sent() && ! isset( $_COOKIE[ $cookie_title ] ) ) {
     878                            $cookie_value = wp_json_encode(
    866879                                array(
    867880                                    'city'    => $city,
     
    869882                                    'country' => $country,
    870883                                )
    871                             ),
    872                             0,
    873                             COOKIEPATH,
    874                             COOKIE_DOMAIN
    875                         );
    876                     }
    877                 } catch ( \Throwable $th ) {
    878                     // Error with GEO IP.
    879                     // Display it IF debug via GET is enabled and administrator.
    880                     if ( current_user_can( 'administrator' ) || self::is_debug_mode_enabled() ) {
    881                         self::debug( 'Error Calculating Location', $th->getMessage() );
     884                            );
     885
     886                            setcookie(
     887                                $cookie_title,
     888                                $cookie_value,
     889                                0,
     890                                COOKIEPATH,
     891                                COOKIE_DOMAIN
     892                            );
     893                            $_COOKIE[ $cookie_title ] = $cookie_value;
     894                        }
     895                    } catch ( \Throwable $th ) {
     896                        // Error with GEO IP.
     897                        // Display it IF debug via GET is enabled and administrator.
     898                        if ( current_user_can( 'administrator' ) || self::is_debug_mode_enabled() ) {
     899                            self::debug( 'Error Calculating Location', $th->getMessage() );
     900                        }
    882901                    }
    883902                }
  • termageddon-usercentrics/trunk/languages/termageddon-usercentrics.pot

    r3060868 r3104855  
    286286#: admin/class-termageddon-usercentrics-admin.php:507
    287287msgid ""
    288 "When enabled, this feature allows you to disable the consent tool for all "
     288"When enabled, this feature allows you to turn off the consent tool for all "
    289289"site visitors, however by adding <code>?enable-usercentrics</code> to the "
    290290"end of a URL, the consent tool will load, allowing you to troubleshoot any "
  • termageddon-usercentrics/trunk/public/class-termageddon-usercentrics-public.php

    r3060868 r3104855  
    120120        echo wp_kses( $script, Termageddon_Usercentrics::ALLOWED_HTML );
    121121        echo '<!-- END TERMAGEDDON + USERCENTRICS -->';
     122    }
     123
     124    /**
     125     * Display debug information to console if applicable
     126     *
     127     * @return void
     128     */
     129    public function debug_display() {
     130        if ( ( Termageddon_Usercentrics::is_geoip_enabled() || Termageddon_Usercentrics::is_debug_mode_enabled() )
     131            &&
     132            ! Termageddon_Usercentrics::is_ajax_mode_enabled()
     133            ) {
     134                list('city' => $city, 'state' => $state, 'country' => $country) = Termageddon_Usercentrics::lookup_ip_address();
     135
     136                // Output debug message to console.
     137                Termageddon_Usercentrics::debug(
     138                    'IP Address: ' . Termageddon_Usercentrics::get_processed_ip_address(),
     139                    'City: ' . ( $city ?? 'Unknown' ),
     140                    'State: ' . ( $state ?? 'Unknown' ),
     141                    'Country: ' . ( $country ?? 'Unknown' ),
     142                    '--',
     143                    'Located in EU?: ' . ( Termageddon_Usercentrics::is_located_in_eu() ? 'Yes' : 'No' ),
     144                    'Located in UK?: ' . ( Termageddon_Usercentrics::is_located_in_uk() ? 'Yes' : 'No' ),
     145                    'Located in Canada?: ' . ( Termageddon_Usercentrics::is_located_in_canada() ? 'Yes' : 'No' ),
     146                    'Located in California?: ' . ( Termageddon_Usercentrics::is_located_in_california() ? 'Yes' : 'No' ),
     147                    'Located in Virginia?: ' . ( Termageddon_Usercentrics::is_located_in_virginia() ? 'Yes' : 'No' ),
     148                    '--',
     149                    'Geo-Location Mode?: ' . ( Termageddon_Usercentrics::is_geoip_enabled() ? 'Yes' : 'No' ),
     150                    'AJAX Mode?: ' . ( Termageddon_Usercentrics::is_ajax_mode_enabled() ? 'Yes' : 'No' ),
     151                );
     152        }
    122153    }
    123154
     
    155186        }
    156187
    157         // Check for Disable for troubleshooting while validating query param.
    158         if (Termageddon_Usercentrics::is_disabled_for_troubleshooting()) {
    159             return self::disable_termageddon_script();
    160         }
    161 
    162         // Debug Display to identify locations.
    163         if ( ( Termageddon_Usercentrics::is_geoip_enabled() || Termageddon_Usercentrics::is_debug_mode_enabled() )
    164                 &&
    165                 ! Termageddon_Usercentrics::is_ajax_mode_enabled()
    166             ) {
    167             list('city' => $city, 'state' => $state, 'country' => $country) = Termageddon_Usercentrics::lookup_ip_address();
    168 
    169             // Output debug message to console.
    170             Termageddon_Usercentrics::debug(
    171                 'IP Address: ' . Termageddon_Usercentrics::get_processed_ip_address(),
    172                 'City: ' . ( $city ?? 'Unknown' ),
    173                 'State: ' . ( $state ?? 'Unknown' ),
    174                 'Country: ' . ( $country ?? 'Unknown' ),
    175                 '--',
    176                 'Located in EU?: ' . ( Termageddon_Usercentrics::is_located_in_eu() ? 'Yes' : 'No' ),
    177                 'Located in UK?: ' . ( Termageddon_Usercentrics::is_located_in_uk() ? 'Yes' : 'No' ),
    178                 'Located in Canada?: ' . ( Termageddon_Usercentrics::is_located_in_canada() ? 'Yes' : 'No' ),
    179                 'Located in California?: ' . ( Termageddon_Usercentrics::is_located_in_california() ? 'Yes' : 'No' ),
    180                 'Located in Virginia?: ' . ( Termageddon_Usercentrics::is_located_in_virginia() ? 'Yes' : 'No' ),
    181                 '--',
    182                 'Geo-Location Mode?: ' . ( Termageddon_Usercentrics::is_geoip_enabled() ? 'Yes' : 'No' ),
    183                 'AJAX Mode?: ' . ( Termageddon_Usercentrics::is_ajax_mode_enabled() ? 'Yes' : 'No' ),
    184             );
    185         }
    186 
    187         $disable_on_logged_in = get_option( 'termageddon_usercentrics_disable_logged_in', false ) ? true : false;
    188         if ( $disable_on_logged_in && is_user_logged_in() ) {
    189             return self::disable_termageddon_script();
    190         }
    191 
    192         $disable_on_editor = get_option( 'termageddon_usercentrics_disable_editor', false ) ? true : false;
    193         if ( $disable_on_editor && current_user_can( 'editor' ) ) {
    194             return self::disable_termageddon_script();
    195         }
    196 
    197         $disable_on_admin = get_option( 'termageddon_usercentrics_disable_admin', false ) ? true : false;
    198         if ( $disable_on_admin && current_user_can( 'administrator' ) ) {
    199             return self::disable_termageddon_script();
    200         }
    201 
    202         if ( Termageddon_Usercentrics::is_geoip_enabled() && ! Termageddon_Usercentrics::is_ajax_mode_enabled() && Termageddon_Usercentrics::should_hide_due_to_location() ) {
    203             return self::disable_termageddon_script();
     188        // If forcibly enabled, bypass individual detections.
     189        if ( ! Termageddon_Usercentrics::is_enabled_via_get_override() ) {
     190            // Check for Disable for troubleshooting.
     191            if ( Termageddon_Usercentrics::is_disabled_for_troubleshooting() ) {
     192                return self::disable_termageddon_script();
     193            }
     194
     195            // Debug display to console if applicable.
     196            self::debug_display();
     197
     198            // Check for individual disable detections.
     199            $disable_on_logged_in = get_option( 'termageddon_usercentrics_disable_logged_in', false ) ? true : false;
     200            if ( $disable_on_logged_in && is_user_logged_in() ) {
     201                return self::disable_termageddon_script();
     202            }
     203
     204            $disable_on_editor = get_option( 'termageddon_usercentrics_disable_editor', false ) ? true : false;
     205            if ( $disable_on_editor && current_user_can( 'editor' ) ) {
     206                return self::disable_termageddon_script();
     207            }
     208
     209            $disable_on_admin = get_option( 'termageddon_usercentrics_disable_admin', false ) ? true : false;
     210            if ( $disable_on_admin && current_user_can( 'administrator' ) ) {
     211                return self::disable_termageddon_script();
     212            }
     213
     214            if ( Termageddon_Usercentrics::is_geoip_enabled() && ! Termageddon_Usercentrics::is_ajax_mode_enabled() && Termageddon_Usercentrics::should_hide_due_to_location() ) {
     215                return self::disable_termageddon_script();
     216            }
     217        } else {
     218            // Debug display to console if applicable.
     219            self::debug_display();
    204220        }
    205221
  • termageddon-usercentrics/trunk/public/js/termageddon-usercentrics-ajax.js

    r2890756 r3104855  
    1010        const parts = value.split(`; ${name}=`);
    1111        if (parts.length === 2) return parts.pop().split(";").shift();
     12    };
     13
     14    const getQueryParams = (param) => {
     15        const params = new Proxy(new URLSearchParams(window.location.search), {
     16            get: (searchParams, prop) => searchParams.get(prop),
     17        });
     18
     19        return params[param];
    1220    };
    1321
     
    5765    if (typeof UC_UI === "undefined")
    5866        return console.error("Usercentrics not loaded");
     67
     68    //Check query variable from browser
     69    const query_hide =
     70        getQueryParams("enable-usercentrics") === "" ? true : false;
    5971
    6072    //Check for local cookie to use instead of calling.
     
    133145                }
    134146
     147                if (query_hide) {
     148                    if (tuDebug)
     149                        console.log(
     150                            "UC: Enabling due to query parameter override.",
     151                            "Showing Usercentrics"
     152                        );
     153                    return updateCookieConsent(false);
     154                }
     155
    135156                //If you are not supposed to be hiding, show the CMP.
    136157                setCookie(tuCookieHideName, data.hide ? "true" : "false");
  • termageddon-usercentrics/trunk/public/js/termageddon-usercentrics-ajax.min.js

    r2890756 r3104855  
    1 const tuCookieHideName="tu-geoip-hide",tuDebug="true"===termageddon_usercentrics_obj.debug,tuPSLHide="true"===termageddon_usercentrics_obj.psl_hide;tuDebug&&console.log("UC: AJAX script initialized"),window.addEventListener("UC_UI_INITIALIZED",(function(){const getCookie=name=>{const value=`; ${document.cookie}`,parts=value.split(`; ${name}=`);if(2===parts.length)return parts.pop().split(";").shift()},setCookie=(name,value,days)=>{var expires="";if(days){var date=new Date;date.setTime(date.getTime()+24*days*60*60*1e3),expires="; expires="+date.toUTCString()}document.cookie=name+"="+(value||"")+expires+"; path=/"},updateCookieConsent=hide=>{if(!hide)return tuDebug&&console.log("UC: Showing consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").show(),jQuery("div#usercentrics-root").show(),UC_UI.isConsentRequired()?UC_UI.showFirstLayer():UC_UI.closeCMP();tuDebug&&console.log("UC: Hiding consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").hide(),jQuery("div#usercentrics-root").hide(),UC_UI.areAllConsentsAccepted()||UC_UI.acceptAllConsents().then(()=>{tuDebug&&console.log("UC: All consents have been accepted."),UC_UI.closeCMP().then(()=>{tuDebug&&console.log("UC: CMP Widget has been closed.")})})};if("undefined"==typeof UC_UI)return console.error("Usercentrics not loaded");const cookie_hide=getCookie("tu-geoip-hide");if(null==cookie_hide||tuDebug){tuDebug&&console.log("UC: Making AJAX Call");var data={action:"uc_geolocation_lookup",nonce:termageddon_usercentrics_obj.nonce};void 0!==termageddon_usercentrics_obj.location&&(data.location=termageddon_usercentrics_obj.location),jQuery.post(termageddon_usercentrics_obj.ajax_url,data).done((function(response){if(!response.success)return console.error("Unable to lookup location.",response.message||"");if(!response.data)return console.error("Location data was not provided.",response.data);const data=response.data;tuDebug&&console.log("TERMAGEDDON USERCENTRICS (AJAX)\nIP Address: "+data.ipAddress+"\nCity: "+(data.city||"Unknown")+"\nState: "+(data.state||"Unknown")+"\nCountry: "+(data.country||"Unknown")+"\n--\nLocated in EU?: "+(data.inEU?"Yes":"No")+"\nLocated in UK?: "+(data.inUK?"Yes":"No")+"\nLocated in Canada?: "+(data.inCanada?"Yes":"No")+"\nLocated in California?: "+(data.inCalifornia?"Yes":"No")+"\nLocated in Virginia?: "+(data.inVirginia?"Yes":"No")),setCookie("tu-geoip-hide",data.hide?"true":"false"),updateCookieConsent(data.hide)})).fail((function(response){console.error("Usercentrics: Invalid response returned. Showing widget as a default.",response),updateCookieConsent(!1)}))}else tuDebug&&console.log("UC: Cookie found.",(cookie_hide?"Showing":"Hiding")+" Usercentrics"),updateCookieConsent("true"===cookie_hide)}));
     1const tuCookieHideName="tu-geoip-hide",tuDebug="true"===termageddon_usercentrics_obj.debug,tuPSLHide="true"===termageddon_usercentrics_obj.psl_hide;tuDebug&&console.log("UC: AJAX script initialized"),window.addEventListener("UC_UI_INITIALIZED",(function(){const getCookie=name=>{const value=`; ${document.cookie}`,parts=value.split(`; ${name}=`);if(2===parts.length)return parts.pop().split(";").shift()},getQueryParams=param=>{const params=new Proxy(new URLSearchParams(window.location.search),{get:(searchParams,prop)=>searchParams.get(prop)});return params[param]},setCookie=(name,value,days)=>{var expires="";if(days){var date=new Date;date.setTime(date.getTime()+24*days*60*60*1e3),expires="; expires="+date.toUTCString()}document.cookie=name+"="+(value||"")+expires+"; path=/"},updateCookieConsent=hide=>{if(!hide)return tuDebug&&console.log("UC: Showing consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").show(),jQuery("div#usercentrics-root").show(),UC_UI.isConsentRequired()?UC_UI.showFirstLayer():UC_UI.closeCMP();tuDebug&&console.log("UC: Hiding consent widget"),tuPSLHide&&jQuery("#usercentrics-psl, .usercentrics-psl").hide(),jQuery("div#usercentrics-root").hide(),UC_UI.areAllConsentsAccepted()||UC_UI.acceptAllConsents().then(()=>{tuDebug&&console.log("UC: All consents have been accepted."),UC_UI.closeCMP().then(()=>{tuDebug&&console.log("UC: CMP Widget has been closed.")})})};if("undefined"==typeof UC_UI)return console.error("Usercentrics not loaded");const query_hide=""===getQueryParams("enable-usercentrics"),cookie_hide=getCookie("tu-geoip-hide");if(null==cookie_hide||tuDebug){tuDebug&&console.log("UC: Making AJAX Call");var data={action:"uc_geolocation_lookup",nonce:termageddon_usercentrics_obj.nonce};void 0!==termageddon_usercentrics_obj.location&&(data.location=termageddon_usercentrics_obj.location),jQuery.post(termageddon_usercentrics_obj.ajax_url,data).done((function(response){if(!response.success)return console.error("Unable to lookup location.",response.message||"");if(!response.data)return console.error("Location data was not provided.",response.data);const data=response.data;if(tuDebug&&console.log("TERMAGEDDON USERCENTRICS (AJAX)\nIP Address: "+data.ipAddress+"\nCity: "+(data.city||"Unknown")+"\nState: "+(data.state||"Unknown")+"\nCountry: "+(data.country||"Unknown")+"\n--\nLocated in EU?: "+(data.inEU?"Yes":"No")+"\nLocated in UK?: "+(data.inUK?"Yes":"No")+"\nLocated in Canada?: "+(data.inCanada?"Yes":"No")+"\nLocated in California?: "+(data.inCalifornia?"Yes":"No")+"\nLocated in Virginia?: "+(data.inVirginia?"Yes":"No")),query_hide)return tuDebug&&console.log("UC: Enabling due to query parameter override.","Showing Usercentrics"),updateCookieConsent(!1);setCookie("tu-geoip-hide",data.hide?"true":"false"),updateCookieConsent(data.hide)})).fail((function(response){console.error("Usercentrics: Invalid response returned. Showing widget as a default.",response),updateCookieConsent(!1)}))}else tuDebug&&console.log("UC: Cookie found.",(cookie_hide?"Showing":"Hiding")+" Usercentrics"),updateCookieConsent("true"===cookie_hide)}));
  • termageddon-usercentrics/trunk/termageddon-usercentrics.php

    r3060868 r3104855  
    1515 * Plugin Name:       Termageddon + Usercentrics
    1616 * Description:       Easily integrate the Usercentrics consent solution into your website while controlling visibility for logged in users and admins.
    17  * Version:           1.4.0
     17 * Version:           1.4.1
    1818 * Author:            Termageddon
    1919 * Author URI:        https://termageddon.com
     
    3434 * Rename this for your plugin and update it as you release new versions.
    3535 */
    36 define( 'TERMAGEDDON_COOKIE_VERSION', '1.4.0' );
     36define( 'TERMAGEDDON_COOKIE_VERSION', '1.4.1' );
    3737
    3838define( 'TERMAGEDDON_COOKIE_PLUGIN_PATH', dirname( __FILE__ ) );// No trailing slash.
Note: See TracChangeset for help on using the changeset viewer.