| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Multisite hook on new site 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 ActivationNewSiteMultisite |
| 18 |
* |
| 19 |
* @package IvyForms\Services\InstallActions |
| 20 |
*/ |
| 21 |
class ActivationNewSiteMultisite |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Activate the plugin for every newly created site if the plugin is network activated |
| 25 |
* |
| 26 |
* @param int $siteId |
| 27 |
* @throws InvalidArgumentException |
| 28 |
*/ |
| 29 |
public static function init(int $siteId): void |
| 30 |
{ |
| 31 |
if (! function_exists('is_plugin_active_for_network')) { |
| 32 |
if (file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) { |
| 33 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
if ( |
| 38 |
defined('IVYFORMS_PLUGIN_SLUG') && |
| 39 |
is_plugin_active_for_network(IVYFORMS_PLUGIN_SLUG) // @phpstan-ignore argument.type |
| 40 |
) { |
| 41 |
switch_to_blog($siteId); |
| 42 |
//Create database table if not exists |
| 43 |
ActivationDatabaseHook::init(); |
| 44 |
restore_current_blog(); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|