From 354fbd46b5f4dbc5e87e3e24a2df4a7dadbe500e Mon Sep 17 00:00:00 2001 From: Bogdan Ungureanu Date: Thu, 19 Dec 2024 15:20:03 +0200 Subject: [PATCH] Promote with Blaze: Purge cache on Atomic sites when site visibility changes (#40650) * Promote with Blaze: Purge cache on Atomic sites when site visibility changes * Linting * Linting... * Enable the quicklink from wpcomsh * Fix linting * Add guard * Remove changelog for Jetpack --- .../changelog/fix-atomic-promote-with-blaze | 4 ++ .../plugins/wpcomsh/feature-plugins/blaze.php | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 projects/plugins/wpcomsh/changelog/fix-atomic-promote-with-blaze diff --git a/projects/plugins/wpcomsh/changelog/fix-atomic-promote-with-blaze b/projects/plugins/wpcomsh/changelog/fix-atomic-promote-with-blaze new file mode 100644 index 0000000000000..8841c588231a2 --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/fix-atomic-promote-with-blaze @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Purge the cache when the site visibility changes on Atomic sites diff --git a/projects/plugins/wpcomsh/feature-plugins/blaze.php b/projects/plugins/wpcomsh/feature-plugins/blaze.php index 1c269f7e9fe43..a680f185664bb 100644 --- a/projects/plugins/wpcomsh/feature-plugins/blaze.php +++ b/projects/plugins/wpcomsh/feature-plugins/blaze.php @@ -6,6 +6,8 @@ * @package wpcomsh */ +use Automattic\Jetpack\Connection\Manager as Jetpack_Connection; + /** * Activate the Blaze module * If you use a version of Jetpack that supports it, @@ -61,5 +63,57 @@ function wpcomsh_activate_blaze_module_on_launching( $old_value, $new_value ) { if ( $blog_public === 1 ) { wpcomsh_activate_blaze_module(); } + + return $new_value; } add_filter( 'update_option_blog_public', 'wpcomsh_activate_blaze_module_on_launching', 10, 2 ); + +/** + * Delete the transient for the given site id. + * + * @return void + */ +function wpcomsh_blaze_purge_transient_cache() { + $site_id = Jetpack_Connection::get_site_id(); + + if ( is_wp_error( $site_id ) ) { + return; + } + + $transient = 'jetpack_blaze_site_supports_blaze_' . $site_id; + delete_transient( $transient ); +} + +/** + * Delete the caching transient when coming soon is changed. + */ +add_action( + 'pre_update_option_wpcom_public_coming_soon', + function ( $option ) { + wpcomsh_blaze_purge_transient_cache(); + return $option; + } +); + +/** + * Delete the caching transient when the blog visibility option changes. + */ +add_action( + 'pre_update_option_blog_public', + function ( $option ) { + wpcomsh_blaze_purge_transient_cache(); + return $option; + } +); + +/** + * On Atomic sites the Promote with Blaze option is enabled. + * + * @phan-suppress PhanUndeclaredFunctionInCallable -- jetpack_blaze_post_row_actions_disable is part of jetpack. + */ +add_action( + 'jetpack_modules_loaded', + function () { + remove_filter( 'jetpack_blaze_post_row_actions_enable', 'jetpack_blaze_post_row_actions_disable' ); + } +);