@@ -190,12 +190,50 @@ public function loadTextDomain() {
190
190
/**
191
191
* Activate the plugin
192
192
*/
193
- public function activate () {
193
+ public function activate ( $ network_wide ) {
194
+ if ( is_multisite () && $ network_wide ) {
195
+ foreach ( get_sites ( array ( 'fields ' => 'ids ' ) ) as $ blog_id ) {
196
+ switch_to_blog ( $ blog_id );
197
+ $ this ->activate_on_site ();
198
+ restore_current_blog ();
199
+ }
200
+ } else {
201
+ $ this ->activate_on_site ();
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Activates the plugin on a particular blog instance (supports multisite and single site).
207
+ */
208
+ private function activate_on_site () {
194
209
wp_clear_scheduled_hook ( 'visualizer_schedule_refresh_db ' );
195
210
wp_schedule_event ( strtotime ( 'midnight ' ) - get_option ( 'gmt_offset ' ) * HOUR_IN_SECONDS , 'hourly ' , 'visualizer_schedule_refresh_db ' );
196
211
add_option ( 'visualizer-activated ' , true );
197
212
}
198
213
214
+ /**
215
+ * Deactivate the plugin
216
+ */
217
+ public function deactivate ( $ network_wide ) {
218
+ if ( is_multisite () && $ network_wide ) {
219
+ foreach ( get_sites ( array ( 'fields ' => 'ids ' ) ) as $ blog_id ) {
220
+ switch_to_blog ( $ blog_id );
221
+ $ this ->deactivate_on_site ();
222
+ restore_current_blog ();
223
+ }
224
+ } else {
225
+ $ this ->deactivate_on_site ();
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Deactivates the plugin on a particular blog instance (supports multisite and single site).
231
+ */
232
+ private function deactivate_on_site () {
233
+ wp_clear_scheduled_hook ( 'visualizer_schedule_refresh_db ' );
234
+ delete_option ( 'visualizer-activated ' , true );
235
+ }
236
+
199
237
/**
200
238
* Check if plugin has been activated and then redirect to the correct page.
201
239
*/
@@ -218,14 +256,6 @@ public function adminInit() {
218
256
}
219
257
220
258
221
- /**
222
- * Deactivate the plugin
223
- */
224
- public function deactivate () {
225
- wp_clear_scheduled_hook ( 'visualizer_schedule_refresh_db ' );
226
- delete_option ( 'visualizer-activated ' , true );
227
- }
228
-
229
259
/**
230
260
* Refresh the specific chart from the db.
231
261
*
0 commit comments