__( 'General Business', 'ai-ready-wp' ), 'restaurant' => __( 'Restaurant / Gastronomy', 'ai-ready-wp' ), 'real-estate' => __( 'Real Estate', 'ai-ready-wp' ), 'ecommerce' => __( 'E-Commerce / Shop', 'ai-ready-wp' ), 'saas' => __( 'SaaS / Software', 'ai-ready-wp' ), 'agency' => __( 'Agency / Consulting', 'ai-ready-wp' ), 'medical' => __( 'Medical / Health', 'ai-ready-wp' ), 'legal' => __( 'Legal / Law Firm', 'ai-ready-wp' ), 'finance' => __( 'Finance / Insurance', 'ai-ready-wp' ), 'education' => __( 'Education / Training', 'ai-ready-wp' ), 'construction' => __( 'Construction / Trades', 'ai-ready-wp' ), 'fitness' => __( 'Fitness / Sports', 'ai-ready-wp' ), 'beauty' => __( 'Beauty / Wellness', 'ai-ready-wp' ), 'automotive' => __( 'Automotive', 'ai-ready-wp' ), 'hotel' => __( 'Hotel / Hospitality', 'ai-ready-wp' ), 'nonprofit' => __( 'Nonprofit / Association', 'ai-ready-wp' ), ]; } // ─── Hidden wizard page ───────────────────────────────── public function register_page(): void { $hook = add_submenu_page( 'options.php', __( 'AI-Ready Setup', 'ai-ready-wp' ), __( 'AI-Ready Setup', 'ai-ready-wp' ), 'manage_options', self::PAGE, [ $this, 'render' ] ); if ( $hook ) { add_action( 'admin_print_styles-' . $hook, [ $this, 'print_styles' ] ); } } private function wizard_url( int $step = 1 ): string { return add_query_arg( [ 'page' => self::PAGE, 'step' => $step ], admin_url( 'admin.php' ) ); } public function silence_notices_on_wizard(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only page check. if ( ! isset( $_GET['page'] ) || self::PAGE !== $_GET['page'] ) { return; } remove_all_actions( 'admin_notices' ); remove_all_actions( 'all_admin_notices' ); } // ─── Activation redirect (bulk-safe) ──────────────────── public function maybe_redirect_after_activation(): void { if ( ! get_transient( self::REDIRECT_KEY ) ) { return; } delete_transient( self::REDIRECT_KEY ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only guard against bulk activation. if ( isset( $_GET['activate-multi'] ) || is_network_admin() || wp_doing_ajax() ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } wp_safe_redirect( $this->wizard_url( 1 ) ); exit; } // ─── Step handling ────────────────────────────────────── public function handle_step(): void { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified below. if ( empty( $_POST['airewp_setup_step'] ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } check_admin_referer( 'airewp_setup' ); $step = sanitize_text_field( wp_unslash( $_POST['airewp_setup_step'] ) ); $settings = AI_Ready_WP::get_settings(); if ( 'business' === $step ) { $settings['company_name'] = isset( $_POST['airewp_company_name'] ) ? sanitize_text_field( wp_unslash( $_POST['airewp_company_name'] ) ) : $settings['company_name']; $settings['company_desc'] = isset( $_POST['airewp_company_desc'] ) ? sanitize_textarea_field( wp_unslash( $_POST['airewp_company_desc'] ) ) : $settings['company_desc']; $settings['company_email'] = isset( $_POST['airewp_company_email'] ) ? sanitize_email( wp_unslash( $_POST['airewp_company_email'] ) ) : $settings['company_email']; $settings['services'] = isset( $_POST['airewp_services'] ) ? sanitize_text_field( wp_unslash( $_POST['airewp_services'] ) ) : $settings['services']; update_option( AIREWP_OPTION_KEY, $settings ); wp_safe_redirect( $this->wizard_url( 3 ) ); exit; } if ( 'industry' === $step ) { $industry = isset( $_POST['airewp_industry'] ) ? sanitize_text_field( wp_unslash( $_POST['airewp_industry'] ) ) : 'general'; $settings['industry'] = array_key_exists( $industry, $this->industries() ) ? $industry : 'general'; $schema = isset( $_POST['airewp_schema_type'] ) ? sanitize_text_field( wp_unslash( $_POST['airewp_schema_type'] ) ) : 'Organization'; $settings['schema_type'] = in_array( $schema, [ 'Organization', 'LocalBusiness' ], true ) ? $schema : 'Organization'; update_option( AIREWP_OPTION_KEY, $settings ); update_option( self::DONE_OPTION, time() ); wp_safe_redirect( $this->wizard_url( 4 ) ); exit; } } // ─── Render ───────────────────────────────────────────── public function render(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display selector only. $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 1; $step = max( 1, min( 4, $step ) ); echo '
'; $this->render_header( $step ); switch ( $step ) { case 1: $this->step_welcome(); break; case 2: $this->step_business(); break; case 3: $this->step_industry(); break; case 4: $this->step_done(); break; } echo '
'; } private function render_header( int $step ): void { $labels = [ 1 => __( 'Welcome', 'ai-ready-wp' ), 2 => __( 'Business', 'ai-ready-wp' ), 3 => __( 'Industry', 'ai-ready-wp' ), 4 => __( 'Done', 'ai-ready-wp' ), ]; echo '

' . esc_html__( 'AI-Ready WP Setup', 'ai-ready-wp' ) . '

'; echo '
    '; foreach ( $labels as $n => $label ) { $class = $n < $step ? 'done' : ( $n === $step ? 'active' : '' ); echo '
  1. ' . (int) $n . '' . esc_html( $label ) . '
  2. '; } echo '
'; } private function step_welcome(): void { echo '

' . esc_html__( 'Make your site discoverable by AI agents and search engines. Two quick steps and everything generates automatically.', 'ai-ready-wp' ) . '

'; echo ''; echo '

' . esc_html__( 'Get Started', 'ai-ready-wp' ) . '

'; } private function step_business(): void { $s = AI_Ready_WP::get_settings(); echo '

' . esc_html__( 'Tell AI agents who you are. This fills your discovery files and schema.', 'ai-ready-wp' ) . '

'; echo '
'; wp_nonce_field( 'airewp_setup' ); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '

'; echo '
'; } private function step_industry(): void { $s = AI_Ready_WP::get_settings(); echo '

' . esc_html__( 'Pick your industry so agents get the right context, and choose how you appear in structured data.', 'ai-ready-wp' ) . '

'; echo '
'; wp_nonce_field( 'airewp_setup' ); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '

'; echo '
'; } private function step_done(): void { // Completion is recorded in the nonce-verified 'industry' POST handler. echo '

' . esc_html__( 'Your site is AI-ready! Your discovery files and schema are live and will keep themselves updated.', 'ai-ready-wp' ) . '

'; echo '

'; echo '' . esc_html__( 'View AI-Readiness Score', 'ai-ready-wp' ) . ' '; echo '' . esc_html__( 'All settings', 'ai-ready-wp' ) . ' '; echo '' . esc_html__( 'See your llms.txt', 'ai-ready-wp' ) . ''; echo '

'; } // ─── Review notice ────────────────────────────────────── public function review_notice(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } if ( get_option( self::REVIEW_OPTION ) ) { return; } $done = (int) get_option( self::DONE_OPTION, 0 ); if ( ! $done || ( time() - $done ) < self::REVIEW_DELAY ) { return; } $review_url = 'https://wordpress.org/support/plugin/ai-ready-wp/reviews/#new-post'; $dismiss_url = wp_nonce_url( add_query_arg( 'airewp_review_dismiss', '1' ), 'airewp_review_dismiss' ); echo '

'; echo esc_html__( 'Enjoying AI-Ready WP? A quick review on WordPress.org would really help us — it takes a minute.', 'ai-ready-wp' ); echo ' ' . esc_html__( 'Leave a review', 'ai-ready-wp' ) . ''; echo ' · ' . esc_html__( 'No thanks', 'ai-ready-wp' ) . ''; echo '

'; } public function handle_review_dismiss(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verified on the next line. if ( empty( $_GET['airewp_review_dismiss'] ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } check_admin_referer( 'airewp_review_dismiss' ); update_option( self::REVIEW_OPTION, 1 ); wp_safe_redirect( remove_query_arg( [ 'airewp_review_dismiss', '_wpnonce' ] ) ); exit; } // ─── Styles ───────────────────────────────────────────── public function print_styles(): void { echo ''; } }