run(); // Grant the management capability. Capabilities::grant(); // Seed default settings without overwriting existing ones. self::seed_settings(); // Record install metadata (useful for support/migrations). if ( false === get_option( 'profit_engine_installed_at' ) ) { add_option( 'profit_engine_installed_at', gmdate( 'Y-m-d H:i:s' ), '', false ); } update_option( 'profit_engine_version', PROFIT_ENGINE_VERSION, false ); // Ensure rewrite/REST routes are fresh. flush_rewrite_rules(); } /** * Seed default plugin settings if absent. */ private static function seed_settings(): void { if ( false !== get_option( 'profit_engine_settings' ) ) { return; } $defaults = array( 'cost_basis' => 'average', // 'average' | 'last' (merchant-configurable). 'tax_in_profit' => false, // Exclude tax from profit by default. 'forecast_window' => 30, // Days of sales history for velocity. 'coverage_days' => 30, // How far ahead to stock beyond lead time. 'safety_days' => 7, // Fallback safety stock (auto) in days of demand. 'default_lead_time' => 7, // Used when supplier lead time is unset. 'payment_fee_percent' => 0, // Default gateway fee percentage. 'payment_fee_fixed' => 0, // Default gateway fixed fee. 'shipping_alloc' => 'value', // 'value' | 'none' allocation basis. 'other_cost_percent' => 0, // Other cost as % of revenue. 'other_cost_fixed' => 0, // Other fixed cost per order. 'delete_data_on_uninstall' => false, // Opt-in destructive uninstall. ); add_option( 'profit_engine_settings', $defaults, '', false ); } }