*/ function recommended_settings(): array { $seo_active = active_seo_plugin() !== null; return array( // Discovery — all on, low cost, no conflicts. 'ajaco_api_catalog_enabled' => true, 'ajaco_mcp_server_card_enabled' => true, 'ajaco_agent_skills_index_enabled' => true, 'ajaco_llms_txt_enabled' => true, // IndexNow off — requires API key + production environment. 'ajaco_indexnow_enabled' => false, // Presentation — on by default; JSON-LD off when an SEO plugin is active // (auto-suppression would no-op anyway, but turning it off makes the UI honest). 'ajaco_markdown_enabled' => true, 'ajaco_json_ld_enabled' => ! $seo_active, 'ajaco_openapi_enabled' => true, 'ajaco_webmcp_enabled' => true, // Discovery/auth — on: a truthful, static document. 'ajaco_auth_md_enabled' => true, // Declarations — on. 'ajaco_content_signals_enabled' => true, 'ajaco_ai_bot_rules_enabled' => true, ); } /** * Handle the wizard form submission. * * @return void */ function handle_wizard_submit(): void { if ( ! current_user_can( required_capability() ) ) { wp_die( esc_html__( 'You do not have permission to run the AJ Agent Crawl Optimizer setup wizard.', 'aj-agent-crawl-optimizer' ), '', array( 'response' => 403 ) ); } check_admin_referer( 'ajaco_apply_wizard' ); $action = isset( $_POST['ajaco_wizard_action'] ) ? sanitize_text_field( wp_unslash( $_POST['ajaco_wizard_action'] ) ) : ''; if ( 'apply' === $action ) { // Only write options THIS form rendered. An absent checkbox otherwise // reads as "the user unchecked it" — which silently disables features // when the open page was rendered by an older version of the plugin // (whose form had no field for options added since), or when the POST // was truncated by PHP's max_input_vars. $rendered = isset( $_POST['ajaco_wizard_fields'] ) ? array_filter( array_map( 'trim', explode( ',', sanitize_text_field( wp_unslash( $_POST['ajaco_wizard_fields'] ) ) ) ) ) : array(); foreach ( array_keys( recommended_settings() ) as $option ) { if ( ! in_array( $option, $rendered, true ) ) { continue; // Not on the submitted form — leave it exactly as it is. } $checked = isset( $_POST[ $option ] ) && '1' === $_POST[ $option ]; update_option( $option, $checked ); } set_transient( WIZARD_APPLIED_FLAG, 1, 60 ); } // Apply or skip — either way, dismiss the wizard (re-runnable any time // from the settings page link). delete_option( WIZARD_PENDING_OPTION ); update_option( WIZARD_DONE_OPTION, 1, false ); wp_safe_redirect( settings_page_url() ); exit; } /** * Show a flash notice after the wizard's settings are applied. * * @return void */ function maybe_show_wizard_applied_notice(): void { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; // The settings screen id depends on its parent menu — match the page slug // instead of hardcoding the pre-2.0 'settings_page_' prefix. if ( ! $screen || false === strpos( (string) $screen->id, 'aj-agent-crawl-optimizer' ) ) { return; } if ( ! get_transient( WIZARD_APPLIED_FLAG ) ) { return; } delete_transient( WIZARD_APPLIED_FLAG ); ?>
' . esc_html( $seo_plugin ) . '' ); ?>