ComingSoonAdminBarBadge.php
1 year ago
ComingSoonCacheInvalidator.php
1 year ago
ComingSoonHelper.php
1 year ago
ComingSoonRequestHandler.php
9 months ago
ComingSoonCacheInvalidator.php
44 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Internal\ComingSoon; |
| 3 | |
| 4 | /** |
| 5 | * Adds hooks to invalidate caches when the coming soon settings are changed. |
| 6 | */ |
| 7 | class ComingSoonCacheInvalidator { |
| 8 | |
| 9 | /** |
| 10 | * Sets up the hooks. |
| 11 | * |
| 12 | * @internal |
| 13 | */ |
| 14 | final public function init() { |
| 15 | add_action( 'update_option_woocommerce_coming_soon', array( $this, 'invalidate_caches' ) ); |
| 16 | add_action( 'update_option_woocommerce_store_pages_only', array( $this, 'invalidate_caches' ) ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Invalidate the WordPress object cache and other known caches. |
| 21 | * |
| 22 | * @internal |
| 23 | */ |
| 24 | public function invalidate_caches() { |
| 25 | // Standard WordPress object cache invalidation. |
| 26 | wp_cache_flush(); |
| 27 | |
| 28 | /** |
| 29 | * Temporary solution to invalidate the WordPress.com Edge Cache. We can trigger |
| 30 | * invalidation by publishing any post. It should be refactored with a supported integration. |
| 31 | */ |
| 32 | $cart_page_id = get_option( 'woocommerce_cart_page_id' ) ?? null; |
| 33 | if ( $cart_page_id ) { |
| 34 | // Re-publish the coming soon page. Has the side-effect of invalidating the Edge Cache. |
| 35 | wp_update_post( |
| 36 | array( |
| 37 | 'ID' => $cart_page_id, |
| 38 | 'post_status' => 'publish', |
| 39 | ) |
| 40 | ); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |