← All changes
|
backend/src/Services/InstallActions/ActivationMultisite.php
+42
-0
0.6.1
→
1.5.1
View file →
| @@ -1,0 +1,42 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Network activation | |
| 5 | + */ | |
| 6 | + | |
| 7 | +namespace IvyForms\Services\InstallActions; | |
| 8 | + | |
| 9 | +use IvyForms\Common\Exceptions\InvalidArgumentException; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Class ActivationMultisite | |
| 13 | + * | |
| 14 | + * @package IvyForms\Services\InstallActions | |
| 15 | + */ | |
| 16 | +class ActivationMultisite | |
| 17 | +{ | |
| 18 | + /** | |
| 19 | + * Activate the plugin for every sub-site separately | |
| 20 | + * @throws InvalidArgumentException | |
| 21 | + */ | |
| 22 | + public static function init(): void | |
| 23 | + { | |
| 24 | + global $wpdb; | |
| 25 | + | |
| 26 | + // Get current blog id | |
| 27 | + $oldSite = $wpdb->blogid; | |
| 28 | + // Get all blog ids | |
| 29 | + $siteIds = $wpdb->get_col( | |
| 30 | + $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs") | |
| 31 | + ); | |
| 32 | + | |
| 33 | + foreach ($siteIds as $siteId) { | |
| 34 | + switch_to_blog($siteId); | |
| 35 | + // Create database table if not exists | |
| 36 | + ActivationDatabaseHook::init(); | |
| 37 | + ActivationCapabilitiesHook::ensureAdministratorCaps(); | |
| 38 | + } | |
| 39 | + // Returns to current blog | |
| 40 | + switch_to_blog($oldSite); | |
| 41 | + } | |
| 42 | +} | |