| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Util; |
| 4 | 4 | |
| 5 | +if (!defined('ABSPATH')) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | /** |
| 6 | 10 | * Class handling plugin deactivation. |
| 7 | 11 | * |
| 8 | 12 | * @since 1.0.0 |
| @@ -8,19 +12,41 @@ | ||
| 8 | 12 | * @since 1.0.0 |
| 9 | 13 | * @access private |
| 10 | 14 | * @ignore |
| 11 | 15 | */ |
| 12 | -final class Deactivation { | |
| 16 | +final class Deactivation | |
| 17 | +{ | |
| 13 | 18 | /** |
| 14 | 19 | * Registers functionality through WordPress hooks. |
| 15 | 20 | * |
| 16 | 21 | * @since 1.0.0 |
| 17 | 22 | */ |
| 18 | - public function register() { | |
| 23 | + public function register() | |
| 24 | + { | |
| 19 | 25 | add_action('bitforms_deactivation', [$this, 'deactive']); |
| 20 | 26 | } |
| 21 | 27 | |
| 22 | - public function deactive() { | |
| 28 | + // handle deactivation tasks with multisite support | |
| 29 | + public function deactive($network_wide) | |
| 30 | + { | |
| 31 | + if ($network_wide && \function_exists('is_multisite') && is_multisite()) { | |
| 32 | + global $wpdb; | |
| 33 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); | |
| 34 | + foreach ($blog_ids as $blog_id) { | |
| 35 | + switch_to_blog($blog_id); | |
| 36 | + $this->deactivateOnCurrentBlog(); | |
| 37 | + restore_current_blog(); | |
| 38 | + } | |
| 39 | + } else { | |
| 40 | + $this->deactivateOnCurrentBlog(); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Deactivates plugin for a single site | |
| 46 | + */ | |
| 47 | + public function deactivateOnCurrentBlog() | |
| 48 | + { | |
| 23 | 49 | $routes = get_option('bitforms_routes'); |
| 24 | 50 | if ($routes && isset($routes['root'])) { |
| 25 | 51 | $root_page = ['ID' => $routes['root'], 'post_status' => 'draft']; |
| 26 | 52 | wp_update_post($root_page); |