| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.13 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Admin; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Maintenance |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Hook data |
| 23 |
* |
| 24 |
* @var array |
| 25 |
*/ |
| 26 |
private static $hook_data; |
| 27 |
|
| 28 |
public function __construct($hook_data) |
| 29 |
{ |
| 30 |
self::$hook_data = $hook_data; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Runs maintenance. |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function init() |
| 39 |
{ |
| 40 |
register_activation_hook(FBOX_PLUGIN_BASE_FILE, [__CLASS__, 'activation']); |
| 41 |
register_uninstall_hook(FBOX_PLUGIN_BASE_FILE, [__CLASS__, 'uninstall']); |
| 42 |
|
| 43 |
if (!is_multisite()) |
| 44 |
{ |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
// A site added to the network needs the same install every other site got. |
| 49 |
add_action('wp_initialize_site', [__CLASS__, 'onSiteInitialized'], 100, 1); |
| 50 |
|
| 51 |
// A site removed from the network takes its FireBox tables with it. |
| 52 |
add_filter('wpmu_drop_tables', [__CLASS__, 'dropTables'], 10, 2); |
| 53 |
|
| 54 |
// Drains the remaining sites of a large network activation. |
| 55 |
add_action('firebox_network_install', [__CLASS__, 'continueNetworkInstall']); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Runs on plugin activation |
| 60 |
* |
| 61 |
* @param bool $network_wide Whether the plugin was network activated. |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public static function activation($network_wide = false) |
| 66 |
{ |
| 67 |
if (is_multisite() && $network_wide) |
| 68 |
{ |
| 69 |
SiteInstaller::installNetwork(); |
| 70 |
} |
| 71 |
else |
| 72 |
{ |
| 73 |
SiteInstaller::installOnActivation(); |
| 74 |
} |
| 75 |
|
| 76 |
// Redirect to the dashboard on first activation. Read by |
| 77 |
// Admin::redirectAfterActivation(), which skips the network admin. |
| 78 |
update_option('firebox_activation_redirect', true); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Installs FireBox on a site that was just added to the network. |
| 83 |
* |
| 84 |
* @param \WP_Site $site |
| 85 |
* |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
public static function onSiteInitialized($site) |
| 89 |
{ |
| 90 |
if (!is_multisite() || !$site instanceof \WP_Site) |
| 91 |
{ |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
if (!self::isNetworkActive()) |
| 96 |
{ |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
switch_to_blog($site->blog_id); |
| 101 |
SiteInstaller::install(); |
| 102 |
restore_current_blog(); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Adds the FireBox tables to the ones WordPress drops with a deleted site. |
| 107 |
* |
| 108 |
* WordPress calls this filter while switched to the site being deleted, so |
| 109 |
* $wpdb->prefix is that site's prefix. |
| 110 |
* |
| 111 |
* @param array $tables |
| 112 |
* @param int $blog_id |
| 113 |
* |
| 114 |
* @return array |
| 115 |
*/ |
| 116 |
public static function dropTables($tables, $blog_id) |
| 117 |
{ |
| 118 |
global $wpdb; |
| 119 |
|
| 120 |
foreach (self::$hook_data['tables'] as $table) |
| 121 |
{ |
| 122 |
$tables[] = $wpdb->prefix . $table; |
| 123 |
} |
| 124 |
|
| 125 |
return $tables; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Installs the next batch of sites of a network activation. |
| 130 |
* |
| 131 |
* @return void |
| 132 |
*/ |
| 133 |
public static function continueNetworkInstall() |
| 134 |
{ |
| 135 |
SiteInstaller::installNetwork(); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Whether FireBox is activated for the whole network. |
| 140 |
* |
| 141 |
* @return bool |
| 142 |
*/ |
| 143 |
private static function isNetworkActive() |
| 144 |
{ |
| 145 |
if (!function_exists('is_plugin_active_for_network')) |
| 146 |
{ |
| 147 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 148 |
} |
| 149 |
|
| 150 |
return is_plugin_active_for_network(FBOX_PLUGIN_BASENAME); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Runs on plugin deactivation |
| 155 |
* |
| 156 |
* @return void |
| 157 |
*/ |
| 158 |
public static function uninstall() |
| 159 |
{ |
| 160 |
$pluginUninstall = new PluginUninstall(self::$hook_data); |
| 161 |
$pluginUninstall->start(); |
| 162 |
} |
| 163 |
} |