Skip to content

Commit

Permalink
Multisite: Better invalidation
Browse files Browse the repository at this point in the history
See: #37
  • Loading branch information
kovshenin committed Feb 3, 2024
1 parent 4e7a6fe commit 54f57a6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions include/invalidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
expire( sprintf( 'post:%d:%d', $blog_id, $post_id ) );
}, 10, 2 );

// Multisite network/blog flags.
add_action( 'init', function() {
if ( is_multisite() ) {
flag( sprintf( 'network:%d:%d', get_current_network_id(), get_current_blog_id() ) );
}
} );

// Last-minute expirations, save flags.
add_action( 'shutdown', function() {
$flush_actions = [
Expand All @@ -117,13 +124,28 @@
'update_option_page_for_posts',
'update_option_posts_per_page',
'update_option_woocommerce_permalinks',
'automatic_updates_complete',
'_core_updated_successfully',
];

$flush_actions = apply_filters( 'surge_flush_actions', $flush_actions );

$ms_flush_actions = [
'_core_updated_successfully',
'automatic_updates_complete',
];

$expire_flag = is_multisite()
? sprintf( 'network:%d:%d', get_current_network_id(), get_current_blog_id() )
: '/';

foreach ( $flush_actions as $action ) {
if ( did_action( $action ) ) {
expire( $expire_flag );
break;
}
}

// Multisite flush actions expire the entire network.
foreach ( $ms_flush_actions as $action ) {
if ( did_action( $action ) ) {
expire( '/' );
break;
Expand Down

0 comments on commit 54f57a6

Please sign in to comment.