boot(); } ); register_activation_hook( __FILE__, array( __NAMESPACE__ . '\\Plugin', 'activate' ) ); register_deactivation_hook( __FILE__, array( __NAMESPACE__ . '\\Plugin', 'deactivate' ) ); // Multisite: when a new site is created while Agentimus is network-active, give it // the same per-site setup (tables, defaults, prune cron, rewrite rules) at once, // rather than waiting for that site's first boot to self-heal. add_action( 'wp_initialize_site', static function ( $new_site ) { if ( ! function_exists( 'is_plugin_active_for_network' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( ! is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) { return; } switch_to_blog( (int) $new_site->blog_id ); Plugin::install_site(); restore_current_blog(); }, 100 ); // Multisite: when a SUB-SITE is deleted, core drops only its stock tables. Add ours so they don't // survive forever as orphans (uninstall can't reach a site that no longer exists). Keep this list // in sync with the DROP TABLE calls in uninstall.php. add_filter( 'wpmu_drop_tables', static function ( $tables, $blog_id ) { global $wpdb; $prefix = $wpdb->get_blog_prefix( (int) $blog_id ); foreach ( array( 'agentimus_agent_hits', 'agentimus_ai_referrals', 'agentimus_flagged_ips', 'agentimus_unknown_sources', 'agentimus_agent_events', 'agentimus_visibility', 'agentimus_edge_hourly', 'agentimus_bing_daily', 'agentimus_search_queries' ) as $agentimus_table ) { $tables[] = $prefix . $agentimus_table; } return $tables; }, 10, 2 );