| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | |
| 4 | 4 | class CloudflarePageCache extends berqIntegrations { |
| 5 | 5 | function __construct() { |
| 6 | 6 | add_action('berqwp_flush_all_cache', [$this, 'flush_cache']); |
| 7 | - add_action('berqwp_stored_page_cache', [$this, 'flush_cache']); | |
| 7 | + add_action('berqwp_stored_page_cache', [$this, 'flush_page_cache']); | |
| 8 | 8 | add_action('berqwp_flush_page_cache', [$this, 'flush_cache']); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function flush_cache() { |
| @@ -11,8 +11,20 @@ | ||
| 11 | 11 | function flush_cache() { |
| 12 | 12 | if (class_exists('SW_CLOUDFLARE_PAGECACHE') && isset($GLOBALS['sw_cloudflare_pagecache'])) { |
| 13 | 13 | $GLOBALS['sw_cloudflare_pagecache']->objects['cache_controller']->purge_all(); |
| 14 | 14 | } |
| 15 | + } | |
| 16 | + | |
| 17 | + function flush_page_cache($slug) { | |
| 18 | + if (!class_exists('SW_CLOUDFLARE_PAGECACHE') || !isset($GLOBALS['sw_cloudflare_pagecache'])) { | |
| 19 | + return; | |
| 20 | + } | |
| 21 | + | |
| 22 | + if (empty($slug)) { | |
| 23 | + $slug = '/'; | |
| 24 | + } | |
| 25 | + | |
| 26 | + $GLOBALS['sw_cloudflare_pagecache']->objects['cache_controller']->purge_url(home_url($slug)); | |
| 15 | 27 | } |
| 16 | 28 | } |
| 17 | 29 | |
| 18 | 30 | new CloudflarePageCache(); |