PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.8.1
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.8.1
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / Integration / Plugin / GeoTargetingWP.php
nitropack / classes / Integration / Plugin Last commit date
AdvancedMathCaptcha.php 3 years ago AeliaCurrencySwitcher.php 3 years ago BeaverBuilder.php 4 years ago CF_Helper.php 3 years ago Cloudflare.php 2 years ago CommonHelpers.php 3 years ago CookieNotice.php 4 years ago DownloadManager.php 4 years ago Elementor.php 3 years ago Ezoic.php 4 years ago FusionBuilder.php 4 years ago GeoTargetingWP.php 3 years ago GravityForms.php 3 years ago JetPackNP.php 3 years ago NginxHelper.php 2 years ago RC.php 3 years ago RankMathNP.php 3 years ago RocketNet_Helper.php 4 years ago ShortPixel.php 4 years ago SquirrlySEO.php 3 years ago TheEventsCalendar.php 3 years ago ThriveTheme.php 4 years ago WCML.php 3 years ago WPBakeryNP.php 3 years ago WPCacheHelper.php 3 years ago WPForms.php 3 years ago WPRocket.php 4 years ago Woocommerce.php 4 years ago WoocommerceCacheHandler.php 4 years ago YoastSEO.php 3 years ago
GeoTargetingWP.php
94 lines
1 <?php
2
3 namespace NitroPack\Integration\Plugin;
4
5 class GeoTargetingWP {
6 const STAGE = "very_early";
7 const allGeoWpCookies = ['geot_country', 'geot_state', 'geot_city'];
8 const defaultVariationCookies = ['geot_country'];
9
10 public static function isActive() {
11 return defined("GEOWP_VERSION");
12 }
13
14 public function init($stage) {
15 $siteConfig = get_nitropack()->getSiteConfig();
16 $geotSettings = null;
17
18 if (empty($siteConfig["isGeoTargetingWPActive"])) {
19 return true;
20 }
21
22 // no need for variation cookies with GEOWP if using Ajax mode
23 if (function_exists( 'geot_settings' )) {
24 $geotSettings = geot_settings();
25 } elseif (function_exists('get_option')) {
26 $geotSettings = apply_filters( 'geot/settings_page/opts', get_option( 'geot_settings' ) );
27 }
28 if (!empty($geotSettings) && $geotSettings['ajax_mode'] == "1") {
29 return true;
30 }
31
32 // enable geot cookies
33 add_filter( 'geot/enable_cookies', '__return_true');
34
35 // require geot cookies for serving cache
36 add_filter("nitropack_passes_cookie_requirements", [$this, "hasGeoTargetingWpCookies"]);
37
38 // serve cache after geowp has added geot cookies
39 add_action('init', function() {
40 nitropack_handle_request('geotargetingwp');
41 }, 16);
42
43 add_action('np_set_cookie_filter', function() {
44 \NitroPack\SDK\NitroPack::addCookieFilter([$this, "filterCookies"]);
45 });
46
47 return true;
48 }
49
50 public static function getCustomVariationCookies() {
51 $enabledCookies = self::defaultVariationCookies;
52 // apply_filter() is unavailable at stage 'very_early'
53 // $enabledCookies = apply_filter("nitropack_geotargetingwp_enabled_cookies", self::defaultVariationCookies);
54 return array_intersect(self::allGeoWpCookies, $enabledCookies);
55 }
56
57 public static function configureVariationCookies() {
58 $siteConfig = get_nitropack()->getSiteConfig();
59
60 if (empty($siteConfig["isGeoTargetingWPActive"])) {
61 removeVariationCookies(self::allGeoWpCookies);
62 return true;
63 }
64
65 // standard cookie integration
66 initVariationCookies(self::getCustomVariationCookies());
67 }
68
69 public function hasGeoTargetingWpCookies($currentState) {
70 $allCookies = array_merge($_COOKIE, getNewCookies());
71 $neededCookies = self::getCustomVariationCookies();
72
73 foreach($neededCookies as $c) {
74 if (!empty($allCookies[$c])) {
75 $neededCookies = array_diff($neededCookies, [$c]);
76 }
77 }
78
79 if (!empty($neededCookies)) {
80 return false;
81 }
82 return $currentState;
83 }
84
85 public function filterCookies(&$cookies) {
86 foreach (self::getCustomVariationCookies() as $cookieName) {
87 $newlySetCookie = getNewCookie($cookieName);
88 if (empty($_COOKIE[$cookieName]) && !empty($newlySetCookie)) {
89 $cookies[$cookieName] = $newlySetCookie;
90 }
91 }
92 }
93 }
94