settings = new Settings(); // Figure out post-type vendor labels at runtime (no hardcoded plugin list). // Only on our settings screen, so the per-registration backtrace cost is // never paid on a normal page load. if ( is_admin() && 'agentimus' === ( isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only admin screen check, no state change. Content::watch_origins(); } Cache::register_flush_hooks(); ( new Endpoints( $this->settings ) )->register(); ( new Schema( $this->settings ) )->register(); ( new Rest( $this->settings ) )->register(); ( new Admin( $this->settings ) )->register(); ( new Discovery\Module( $this->settings ) )->register(); ( new Activity\Module( $this->settings ) )->register(); // After an update that adds a new /.well-known name (e.g. tdmrep.json), // flush the rewrite rules once so it resolves without re-activation. Runs // after WellKnown::add_rules() (init, default priority) and no-ops as soon // as the stored rewrite version matches. add_action( 'init', array( self::class, 'maybe_flush_rewrites' ), 20 ); /** * Fires after Agentimus has booted. The seam a Pro add-on hooks to * register its own features against the shared Settings instance. * * @param Plugin $plugin The plugin instance. */ do_action( 'agentimus_booted', $this ); } /** * Activation: seed defaults and register the /.well-known rewrite rule before * flushing, so the discovery endpoints resolve on the very first request. */ public static function activate() { // Detect a truly fresh install BEFORE seeding anything, so the onboarding // wizard shows only for new users — never for an upgrade or a migrant from // the pre-rename "Agent Ready" option. $had_settings = ( false !== get_option( Settings::OPTION, false ) ) || ( false !== get_option( 'agent_ready_settings', false ) ); self::migrate_legacy_option(); ( new Settings() )->ensure_defaults(); Activity\Table::install(); Activity\Referrals::install(); Activity\Module::schedule(); Discovery\WellKnown::add_rules(); flush_rewrite_rules(); update_option( 'agentimus_rewrite_version', AGENTIMUS_VERSION ); // Activation already flushed — don't re-flush on the next request. self::seed_onboarding_state( $had_settings ); } /** * One-time rewrite flush after a plugin update introduces a new routed * /.well-known name. Compares a stored version marker against the running * version and flushes (then records) exactly once. Hooked late on `init`, so * WellKnown::add_rules() has already registered the current rule set. */ public static function maybe_flush_rewrites() { if ( AGENTIMUS_VERSION === get_option( 'agentimus_rewrite_version' ) ) { return; } flush_rewrite_rules(); update_option( 'agentimus_rewrite_version', AGENTIMUS_VERSION ); } /** * Carry settings over from the pre-rename "Agent Ready" option key, so an * existing install keeps its configuration after the rename to Agentimus. * One-time: runs only when the new key is absent. */ private static function migrate_legacy_option() { if ( false !== get_option( Settings::OPTION, false ) ) { return; } $legacy = get_option( 'agent_ready_settings', false ); // Old key — intentionally literal. if ( is_array( $legacy ) ) { add_option( Settings::OPTION, $legacy ); } } /** * Decide whether the first-run setup wizard should appear. A fresh install * leaves the flag unset (wizard shows) and queues a one-time redirect to the * plugin screen; an install that already had settings is marked onboarded so * an existing user never sees the wizard. * * @param bool $had_settings Whether configuration existed before activation. */ private static function seed_onboarding_state( $had_settings ) { if ( $had_settings ) { add_option( 'agentimus_onboarded', AGENTIMUS_VERSION ); // No-op if already present. return; } set_transient( 'agentimus_activation_redirect', 1, 30 ); } /** * Deactivation: drop generated caches and the rewrite rule (options are kept; * uninstall removes them). */ public static function deactivate() { Cache::flush(); Activity\Module::unschedule(); wp_clear_scheduled_hook( 'agentimus_warm_llms_full' ); flush_rewrite_rules(); } }