ui = $ui; $this->features = $features; $this->ai_settings = $ai_settings; $this->post_type_settings = $post_type_settings; $this->setup_health = new SetupHealth( $global_settings, $ai_settings, $robots_txt, $integrations, $onboarding, $ai_bots ); } public function slug(): string { return 'dashboard'; } public function label(): string { return __( 'Dashboard', 'acez-seo' ); } public function icon(): string { return 'dashboard'; } public function enqueue(): void { } public function handles_form_key( string $raw_tab ): bool { return 'features' === sanitize_key( $raw_tab ); } /** @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 ); $flags = array(); foreach ( FeaturesRepository::KEYS as $feature_key ) { $flags[ $feature_key ] = isset( $_POST[ 'feature_' . $feature_key ] ); } // A disabled checkbox is not submitted — when the AI toggle is // greyed out (provider not ready), keep the stored value instead // of silently flipping it off. if ( ! $this->ai_settings->is_ready() ) { $flags['ai'] = (bool) ( $this->features->get()['ai'] ?? true ); } $this->features->update( $flags ); return array( 'tab' => 'dashboard' ); } public function render(): void { $post_types = PostTypes::supported(); $this->render_welcome_panel(); $this->render_setup_health_card(); // Row 1: feature toggles left, Free vs Pro teaser right. echo '
'; echo '
'; $this->render_features_card(); echo '
'; echo '
'; $this->render_free_pro_card(); echo '
'; echo '
'; /** * Fires between the dashboard's top row and the per-post-type stats — * extensions (e.g. the Pro addon's Search Console trend card, M29) * inject full-width cards here. */ do_action( 'acez_seo_dashboard_cards' ); // Row 2, full width: quick per-post-type status overview. echo '

' . esc_html__( 'A quick overview of SEO/schema.org status for every supported content type.', 'acez-seo' ) . '

'; if ( array() !== $post_types ) { echo '
'; foreach ( $post_types as $post_type ) { $this->render_stat_card( $post_type ); } echo '
'; } else { echo '
' . esc_html__( 'No public content types were detected.', 'acez-seo' ) . '
'; } } private function render_welcome_panel(): void { // NOT a licence gate on functionality (M69 Etap 7 acceptance // criterion). This only picks which half of the "Free vs Pro" card to // show — marketing copy on our own screen, which WordPress.org // Guideline 11 explicitly allows. Nothing a user can DO depends on it. $is_pro = \AcezSeo\Support\ProGate::is_active(); $features = array( __( 'Automatic SEO meta tags — title, description, Open Graph, and Twitter Cards', 'acez-seo' ), __( 'Structured schema.org data (JSON-LD) combined into one consistent graph', 'acez-seo' ), __( 'Location rules — page templates and conditions that decide where data appears', 'acez-seo' ), __( 'Support for posts, pages, any CPT, and taxonomy archives', 'acez-seo' ), __( 'A graphical robots.txt editor and integration with WordPress\'s built-in sitemap', 'acez-seo' ), ); if ( $is_pro ) { $features[] = __( 'Pro active: redirects manager and 404 monitor, bulk AI generation, premium schema (recipes, events, job postings, courses) and full content analysis', 'acez-seo' ); } echo '
'; echo '
' . wp_kses( $this->ui->menu_icon_svg(), KsesTags::svg() ) . '
'; echo '
'; echo '

' . esc_html__( 'Welcome to Acez SEO AI', 'acez-seo' ); if ( $is_pro ) { echo ' ' . esc_html__( 'Pro', 'acez-seo' ) . ''; } echo '

'; echo '

' . ( $is_pro ? esc_html__( 'Acez SEO AI automatically generates SEO meta tags and structured schema.org data (JSON-LD) for posts, pages, and custom content types — with an active Pro license you also get redirects, a 404 monitor, bulk AI generation and premium schema types, all tied together in one coherent system, without manually pasting code.', 'acez-seo' ) : esc_html__( 'Acez SEO AI automatically generates SEO meta tags and structured schema.org data (JSON-LD) for posts, pages, and custom content types — helping search engines and AI bots better understand your site, without manually pasting code.', 'acez-seo' ) ) . '

'; echo '
    '; foreach ( $features as $feature ) { echo '
  • ' . esc_html( $feature ) . '
  • '; } echo '
'; echo '
'; echo '
'; } /** * "Kondycja konfiguracji" (M41, last item): reports setup completion from * the REAL state of the underlying options (`Support\SetupHealth`), not * from the onboarding wizard's own progress flag — a site configured by * hand without ever running the wizard still shows 100%. Stays visible at * 100% as a passive green confirmation (user decision) rather than * disappearing — only the "Dokończ konfigurację" call-to-action drops * away once there is nothing left to finish. */ private function render_setup_health_card(): void { $report = $this->setup_health->report(); $percent = $report['percent']; echo '
'; echo '
' . esc_html__( 'Setup health', 'acez-seo' ) . wp_kses( HelpIcon::render( 'setup_health' ), KsesTags::help_icon() ) . '
'; echo '
'; printf( '
', absint( $percent ) ); printf( '

%1$d%% %2$s

', absint( $percent ), 100 === $percent ? esc_html__( 'Basic setup complete.', 'acez-seo' ) : esc_html__( 'A few steps are still waiting to be finished.', 'acez-seo' ) ); echo '
    '; foreach ( $report['steps'] as $step ) { printf( '
  • %2$s%3$s
  • ', $step['done'] ? 'done' : 'pending', wp_kses( $this->setup_health_icon( $step['done'] ), KsesTags::svg() ), esc_html( $step['label'] ) ); } echo '
'; if ( null !== $report['next_incomplete_step'] ) { printf( '

%2$s

', esc_url( add_query_arg( array( 'page' => FormControls::PAGE_SLUG, 'tab' => 'onboarding', 'step' => $report['next_incomplete_step'] ), admin_url( 'admin.php' ) ) ), esc_html__( 'Finish setup', 'acez-seo' ) ); } echo '
'; echo '
'; } /** * Free vs Pro teaser (dashboard row 1, right of the feature toggles): * a quick honest contrast, not a hard paywall — the free version stays * fully functional on its own (see the License tab notice). */ private function render_free_pro_card(): void { $free_items = array( __( 'SEO meta tags, Open Graph and Twitter Cards', 'acez-seo' ), __( 'Schema.org (JSON-LD) linked into a single graph', 'acez-seo' ), __( 'AI content generation (your own API key)', 'acez-seo' ), __( 'Basic in-editor content analysis (keyphrase, lengths, alt text)', 'acez-seo' ), __( 'AI image analysis for alt text — the model looks at the picture, not just the file name', 'acez-seo' ), ); // 'new' => true marks features shipped in the LATEST round with the // "Nowość" chip — existing installs updating the plugin might // otherwise miss them. Move the flag forward each round, don't let it // accumulate: a chip on half the list stops meaning anything. $pro_items = array( array( 'label' => __( 'Redirect manager and 404 error monitor', 'acez-seo' ) ), array( 'label' => __( 'Full content analysis: Polish inflection, readability, AI review', 'acez-seo' ) ), array( 'label' => __( 'Bulk AI generation for many posts at once', 'acez-seo' ) ), array( 'label' => __( 'Internal linking suggestions (AI)', 'acez-seo' ) ), array( 'label' => __( 'Google Search Console integration (search data, quick wins)', 'acez-seo' ) ), array( 'label' => __( 'Premium schema: recipes, events, job postings, courses', 'acez-seo' ) ), array( 'label' => __( 'AI meta translation from the original post (multilingual sites)', 'acez-seo' ) ), array( 'label' => __( 'Full schema control: edit node properties and add custom nodes from a form', 'acez-seo' ), 'new' => true ), ); echo '
'; echo '
' . esc_html__( 'Free vs Pro', 'acez-seo' ) . '
'; echo '
'; echo '

' . esc_html__( 'The free version is fully functional. Pro adds tools for larger sites and teams.', 'acez-seo' ) . '

'; echo '

' . esc_html__( 'What you have (Free)', 'acez-seo' ) . '

'; echo '
    '; foreach ( $free_items as $item ) { printf( '
  • %1$s%2$s
  • ', wp_kses( $this->free_pro_icon( 'check' ), KsesTags::svg() ), esc_html( $item ) ); } echo '
'; echo '

' . esc_html__( 'Unlock with Pro', 'acez-seo' ) . '

'; echo '
    '; foreach ( $pro_items as $item ) { printf( '
  • %1$s%2$s%3$s
  • ', wp_kses( $this->free_pro_icon( 'lock' ), KsesTags::svg() ), esc_html( $item['label'] ), ! empty( $item['new'] ) ? ' ' . esc_html__( 'New', 'acez-seo' ) . '' : '' ); } echo '
'; printf( '

%2$s

', esc_url( ProProductLink::url() ), esc_html__( 'See Pro →', 'acez-seo' ) ); echo '
'; echo '
'; } /** * Deliberately its own icon rather than reusing `free_pro_icon('lock')` * for the "pending" state — the lock icon elsewhere on this Dashboard * means "gated behind Pro", which is not what an unfinished FREE setup * step means; a plain empty ring avoids that mix-up. */ private function setup_health_icon( bool $done ): string { if ( $done ) { return $this->free_pro_icon( 'check' ); } return ''; } private function free_pro_icon( string $name ): string { if ( 'check' === $name ) { return ''; } return ''; } private function render_features_card(): void { $features = $this->features->get(); $rows = array( 'meta_title' => array( __( 'Meta title', 'acez-seo' ), __( 'The page title tag: uses your "SEO title" or the template, and generates one automatically only when you leave those fields empty.', 'acez-seo' ), 'feature_meta_title' ), 'meta_description' => array( __( 'Meta description', 'acez-seo' ), __( 'The meta description tag: uses your "Meta description" or the template, and the excerpt/content only when you leave those fields empty.', 'acez-seo' ), 'feature_meta_description' ), 'meta_robots' => array( __( 'Meta robots', 'acez-seo' ), __( 'Automatically generate the robots tag (index/follow) per post and content-type settings.', 'acez-seo' ), 'feature_meta_robots' ), 'open_graph' => array( __( 'Open Graph', 'acez-seo' ), __( 'Open Graph tags for sharing on Facebook and other social networks.', 'acez-seo' ), 'feature_open_graph' ), 'twitter_cards' => array( __( 'Twitter cards', 'acez-seo' ), __( 'Twitter cards tags for sharing on X/Twitter.', 'acez-seo' ), 'feature_twitter_cards' ), 'canonical' => array( __( 'Canonical URL', 'acez-seo' ), __( 'Automatically generate a canonical URL to avoid duplicated content.', 'acez-seo' ), 'feature_canonical' ), 'rel_links' => array( __( '"rel" links', 'acez-seo' ), __( 'rel="prev"/"next" links for paginated pages (Google has ignored them since 2019; Bing and others still use them).', 'acez-seo' ), 'feature_rel_links' ), 'sitemap' => array( __( 'XML sitemap', 'acez-seo' ), __( 'WordPress\'s built-in sitemap helping crawlers index the site content.', 'acez-seo' ), 'feature_sitemap' ), 'image_alt' => array( __( 'Image alt text', 'acez-seo' ), __( 'Automatically fill in empty image alt text (from the caption/title).', 'acez-seo' ), 'feature_image_alt' ), 'breadcrumbs' => array( __( 'Breadcrumbs', 'acez-seo' ), __( 'The [acez_seo_breadcrumbs] shortcode for inserting a breadcrumb trail into your template or content.', 'acez-seo' ), 'breadcrumbs' ), 'rss_backlink' => array( __( 'RSS backlink', 'acez-seo' ), __( 'A note with a link to the original appended to posts in the RSS feed — deters content theft.', 'acez-seo' ), 'feature_rss_backlink' ), 'schema' => array( __( 'Schema.org', 'acez-seo' ), __( 'A global switch for JSON-LD structured data (works together with the per-content-type settings).', 'acez-seo' ), 'feature_schema' ), 'ai' => array( __( 'AI support', 'acez-seo' ), __( 'The "Generate with AI" buttons in the editors and the media library. Active only after an AI provider has been configured and tested.', 'acez-seo' ), 'ai_feature' ), ); $ai_ready = $this->ai_settings->is_ready(); $this->ui->card_open( __( 'Features', 'acez-seo' ), 'dashboard', '', 'features' ); echo '

' . esc_html__( 'Global switches for individual plugin features. Turning a feature off here overrides all its detailed settings — useful when another plugin manages part of your SEO.', 'acez-seo' ) . '

'; $this->ui->form_open( 'features' ); echo ''; foreach ( $rows as $key => $row ) { list( $label, $description ) = $row; $help = HelpIcon::render( (string) $row[2] ); $extra = ''; if ( 'sitemap' === $key ) { $extra = sprintf( ' %2$s', esc_url( home_url( '/wp-sitemap.xml' ) ), esc_html__( 'View your sitemap ↗', 'acez-seo' ) ); } // The AI toggle stays greyed out until a provider is configured // AND has passed a connection test (see help entry 'ai_feature'). $disabled = 'ai' === $key && ! $ai_ready; printf( '', esc_html( $label ), esc_attr( $key ), checked( (bool) ( $features[ $key ] ?? true ), true, false ), esc_html( $description ), wp_kses( $extra, KsesTags::link() ), wp_kses( $help, KsesTags::help_icon() ), $disabled ? ' disabled' : '' ); } echo '
%1$s%6$s%5$s
'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); } private function render_stat_card( string $post_type ): void { $settings = $this->post_type_settings->get( $post_type ); $post_type_object = get_post_type_object( $post_type ); $label = $post_type_object instanceof \WP_Post_Type ? $post_type_object->labels->name : $post_type; $counts = (array) wp_count_posts( $post_type ); $published = isset( $counts['publish'] ) ? (int) $counts['publish'] : 0; $with_custom_title = new \WP_Query( array( 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => 1, 'fields' => 'ids', 'no_found_rows' => false, 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- one-off "has any post a custom SEO title?" status probe for the Dashboard card, capped at posts_per_page 1 with fields=ids; runs only on this plugin's own admin screen, never on the front end. array( 'key' => MetaFields::TITLE, 'value' => '', 'compare' => '!=', ), ), ) ); echo '
'; printf( '
%1$s%2$s
', wp_kses( $this->ui->tab_icon_svg( 'post-type' ), KsesTags::svg() ), esc_html( $label ) ); printf( '
%1$s%2$d
', esc_html__( 'Published posts', 'acez-seo' ), absint( $published ) ); printf( '
%1$s%2$d
', esc_html__( 'With a custom SEO title', 'acez-seo' ), (int) $with_custom_title->found_posts ); printf( '
%1$s%3$s
', esc_html__( 'Schema.org', 'acez-seo' ), (bool) $settings['schema_enabled'] ? 'acez-seo-badge--on' : 'acez-seo-badge--off', (bool) $settings['schema_enabled'] ? esc_html__( 'enabled', 'acez-seo' ) : esc_html__( 'disabled', 'acez-seo' ) ); printf( '', esc_url( add_query_arg( array( 'page' => FormControls::PAGE_SLUG, 'tab' => 'content', 'post_type' => $post_type ), admin_url( 'admin.php' ) ) ), esc_html__( 'Configure', 'acez-seo' ) ); echo '
'; } }