feat: rejected-cookie cache exclusions for WooCommerce cart

Add wp_recache_rejected_cookies option (defaults: woocommerce_items_in_cart,
wp_woocommerce_session_*, wp-postpass, comment_author_*, wordpress_*) that
bypasses page cache when any listed cookie is present. Both the WP-level
check (wp_recache_should_exclude) and the standalone drop-in apply the
same exact/prefix matching logic. Editing the option regenerates the
drop-in and purges all cache.
This commit is contained in:
2026-09-13 15:43:20 +02:00
parent 43081d6e5d
commit 65657276f6
7 changed files with 206 additions and 4 deletions
+34
View File
@@ -52,4 +52,38 @@ class WP_Recache_Admin_Test extends WP_UnitTestCase {
$this->assertGreaterThanOrEqual(2, $stats['files']);
}
public function test_sanitize_rejected_cookies_trims_whitespace() {
$admin = new WP_Recache_Admin();
$result = $admin->sanitize_rejected_cookies(" wp-postpass \n comment_author_* ");
$this->assertEquals(['wp-postpass', 'comment_author_*'], $result);
}
public function test_sanitize_rejected_cookies_filters_empty_lines() {
$admin = new WP_Recache_Admin();
$result = $admin->sanitize_rejected_cookies("wp-postpass\n\n\ncomment_author_*\n");
$this->assertEquals(['wp-postpass', 'comment_author_*'], $result);
}
public function test_sanitize_rejected_cookies_handles_array_input() {
$admin = new WP_Recache_Admin();
$result = $admin->sanitize_rejected_cookies(['wp-postpass', 'comment_author_*']);
$this->assertEquals(['wp-postpass', 'comment_author_*'], $result);
}
public function test_rejected_cookies_option_is_registered() {
$admin = new WP_Recache_Admin();
$admin->init();
do_action('admin_init');
$default = [
'woocommerce_items_in_cart',
'wp_woocommerce_session_*',
'wp-postpass',
'comment_author_*',
'wordpress_*',
];
$this->assertEquals($default, get_option('wp_recache_rejected_cookies', $default));
}
}