Skip to content

Commit 9076a62

Browse files
authored
Support network-wide activation/deactivation in multisite (#2104)
1 parent 37b9d7f commit 9076a62

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
When activated or deactivated network-wide, the plugin now refreshes rewrite rules across all sites.

includes/class-activitypub.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,46 @@ public static function init() {
5959

6060
/**
6161
* Activation Hook.
62+
*
63+
* @param bool $network_wide Whether to activate the plugin for all sites in the network or just the current site.
6264
*/
63-
public static function activate() {
65+
public static function activate( $network_wide ) {
6466
self::flush_rewrite_rules();
6567
Scheduler::register_schedules();
6668

6769
\add_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ), 10, 3 );
6870
Migration::update_comment_counts();
71+
72+
if ( \is_multisite() && $network_wide && ! \wp_is_large_network() ) {
73+
$sites = \get_sites( array( 'fields' => 'ids' ) );
74+
foreach ( $sites as $site ) {
75+
\switch_to_blog( $site );
76+
self::flush_rewrite_rules();
77+
\restore_current_blog();
78+
}
79+
}
6980
}
7081

7182
/**
7283
* Deactivation Hook.
84+
*
85+
* @param bool $network_wide Whether to deactivate the plugin for all sites in the network or just the current site.
7386
*/
74-
public static function deactivate() {
87+
public static function deactivate( $network_wide ) {
7588
self::flush_rewrite_rules();
7689
Scheduler::deregister_schedules();
7790

7891
\remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ) );
7992
Migration::update_comment_counts( 2000 );
93+
94+
if ( \is_multisite() && $network_wide && ! \wp_is_large_network() ) {
95+
$sites = \get_sites( array( 'fields' => 'ids' ) );
96+
foreach ( $sites as $site ) {
97+
\switch_to_blog( $site );
98+
self::flush_rewrite_rules();
99+
\restore_current_blog();
100+
}
101+
}
80102
}
81103

82104
/**

0 commit comments

Comments
 (0)