ESI not working
-
Hello! I can’t seem to get this code placed inside functions.php to be excluded from cache with ESI.
Code works as it should when LiteSpeed Cache is disabled.
Any help please?
– LiteSpeed Server at Oderland.
– ESI is enabled in plugin and server.
Thanks!add_action('litespeed_esi_load-custom_js_block', 'custom_js_block_load'); function custom_js_block_load() { do_action('litespeed_control_set_nocache'); // Ensures this block isn't cached ?> <script type="text/javascript"> window.addEventListener('beforeunload', function(e) { e.preventDefault(); e.returnValue = ''; var confirmationMessage = '?r du s?ker p? att du vill l?mna sidan?'; e.returnValue = confirmationMessage; return confirmationMessage; }); </script> <?php } function add_custom_js() { $ipList = [ '192.168.0.*', '192.168.1.*', ]; $userIp = $_SERVER['REMOTE_ADDR']; $matchFound = false; foreach ($ipList as $ipEntity) { if (ipMatch($userIp, $ipEntity)) { $matchFound = true; setcookie('poc', '1', time() + 31536000, '/'); break; } } if (!$matchFound && (!isset($_COOKIE['poc']) || $_COOKIE['poc'] != '1')) { return; } echo apply_filters('litespeed_esi_url', 'custom_js_block', 'Custom JS Block'); } add_action('wp_footer', 'add_custom_js'); function ipMatch($userIp, $ipEntity) { $userSegments = explode('.', $userIp); $entitySegments = explode('.', $ipEntity); $numSegments = count($userSegments); for ($i = 0; $i < $numSegments; $i++) { if ($entitySegments[$i] === '*') { continue; } if ($userSegments[$i] !== $entitySegments[$i]) { return false; } } return true; }
- The topic ‘ESI not working’ is closed to new replies.