$value) { if (strpos($name, $prefix) === 0) { $_wp_recache_exited = true; return; } } } else { if (isset($_COOKIE[$cookie])) { $_wp_recache_exited = true; return; } } } '; $tmp = sys_get_temp_dir() . '/wp-recache-test-' . getmypid(); if (!is_dir($tmp)) { mkdir($tmp, 0777, true); } $file = $tmp . '/dropin.php'; file_put_contents($file, $content); return $file; } function test(string $name, array $cookies, array $request, array $server, bool $expect_exited): void { global $pass, $fail; $_COOKIE = $request; $_SERVER = array_merge([ 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '/test/', 'HTTP_HOST' => 'example.com', ], $server); $_wp_recache_exited = false; $file = write_test_dropin($cookies); include $file; @unlink($file); if ($_wp_recache_exited !== $expect_exited) { echo " FAIL: $name\n"; echo " expected " . ($expect_exited ? 'exited' : 'fell through') . ", got " . ($_wp_recache_exited ? 'exited' : 'fell through') . "\n"; $fail++; } else { echo " PASS: $name\n"; $pass++; } } $defaults = [ 'woocommerce_items_in_cart', 'wp_woocommerce_session_*', 'wp-postpass', 'comment_author_*', 'wordpress_*', ]; echo "=== Exact match ===\n"; test('wp-postpass present → exits', $defaults, ['wp-postpass' => 'abc123'], [], true); test('woocommerce_items_in_cart present → exits', $defaults, ['woocommerce_items_in_cart' => 'yes'], [], true); echo "\n=== Prefix match ===\n"; test('comment_author_12345 matches comment_author_*', $defaults, ['comment_author_12345' => 'test'], [], true); test('wp_woocommerce_session_abc matches wp_woocommerce_session_*', $defaults, ['wp_woocommerce_session_abc123' => 'xyz'], [], true); test('wordpress_logged_in_xyz matches wordpress_*', $defaults, ['wordpress_logged_in_xyz' => '1'], [], true); echo "\n=== No match → falls through ===\n"; test('unrelated cookie → falls through', $defaults, ['session_id' => 'abc123'], [], false); test('empty cookies → falls through', $defaults, [], [], false); echo "\n=== Edge cases ===\n"; test('whitespace-only cookie name skipped', array_merge([' '], $defaults), ['wp-postpass' => 'val'], [], true); test('empty rejected list → falls through', [], ['anything' => '1'], [], false); echo "\n=== POST method → exits before cookie check ===\n"; test('POST request exits early', $defaults, ['wp-postpass' => 'val'], ['REQUEST_METHOD' => 'POST'], true); echo "\n=== Query string → exits before cookie check ===\n"; test('Query string present exits early', $defaults, ['wp-postpass' => 'val'], ['QUERY_STRING' => 'foo=bar'], true); $tmp = sys_get_temp_dir() . '/wp-recache-test-' . getmypid(); @rmdir($tmp); echo "\n--- Results: $pass passed, $fail failed ---\n"; exit($fail > 0 ? 1 : 0);