Instantly share code, notes, and snippets.
Created
July 22, 2026 11:42
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save xlplugins/7d7f79fe52583ca0ba793afc4494857e to your computer and use it in GitHub Desktop.
BWF Cookie Round-Trip Probe (temporary)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: BWF Cookie Round-Trip Probe (temporary) | |
| * Description: Diagnostic for "cookies exist in the browser but do not reach the server". | |
| * With ?bwf_debug=1 on any front-end URL it: (1) sets a probe cookie via document.cookie | |
| * exactly like utm-tracker.js, (2) prints the browser's cookies ON THE PAGE (works in | |
| * mobile in-app browsers with no console), (3) shows a button that fires a GENERIC | |
| * WordPress AJAX request and prints what cookies the SERVER received on that request. | |
| * If the browser has the cookie but the AJAX call does not deliver it, that is an | |
| * environment/hosting problem, reproducible on a plain WP endpoint with no plugin involved. | |
| * | |
| * DEPLOY: wp-content/mu-plugins/bwf-cookie-probe.php | |
| * READ : on-page panel, plus WooCommerce > Status > Logs -> source "bwf-cookie-probe" | |
| * REMOVE once confirmed. | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| /** | |
| * Generic WordPress AJAX endpoint. It belongs to no funnel plugin — it simply reports which cookies | |
| * arrived with the request. If cookies are missing here, the problem is not FunnelKit-specific. | |
| */ | |
| function bwf_cookie_probe_ajax() { | |
| $names = array_keys( (array) $_COOKIE ); // phpcs:ignore | |
| $wffn = array_values( | |
| array_filter( | |
| $names, | |
| function ( $k ) { | |
| return 0 === strpos( $k, 'wffn_' ); | |
| } | |
| ) | |
| ); | |
| $probe = isset( $_COOKIE['bwf_probe'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['bwf_probe'] ) ) : '*** MISSING ***'; // phpcs:ignore | |
| $resp = array( | |
| 'bwf_probe' => $probe, | |
| 'wffn_cookies' => $wffn, | |
| 'total_cookies' => count( $names ), | |
| 'all_names' => $names, | |
| ); | |
| $logger = function_exists( 'wc_get_logger' ) ? wc_get_logger() : null; | |
| if ( $logger ) { | |
| $logger->info( | |
| "GENERIC AJAX — cookies received\nbwf_probe: {$probe}\nwffn_*: " . ( empty( $wffn ) ? '*** NONE ***' : implode( ', ', $wffn ) ) . "\ntotal: " . count( $names ) . "\nall: " . implode( ', ', $names ) . "\nua: " . ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '' ), // phpcs:ignore | |
| array( 'source' => 'bwf-cookie-probe' ) | |
| ); | |
| } | |
| wp_send_json( $resp ); | |
| } | |
| add_action( 'wp_ajax_bwf_cookie_probe_check', 'bwf_cookie_probe_ajax' ); | |
| add_action( 'wp_ajax_nopriv_bwf_cookie_probe_check', 'bwf_cookie_probe_ajax' ); | |
| /** | |
| * On-page probe panel, shown only when ?bwf_debug=1 is present. | |
| */ | |
| add_action( | |
| 'wp_footer', | |
| function () { | |
| if ( is_admin() ) { | |
| return; | |
| } | |
| if ( ! isset( $_GET['bwf_debug'] ) || '1' !== (string) $_GET['bwf_debug'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| return; | |
| } | |
| $ajax_url = esc_url( admin_url( 'admin-ajax.php' ) ); | |
| ?> | |
| <div id="bwf-probe" style="position:fixed;left:0;right:0;bottom:0;z-index:2147483647;max-height:70vh;overflow:auto;background:#0b1020;color:#d6e2ff;font:13px/1.5 -apple-system,BlinkMacSystemFont,monospace;padding:14px;border-top:3px solid #4d7cff"> | |
| <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:10px"> | |
| <strong style="color:#8fb3ff">BWF COOKIE PROBE</strong> | |
| <button type="button" onclick="document.getElementById('bwf-probe').remove()" style="background:#26305a;color:#d6e2ff;border:0;border-radius:6px;padding:6px 12px">close</button> | |
| </div> | |
| <div style="color:#ffd479;margin-bottom:2px">1) Cookies in this browser (document.cookie)</div> | |
| <pre id="bwf-probe-browser" style="margin:0 0 12px;white-space:pre-wrap;word-break:break-all">…</pre> | |
| <button id="bwf-probe-btn" type="button" style="width:100%;background:#4d7cff;color:#fff;border:0;border-radius:8px;padding:12px;font-size:15px;font-weight:600;margin-bottom:12px">2) Send test AJAX to server →</button> | |
| <div style="color:#ffd479;margin-bottom:2px">3) Cookies the SERVER received on that AJAX request</div> | |
| <pre id="bwf-probe-server" style="margin:0 0 12px;white-space:pre-wrap;word-break:break-all">(tap the button above)</pre> | |
| <div id="bwf-probe-verdict" style="font-weight:700;padding:10px;border-radius:6px;background:#171e38"></div> | |
| </div> | |
| <script type="text/javascript"> | |
| (function () { | |
| // Set the probe cookie the SAME way utm-tracker.js does (document.cookie). | |
| try { | |
| if (document.cookie.indexOf('bwf_probe=') === -1) { | |
| var host = location.hostname.replace(/^www\./, ''); | |
| var value = 'set@' + Math.floor(Date.now() / 1000) + '_' + Math.random().toString(36).slice(2, 10); | |
| var exp = new Date(); | |
| exp.setTime(exp.getTime() + 2 * 24 * 60 * 60 * 1000); | |
| document.cookie = 'bwf_probe=' + value + ';expires=' + exp.toUTCString() + ';domain=.' + host + ';path=/'; | |
| } | |
| } catch (e) {} | |
| function showBrowser() { | |
| var el = document.getElementById('bwf-probe-browser'); | |
| el.textContent = document.cookie ? document.cookie.split(';').map(function (c) { return c.trim(); }).join('\n') : '(empty)'; | |
| } | |
| showBrowser(); | |
| document.getElementById('bwf-probe-btn').addEventListener('click', function () { | |
| var out = document.getElementById('bwf-probe-server'); | |
| var verdict = document.getElementById('bwf-probe-verdict'); | |
| out.textContent = 'sending…'; | |
| verdict.textContent = ''; | |
| showBrowser(); | |
| fetch('<?php echo $ajax_url; ?>?action=bwf_cookie_probe_check', { | |
| method: 'POST', | |
| credentials: 'same-origin' // send cookies, exactly like a normal jQuery AJAX | |
| }) | |
| .then(function (r) { return r.json(); }) | |
| .then(function (d) { | |
| out.textContent = JSON.stringify(d, null, 2); | |
| var browserHas = document.cookie.indexOf('bwf_probe=') !== -1; | |
| var serverHas = d && typeof d.bwf_probe === 'string' && d.bwf_probe.indexOf('***') === -1; | |
| if (browserHas && !serverHas) { | |
| verdict.textContent = 'RESULT: Browser HAS the cookie, but the AJAX request delivered NONE of it to the server. Cookies are not reaching the server on this site.'; | |
| verdict.style.color = '#ff6b6b'; | |
| } else if (browserHas && serverHas) { | |
| verdict.textContent = 'RESULT: Cookie was delivered to the server on the AJAX request. Cookies are working normally.'; | |
| verdict.style.color = '#51cf66'; | |
| } else { | |
| verdict.textContent = 'RESULT: The cookie is not in the browser either — it was never stored.'; | |
| verdict.style.color = '#ffd479'; | |
| } | |
| }) | |
| .catch(function (e) { out.textContent = 'AJAX error: ' + e; }); | |
| }); | |
| })(); | |
| </script> | |
| <?php | |
| }, | |
| 9999 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment