Skip to content

Commit

Permalink
Promote with Blaze: Purge cache on Atomic sites when site visibility …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
BogdanUngureanu authored Dec 19, 2024
1 parent 129f0de commit 354fbd4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Purge the cache when the site visibility changes on Atomic sites
54 changes: 54 additions & 0 deletions projects/plugins/wpcomsh/feature-plugins/blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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' );
}
);

0 comments on commit 354fbd4

Please sign in to comment.