Skip to content

Commit 7ecb072

Browse files
Merge pull request #779 from contactashish13/issue-285-pro
Periodic data synchronization option does not work on WP Multisite (only Live option works)
2 parents 859396d + 988cfe6 commit 7ecb072

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

classes/Visualizer/Module/Setup.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,50 @@ public function loadTextDomain() {
190190
/**
191191
* Activate the plugin
192192
*/
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() {
194209
wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' );
195210
wp_schedule_event( strtotime( 'midnight' ) - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 'hourly', 'visualizer_schedule_refresh_db' );
196211
add_option( 'visualizer-activated', true );
197212
}
198213

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+
199237
/**
200238
* Check if plugin has been activated and then redirect to the correct page.
201239
*/
@@ -218,14 +256,6 @@ public function adminInit() {
218256
}
219257

220258

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-
229259
/**
230260
* Refresh the specific chart from the db.
231261
*

0 commit comments

Comments
 (0)