ui = $ui; $this->onboarding = $onboarding; $this->global_settings = $global_settings; $this->post_type_settings = $post_type_settings; $this->importers = $importers; $this->ai_providers = $ai_providers; $this->ai_settings = $ai_settings; $this->robots_txt = $robots_txt; $this->integrations = $integrations; $this->ai_bots = $ai_bots; $this->features = $features; } public function slug(): string { return 'onboarding'; } public function label(): string { return __( 'Setup wizard', 'acez-seo' ); } public function icon(): string { return 'onboarding'; } public function enqueue(): void { // wp.media modal for the organization logo picker, same as SchemaTab. wp_enqueue_media(); wp_enqueue_script( 'acez-seo-media-picker', ACEZ_SEO_URL . 'assets/js/media-picker.js', array( 'media-editor' ), ACEZ_SEO_VERSION, true ); $state = $this->onboarding->get(); // Only needed on Step 3 — same script/REST endpoint AiProvidersTab // uses (M12), it only cares about `.acez-seo-ai-provider-card` // markup/classes, not which tab rendered them. if ( 'in_progress' === $state['status'] && 2 === $state['last_step'] ) { wp_enqueue_script( 'acez-seo-ai-providers', ACEZ_SEO_URL . 'assets/js/ai-providers.js', array(), ACEZ_SEO_VERSION, true ); wp_localize_script( 'acez-seo-ai-providers', 'AcezSeoAiProviders', array( 'restUrl' => esc_url_raw( rest_url( 'acez-seo/v1/test-provider' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'testing' => __( 'Testing…', 'acez-seo' ), 'error' => __( 'Failed to test the connection.', 'acez-seo' ), ) ); } } public function handles_form_key( string $raw_tab ): bool { if ( str_starts_with( $raw_tab, 'onboarding_step3:' ) ) { return true; } return in_array( sanitize_key( $raw_tab ), array( 'onboarding_step1', 'onboarding_step2_import', 'onboarding_step2_next', 'onboarding_step3_skip', 'onboarding_step4', 'onboarding_step4_skip', 'onboarding_step5', 'onboarding_skip', 'onboarding_restart', ), true ); } /** @return array */ public function save( string $raw_tab ): array { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $tab_key = sanitize_key( $raw_tab ); if ( 'onboarding_skip' === $tab_key ) { $this->onboarding->update( array( 'status' => 'skipped' ) ); return array( 'tab' => 'onboarding' ); } if ( 'onboarding_restart' === $tab_key ) { $this->onboarding->update( array( 'status' => 'new', 'last_step' => 0, 'site_type' => '', ) ); return array( 'tab' => 'onboarding' ); } if ( 'onboarding_step1' === $tab_key ) { $this->save_step_1(); return array( 'tab' => 'onboarding' ); } if ( 'onboarding_step2_import' === $tab_key ) { $this->save_step_2_import(); return array( 'tab' => 'onboarding' ); } if ( 'onboarding_step2_next' === $tab_key ) { // Move past the import step regardless of whether the user // actually ran an import — on to Step 3. $this->onboarding->update( array( 'status' => 'in_progress', 'last_step' => 2, ) ); return array( 'tab' => 'onboarding' ); } if ( str_starts_with( $raw_tab, 'onboarding_step3:' ) ) { $this->save_step_3( sanitize_key( substr( $raw_tab, strlen( 'onboarding_step3:' ) ) ) ); return array( 'tab' => 'onboarding' ); } if ( 'onboarding_step3_skip' === $tab_key ) { // "pominięcie = AI zostaje wyłączone, zero nagabywania" (M41): no // provider/feature-flag changes at all — on to Step 4. $this->onboarding->update( array( 'status' => 'in_progress', 'last_step' => 3, ) ); return array( 'tab' => 'onboarding' ); } if ( 'onboarding_step4' === $tab_key ) { $this->save_step_4(); return array( 'tab' => 'onboarding' ); } if ( 'onboarding_step4_skip' === $tab_key ) { // No llms.txt/noai/bot-blocking changes — on to Step 5. $this->onboarding->update( array( 'status' => 'in_progress', 'last_step' => 4, ) ); return array( 'tab' => 'onboarding' ); } // onboarding_step5 — the wizard's final step: saves the (optional) // GSC verification code and always finishes the wizard. $this->save_step_5(); return array( 'tab' => 'onboarding' ); } private function save_step_1(): void { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $site_type = isset( $_POST['site_type'] ) ? sanitize_key( wp_unslash( $_POST['site_type'] ) ) : ''; if ( ! in_array( $site_type, OnboardingRepository::SITE_TYPES, true ) ) { $site_type = 'personal_blog'; } $social_raw = isset( $_POST['social_profiles'] ) ? TemplateSanitizer::sanitize_multiline( wp_strip_all_tags( wp_unslash( $_POST['social_profiles'] ) ) ) : ''; $this->global_settings->update( array( 'organization_name' => isset( $_POST['organization_name'] ) ? sanitize_text_field( wp_unslash( $_POST['organization_name'] ) ) : '', 'organization_logo_id' => isset( $_POST['organization_logo_id'] ) ? (int) $_POST['organization_logo_id'] : 0, 'social_profiles' => array_filter( array_map( 'trim', explode( "\n", $social_raw ) ) ), // Only 'local_business' gets the node enabled automatically — // the rest of its fields (address, hours, phone...) still // need filling in on the Schema tab; the wizard only flips // the switch so the following step doesn't feel like a dead end. 'local_business_enabled' => 'local_business' === $site_type, ) ); // A personal blog is the one site type where showing the individual // author (Person) on posts makes sense by default; a company/shop // voice is usually institutional. `get()` first — `update()` here // replaces the WHOLE per-post-type option, so skipping this would // silently reset title/description templates back to defaults. $post_settings = $this->post_type_settings->get( 'post' ); $post_settings['author_schema_enabled'] = 'personal_blog' === $site_type; $this->post_type_settings->update( 'post', $post_settings ); // Step 2 ("Przenieś dane") only has something to show when a // supported plugin's data was actually detected — otherwise the // milestone calls for skipping it automatically rather than showing // an empty screen, so this jumps straight to last_step=2 (meaning // "step 2 done/skipped", landing on Step 3 on the next render). $has_import_sources = array() !== $this->importers->available(); $this->onboarding->update( array( 'status' => 'in_progress', 'last_step' => $has_import_sources ? 1 : 2, 'site_type' => $site_type, ) ); } private function save_step_2_import(): void { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $source = isset( $_POST['import_source'] ) ? sanitize_key( wp_unslash( $_POST['import_source'] ) ) : ''; $importer = $this->importers->get( $source ); if ( null === $importer || ! $importer->is_available() ) { return; } $overwrite = isset( $_POST['import_overwrite'] ); $dry_run = isset( $_POST['import_preview'] ); $report = $dry_run ? $importer->preview( $overwrite ) : $importer->import( $overwrite ); // A DIFFERENT transient key than ToolsTab's own — the wizard and the // Narzędzia tab each show their own report, so running an import from // one doesn't leave a stale notice waiting in the other. set_transient( 'acez_seo_onboarding_import_report_' . get_current_user_id(), $report->to_array(), 60 ); } /** * Same contract as `AiProvidersTab::save_provider()` (M12) — reuses the * SAME repository methods, just with the wizard's own finish-the-step * behavior instead of redirecting to the AI Providers tab. Also makes * the saved provider the ACTIVE one (the wizard presents "choose a * provider" as a single action, unlike AiProvidersTab's separate * "active provider" dropdown + per-provider card flow). */ private function save_step_3( string $provider_id ): void { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $this->ai_settings->update_provider( $provider_id, array( 'api_key' => isset( $_POST['api_key'] ) ? sanitize_text_field( wp_unslash( $_POST['api_key'] ) ) : '', 'model' => isset( $_POST['model'] ) ? sanitize_text_field( wp_unslash( $_POST['model'] ) ) : '', ) ); $tested = isset( $_POST['provider_tested'] ) && '1' === $_POST['provider_tested']; $this->ai_settings->mark_tested( $provider_id, $tested ); if ( $tested ) { $this->ai_settings->set_active_provider( $provider_id ); // "udany test odblokowuje i włącza master switch `ai`" (M41) — // explicit, even though `ai` already defaults to on: this is the // one moment the wizard KNOWS the provider is genuinely usable. $this->features->update( array( 'ai' => true ) ); } $this->onboarding->update( array( 'status' => 'in_progress', 'last_step' => 3, ) ); } private function save_step_4(): void { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); if ( null !== $this->ai_bots ) { $this->ai_bots->update( array( 'llms_enabled' => isset( $_POST['llms_enabled'] ), 'llms_intro' => isset( $_POST['llms_intro'] ) ? sanitize_textarea_field( wp_unslash( $_POST['llms_intro'] ) ) : '', 'noai' => isset( $_POST['noai'] ), ) ); } // RobotsTxtRepository::update() merges with DEFAULTS, not the // currently stored values (a documented trap) — read get() first and // pass the FULL settings back, or a partial save here would wipe // custom_rules and any previously blocked bots outside this step's // own AI-bot subset. $current = $this->robots_txt->get(); $ai_bot_agents = wp_list_pluck( self::ai_bot_choices(), 'agent' ); $selected = isset( $_POST['blocked_bots'] ) ? array_map( 'sanitize_text_field', (array) wp_unslash( $_POST['blocked_bots'] ) ) : array(); $selected = array_intersect( $selected, $ai_bot_agents ); $preserved = array_diff( (array) $current['blocked_bots'], $ai_bot_agents ); $this->robots_txt->update( array( 'blocked_bots' => array_values( array_unique( array_merge( $preserved, $selected ) ) ), 'custom_rules' => (string) $current['custom_rules'], ) ); $this->onboarding->update( array( 'status' => 'in_progress', 'last_step' => 4, ) ); } private function save_step_5(): void { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $this->integrations->update( array( 'gsc_verification_code' => isset( $_POST['gsc_verification_code'] ) ? sanitize_text_field( wp_unslash( $_POST['gsc_verification_code'] ) ) : '', ) ); $this->onboarding->update( array( 'status' => 'completed', 'last_step' => 5, ) ); } public function render(): void { $state = $this->onboarding->get(); echo '

' . esc_html__( 'Quick-start wizard — a few questions to configure the plugin sensibly for your site right away.', 'acez-seo' ) . wp_kses( HelpIcon::render( 'onboarding' ), KsesTags::help_icon() ) . '

'; // Read-only view override for the Dashboard's "Kondycja konfiguracji" // health card (M41) deep-linking to a specific unfinished step — // nothing is mutated here, each step form still posts to its own save // handler regardless of how the user reached it. $step_override = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only view override, no data written. if ( $step_override >= 1 && $step_override <= 5 ) { $this->render_step_by_number( $step_override, $state ); return; } if ( 'in_progress' === $state['status'] && 1 === $state['last_step'] ) { $this->render_step_2(); return; } if ( 'in_progress' === $state['status'] && 2 === $state['last_step'] ) { $this->render_step_3(); return; } if ( 'in_progress' === $state['status'] && 3 === $state['last_step'] ) { $this->render_step_4(); return; } if ( 'in_progress' === $state['status'] && 4 === $state['last_step'] ) { $this->render_step_5(); return; } if ( 'new' !== $state['status'] ) { $this->render_summary( $state ); return; } $this->render_step_1( $state ); } /** * @param array{status: string, last_step: int, site_type: string} $state */ private function render_summary( array $state ): void { $this->ui->card_open( __( 'Setup wizard', 'acez-seo' ), 'onboarding', '', 'onboarding-summary' ); if ( 'skipped' === $state['status'] ) { echo '

' . esc_html__( 'The wizard was skipped — you can configure everything manually in the other tabs.', 'acez-seo' ) . '

'; } else { $settings = $this->global_settings->get(); $label = self::site_type_labels()[ $state['site_type'] ] ?? $state['site_type']; printf( '

%1$s %2$s

', esc_html__( 'Site type from the wizard:', 'acez-seo' ), esc_html( $label ) ); if ( '' !== trim( (string) $settings['organization_name'] ) ) { printf( '

%1$s %2$s

', esc_html__( 'Organization name:', 'acez-seo' ), esc_html( (string) $settings['organization_name'] ) ); } echo '

' . esc_html__( 'Wizard completed. You\'ll find further configuration (title templates, robots.txt, AI, etc.) in the other tabs.', 'acez-seo' ) . '

'; } $this->ui->form_open( 'onboarding_restart' ); printf( '

', esc_html__( 'Run the wizard again', 'acez-seo' ) ); $this->ui->form_close(); $this->ui->card_close(); } /** * @param array{status: string, last_step: int, site_type: string} $state */ private function render_step_by_number( int $step, array $state ): void { match ( $step ) { 1 => $this->render_step_1( $state ), 2 => $this->render_step_2(), 4 => $this->render_step_4(), 5 => $this->render_step_5(), default => $this->render_step_3(), }; } /** * @param array{status: string, last_step: int, site_type: string} $state */ private function render_step_1( array $state ): void { $this->render_progress( 1 ); $settings = $this->global_settings->get(); $this->ui->card_open( __( 'Step 1: Your website', 'acez-seo' ), 'onboarding', '', 'onboarding-step-1' ); $this->ui->form_open( 'onboarding_step1' ); echo ''; echo ''; $this->ui->text_field( 'organization_name', __( 'Organization name', 'acez-seo' ), (string) $settings['organization_name'] ); $this->ui->media_picker_field( 'organization_logo_id', 'onboarding_organization_logo_id', __( 'Logo', 'acez-seo' ), (int) $settings['organization_logo_id'] ); $this->ui->textarea_field( 'social_profiles', __( 'Social profiles (one URL per line)', 'acez-seo' ), implode( "\n", (array) $settings['social_profiles'] ), __( "https://facebook.com/your-page\nhttps://x.com/your-page", 'acez-seo' ) ); echo '
' . esc_html__( 'What type of website is this?', 'acez-seo' ) . ''; foreach ( self::site_type_labels() as $value => $type_label ) { printf( '', esc_attr( $value ), checked( $state['site_type'], $value, false ), esc_html( $type_label ) ); } echo '

' . esc_html__( 'This is just a sensible starting point — every one of these settings can be changed manually later in the Schema tab.', 'acez-seo' ) . '

'; echo '
'; submit_button( __( 'Save and finish', 'acez-seo' ) ); $this->ui->form_close(); $this->ui->card_close(); $this->ui->form_open( 'onboarding_skip' ); printf( '

', esc_html__( 'Skip the wizard', 'acez-seo' ) ); $this->ui->form_close(); } /** * Step 2 ("Przenieś dane") — only ever shown when `save_step_1()` found at * least one importer with detected data; otherwise the wizard skips * straight to the summary. Reuses the SAME importer preview/import * pipeline as `ToolsTab` (M18), under its own form key and transient so * running an import here doesn't leave a stray notice on the Narzędzia tab. */ private function render_step_2(): void { $this->render_progress( 2 ); $report = $this->pull_import_report(); if ( null !== $report ) { printf( '

%2$s %3$s

', $report->dry_run ? 'notice-info' : 'notice-success', esc_html( $report->dry_run ? __( 'Import preview:', 'acez-seo' ) : __( 'Import finished.', 'acez-seo' ) ), esc_html( $report->to_summary() ) ); } $this->ui->card_open( __( 'Step 2: Migrate data', 'acez-seo' ), 'onboarding', '', 'onboarding-step-2' ); echo '

' . esc_html__( 'Data from another SEO plugin was detected. You can import it now (the source data is only read, never modified or deleted) or skip this step and do it later in the Tools tab.', 'acez-seo' ) . '

'; $available = $this->importers->available(); if ( array() !== $available ) { $this->ui->form_open( 'onboarding_step2_import' ); echo ''; echo ''; echo ''; echo '
' . esc_html__( 'Data source', 'acez-seo' ) . ''; $first = true; foreach ( $available as $importer ) { printf( '', esc_attr( $importer->get_id() ), checked( $first, true, false ), esc_html( $importer->get_label() ) ); $first = false; } echo '
' . esc_html__( 'Overwriting', 'acez-seo' ) . ''; printf( '', esc_html__( 'Overwrite values already set in Acez SEO AI (by default only empty fields are filled in)', 'acez-seo' ) ); echo '
'; echo '

'; submit_button( __( 'Preview (saves nothing)', 'acez-seo' ), 'secondary', 'import_preview', false ); echo ' '; submit_button( __( 'Import', 'acez-seo' ), 'primary', 'import_run', false ); echo '

'; $this->ui->form_close(); } $this->ui->card_close(); $this->ui->form_open( 'onboarding_step2_next' ); printf( '

', esc_html__( 'Next', 'acez-seo' ) ); $this->ui->form_close(); $this->ui->form_open( 'onboarding_skip' ); printf( '

', esc_html__( 'Skip the wizard', 'acez-seo' ) ); $this->ui->form_close(); } /** * Step 3 ("Asystent AI") — optional, per the milestone ("z notą o * kosztach"): connecting AI runs on the user's OWN provider key, so the * cost note is about THEIR bill, not ours. Reuses the exact same * test-connection JS/REST endpoint as `AiProvidersTab` (M12) — the script * only cares about `.acez-seo-ai-provider-card` markup, not which tab * rendered it — under the wizard's OWN form key (`onboarding_step3:{id}`) * so saving here finishes the wizard step instead of redirecting to the * AI Providers tab. */ private function render_step_3(): void { $this->render_progress( 3 ); $this->ui->card_open( __( 'Step 3: AI assistant', 'acez-seo' ), 'onboarding', '', 'onboarding-step-3' ); echo '

' . esc_html__( 'Optional: connect your own Anthropic, OpenAI, Google Gemini, or OpenRouter account to generate titles, descriptions, and alt text in one click. Generation costs are billed to your own account with the provider — the plugin doesn\'t charge anything or act as a payment intermediary.', 'acez-seo' ) . '

'; $providers = $this->ai_providers->all(); $active = $this->ai_settings->get_active_provider(); echo '
' . esc_html__( 'Provider', 'acez-seo' ) . '
'; foreach ( $providers as $provider ) { $this->render_ai_provider_card( $provider, $provider->get_id() === $active ); } $this->ui->card_close(); $this->ui->form_open( 'onboarding_step3_skip' ); printf( '

', esc_html__( 'Skip this step', 'acez-seo' ) ); $this->ui->form_close(); $this->ui->form_open( 'onboarding_skip' ); printf( '

', esc_html__( 'Skip the wizard', 'acez-seo' ) ); $this->ui->form_close(); } /** * Trimmed copy of `AiProvidersTab::render_ai_provider_card()` (M12) — * same markup/classes so the shared `ai-providers.js` behaves identically, * just posting to the wizard's own per-provider form key instead of * `ai:{id}` so saving stays on this tab and advances the wizard. */ private function render_ai_provider_card( AiProviderInterface $provider, bool $is_active ): void { $provider_id = $provider->get_id(); $model = $this->ai_settings->get_model( $provider_id ); $has_key = $this->ai_settings->has_api_key( $provider_id ); printf( '
', esc_attr( $provider_id ), $is_active ? '' : ' hidden' ); printf( '
%1$s%2$s
', wp_kses( $this->ui->tab_icon_svg( 'ai' ), KsesTags::svg() ), esc_html( $provider->get_label() ) ); $this->ui->form_open( 'onboarding_step3:' . $provider_id ); echo ''; printf( '', esc_attr( $provider_id ), esc_html__( 'API key', 'acez-seo' ), $has_key ? esc_attr__( '•••••••• (saved, leave blank to keep it unchanged)', 'acez-seo' ) : esc_attr__( 'not set', 'acez-seo' ), esc_html__( 'The key is encrypted before saving and is never displayed again.', 'acez-seo' ) ); // Not FormControls::text_field() — see AiProvidersTab::render_ai_provider_card() // for why a shared literal id="model" across all provider cards is a bug. printf( '', esc_attr( $provider_id ), esc_html__( 'Model', 'acez-seo' ), esc_attr( $model ), esc_attr__( 'leave blank to use the default', 'acez-seo' ), wp_kses( HelpIcon::render( 'ai_model' ), KsesTags::help_icon() ) ); echo '

%4$s

%5$s
'; echo '

'; printf( ' ', esc_html__( 'Test connection', 'acez-seo' ) ); echo ''; echo '

'; echo ''; printf( '

', $has_key ? '' : ' hidden' ); // Custom class via $type, not $other_attributes['class'] — see AiProvidersTab // for why passing 'class' via $other_attributes here silently drops it // (get_submit_button() emits class="..." from both independently). submit_button( __( 'Save and continue', 'acez-seo' ), 'primary acez-seo-ai-save-button', 'save_provider', false ); echo '

'; echo ''; $this->ui->form_close(); echo '
'; } /** * Step 4 ("SEO ery AI") — the milestone's marketing differentiator: * prepares the site for AI crawlers via TWO existing free repositories, * `AiBotsRepositoryInterface` (llms.txt + noai, M37) and * `RobotsTxtRepositoryInterface` (bot blocking, M19). Explains the * project's own doctrine in one line: robots.txt = WHETHER a bot may * read, llms.txt = WHAT to read, schema (M3) = HOW to understand it. */ private function render_step_4(): void { $this->render_progress( 4 ); if ( null !== $this->ai_bots ) { $ai_bots_settings = $this->ai_bots->get(); $this->ui->card_open( __( 'Step 4: SEO for the AI era', 'acez-seo' ), 'onboarding', '', 'onboarding-step-4' ); echo '

' . esc_html__( 'robots.txt tells bots WHETHER they may read your site, llms.txt tells them WHAT matters most in it, and schema.org (already generated automatically) tells them HOW to understand it. This step turns on the first two.', 'acez-seo' ) . '

'; $this->ui->form_open( 'onboarding_step4' ); echo ''; $this->ui->checkbox_field( 'llms_enabled', __( 'Serve the llms.txt file (a content guide for AI models)', 'acez-seo' ), (bool) $ai_bots_settings['llms_enabled'] ); $this->ui->textarea_field( 'llms_intro', __( 'Custom introduction for llms.txt (optional)', 'acez-seo' ), (string) $ai_bots_settings['llms_intro'], __( 'e.g. We write about SEO and WordPress.', 'acez-seo' ) ); $this->ui->checkbox_field( 'noai', __( 'Send the noai/noimageai signal (opt-out from AI training on your content)', 'acez-seo' ), (bool) $ai_bots_settings['noai'] ); echo '
'; echo '

' . esc_html__( 'Block selected AI bots in robots.txt', 'acez-seo' ) . '

'; echo '

' . esc_html__( 'This is a request, not a real block — honest bots respect it. Covers ONLY AI-training bots; search engine bots (Google/Bing) aren\'t shown here, so you don\'t accidentally block your own search visibility.', 'acez-seo' ) . '

'; $blocked = (array) $this->robots_txt->get()['blocked_bots']; echo ''; foreach ( self::ai_bot_choices() as $bot ) { printf( '', esc_html( $bot['agent'] ), esc_attr( $bot['agent'] ), checked( in_array( $bot['agent'], $blocked, true ), true, false ), esc_html__( 'Block', 'acez-seo' ) . ' (' . esc_html( $bot['label'] ) . ')' ); } echo '
%1$s
'; submit_button( __( 'Save and finish', 'acez-seo' ) ); $this->ui->form_close(); $this->ui->card_close(); } $this->ui->form_open( 'onboarding_step4_skip' ); printf( '

', esc_html__( 'Skip this step', 'acez-seo' ) ); $this->ui->form_close(); $this->ui->form_open( 'onboarding_skip' ); printf( '

', esc_html__( 'Skip the wizard', 'acez-seo' ) ); $this->ui->form_close(); } /** * Step 5 ("Widoczność i podsumowanie") — the wizard's last step: GSC * verification (reusing `IntegrationsTab`'s own field + the same * `GscVerificationConflictDetector`, M21), a Rich Results Test link, and * a "what's next" checklist pointing at the tabs the wizard doesn't (and * shouldn't) automate — per-post-type title templates, breadcrumbs, and * Custom Code. Submitting always finishes the wizard (`status=completed, * last_step=5`); the GSC code itself is optional, like every other field * in this step. */ private function render_step_5(): void { $this->render_progress( 5 ); $this->ui->card_open( __( 'Step 5: Visibility and summary', 'acez-seo' ), 'onboarding', '', 'onboarding-step-5' ); $conflict = GscVerificationConflictDetector::detect(); if ( null !== $conflict ) { printf( '

%s

', esc_html( sprintf( /* translators: %s: name of the other SEO plugin */ __( 'A Google Search Console verification code is already set in another plugin (%s). Setting it here as well would add a second, redundant meta tag.', 'acez-seo' ), $conflict ) ) ); } $this->ui->form_open( 'onboarding_step5' ); echo ''; $this->ui->text_field( 'gsc_verification_code', __( 'Google Search Console verification code (optional)', 'acez-seo' ), (string) $this->integrations->get()['gsc_verification_code'], 'abc123XYZ...', 'onboarding_gsc_verification' ); echo '
'; printf( '

%2$s

', esc_url( 'https://search.google.com/test/rich-results' ), esc_html__( 'Check your site in the Rich Results Test →', 'acez-seo' ) ); echo '

' . esc_html__( 'What\'s next?', 'acez-seo' ) . '

'; submit_button( __( 'Finish the wizard', 'acez-seo' ) ); $this->ui->form_close(); $this->ui->card_close(); $this->ui->form_open( 'onboarding_skip' ); printf( '

', esc_html__( 'Skip the wizard', 'acez-seo' ) ); $this->ui->form_close(); } /** * `KnownBots::all()` also lists real search-engine crawlers (Googlebot, * Bingbot, Applebot) — offering those as one-click blocks in a wizard * step titled "SEO ery AI" would risk someone accidentally tanking their * own search visibility. Filtered down to AI-training/AI-usage bots only; * the full list (incl. search bots) remains available on the robots.txt * tab itself. Public: also reused by `Support\SetupHealth` (M41 Dashboard * health card) to check whether any AI bot is blocked. * * @return array */ public static function ai_bot_choices(): array { $excluded = array( 'Googlebot', 'Bingbot', 'Applebot' ); return array_values( array_filter( KnownBots::all(), static fn( array $bot ): bool => ! in_array( $bot['agent'], $excluded, true ) ) ); } private function pull_import_report(): ?ImportReport { $transient_key = 'acez_seo_onboarding_import_report_' . get_current_user_id(); $stored = get_transient( $transient_key ); if ( ! is_array( $stored ) ) { return null; } delete_transient( $transient_key ); return ImportReport::from_array( $stored ); } /** * Progress bar over all 5 steps — every step is clickable/functional now. */ private function render_progress( int $current_step ): void { $steps = array( 1 => __( 'Your website', 'acez-seo' ), 2 => __( 'Migrate data', 'acez-seo' ), 3 => __( 'AI assistant', 'acez-seo' ), 4 => __( 'SEO for the AI era', 'acez-seo' ), 5 => __( 'Summary', 'acez-seo' ), ); echo '
    '; foreach ( $steps as $step_number => $step_label ) { $state = $step_number === $current_step ? 'current' : ( $step_number < $current_step ? 'done' : 'upcoming' ); printf( '
  1. %2$d. %3$s
  2. ', esc_attr( $state ), (int) $step_number, esc_html( $step_label ) ); } echo '
'; } /** * A method, not a class constant — PHP constants can't hold `__()` calls, * so the translated labels have to be built at call time. * * @return array */ private static function site_type_labels(): array { return array( 'personal_blog' => __( 'Personal blog', 'acez-seo' ), 'company' => __( 'Company', 'acez-seo' ), 'local_business' => __( 'Local business (shop/office/restaurant with an address)', 'acez-seo' ), 'shop' => __( 'Online store', 'acez-seo' ), ); } }