1, 'pricing_enabled' => 1, 'upsell_enabled' => 1, 'banner_enabled' => 1, 'cache_enabled' => 1, 'cache_duration' => 3600, ]); } } /** * Run database migrations after code updates, not only on activation. */ function sodino_maybe_run_migrations() { $current_version = get_option('sodino_db_version', '0'); if (version_compare($current_version, SODINO_DB_VERSION, '>=')) { return; } require_once SODINO_PLUGIN_DIR . 'database/migrations.php'; sodino_create_tables(); } // Deactivation hook register_deactivation_hook(__FILE__, 'sodino_deactivate'); function sodino_deactivate() { // Flush rewrite rules flush_rewrite_rules(); // Clear analytics cron wp_clear_scheduled_hook('sodino_hourly_analytics'); // Clear all cache $cache = \Sodino\Core\Cache::getInstance(); $cache->clearAll(); } // Bootstrap the plugin function sodino_init() { // Check if WooCommerce is active if (!class_exists('WooCommerce')) { add_action('admin_notices', 'sodino_woocommerce_missing_notice'); return; } // Load text domain load_plugin_textdomain('sodino', false, dirname(SODINO_PLUGIN_BASENAME) . '/languages/'); sodino_maybe_run_migrations(); // Initialize admin if (is_admin()) { require_once SODINO_PLUGIN_DIR . 'admin/admin.php'; } // Initialize public hooks sodino_init_public_hooks(); // Schedule analytics aggregation if needed sodino_schedule_analytics(); } add_action('plugins_loaded', 'sodino_init'); /** * Initialize public hooks */ function sodino_init_public_hooks() { $settings = \Sodino\Core\Settings::getInstance(); if ($settings->isPricingEnabled()) { require_once SODINO_PLUGIN_DIR . 'public/hooks/pricing-hooks.php'; } if ($settings->isUpsellEnabled()) { require_once SODINO_PLUGIN_DIR . 'public/hooks/upsell-hooks.php'; } if ($settings->isBannerEnabled()) { require_once SODINO_PLUGIN_DIR . 'public/hooks/banner-hooks.php'; } // Always load analytics require_once SODINO_PLUGIN_DIR . 'public/hooks/analytics-hooks.php'; } /** * Schedule analytics cron job */ function sodino_schedule_analytics() { if (!wp_next_scheduled('sodino_hourly_analytics')) { wp_schedule_event(time(), 'hourly', 'sodino_hourly_analytics'); } } /** * Run analytics aggregation cron job */ function sodino_run_analytics_aggregation() { if (!class_exists('Sodino\Services\AnalyticsService')) { return; } $eventRepository = new Sodino\Repositories\EventRepository(); $ruleRepository = new Sodino\Repositories\RuleRepository(); $analyticsService = new Sodino\Services\AnalyticsService($eventRepository, $ruleRepository); $analyticsService->primeCache(); } add_action('sodino_hourly_analytics', 'sodino_run_analytics_aggregation'); // WooCommerce missing notice function sodino_woocommerce_missing_notice() { ?>