| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Network activation |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace IvyForms\Services\InstallActions; |
| 8 |
|
| 9 |
// phpcs:disable PSR1.Files.SideEffects |
| 10 |
use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 11 |
|
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; // Exit if accessed directly |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Class ActivationMultisite |
| 18 |
* |
| 19 |
* @package IvyForms\Services\InstallActions |
| 20 |
*/ |
| 21 |
class ActivationMultisite |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Activate the plugin for every sub-site separately |
| 25 |
* @throws InvalidArgumentException |
| 26 |
*/ |
| 27 |
public static function init(): void |
| 28 |
{ |
| 29 |
global $wpdb; |
| 30 |
|
| 31 |
// Get current blog id |
| 32 |
$oldSite = $wpdb->blogid; |
| 33 |
// Get all blog ids |
| 34 |
$siteIds = $wpdb->get_col( |
| 35 |
$wpdb->prepare("SELECT blog_id FROM $wpdb->blogs") |
| 36 |
); |
| 37 |
|
| 38 |
foreach ($siteIds as $siteId) { |
| 39 |
switch_to_blog($siteId); |
| 40 |
// Create database table if not exists |
| 41 |
ActivationDatabaseHook::init(); |
| 42 |
} |
| 43 |
// Returns to current blog |
| 44 |
switch_to_blog($oldSite); |
| 45 |
} |
| 46 |
} |
| 47 |
|