quote (apart veld) if ( ! empty( $settings['auto_description'] ) ) { $tagline = get_bloginfo( 'description' ); if ( $tagline ) { $lines[] = "> {$tagline}"; $lines[] = ''; } } // Vrije introductietekst / geïmporteerde beschrijving (raw Markdown) if ( ! empty( $settings['optional_description'] ) ) { $lines[] = trim( $settings['optional_description'] ); $lines[] = ''; } // ── Auto: Pagina's ─────────────────────────────────────── if ( ! empty( $settings['auto_pages'] ) ) { $pages = get_pages( [ 'post_status' => 'publish', 'sort_column' => 'menu_order', 'number' => 60, ] ); if ( ! empty( $pages ) ) { $lines[] = "## Pagina's"; foreach ( $pages as $page ) { $url = get_permalink( $page ); $title = $page->post_title; $desc = $page->post_excerpt ? ': ' . wp_strip_all_tags( $page->post_excerpt ) : ''; $lines[] = "- [{$title}]({$url}){$desc}"; } $lines[] = ''; } } // ── Auto: Categorieën + berichten ──────────────────────── if ( ! empty( $settings['auto_categories'] ) ) { $categories = get_categories( [ 'hide_empty' => true ] ); foreach ( $categories as $cat ) { $lines[] = "## {$cat->name}"; $posts = get_posts( [ 'category' => $cat->term_id, 'posts_per_page' => 10, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', ] ); foreach ( $posts as $post ) { $url = get_permalink( $post ); $title = $post->post_title; $excerpt = get_the_excerpt( $post ); $desc = $excerpt ? ': ' . wp_trim_words( $excerpt, 12 ) : ''; $lines[] = "- [{$title}]({$url}){$desc}"; } $lines[] = ''; } } // ── Auto: Custom Post Types ────────────────────────────── if ( ! empty( $settings['auto_cpt'] ) && is_array( $settings['auto_cpt'] ) ) { foreach ( $settings['auto_cpt'] as $cpt_name ) { $cpt_obj = get_post_type_object( $cpt_name ); if ( ! $cpt_obj ) continue; $posts = get_posts( [ 'post_type' => $cpt_name, 'posts_per_page' => 30, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', ] ); if ( empty( $posts ) ) continue; $lines[] = "## {$cpt_obj->labels->name}"; foreach ( $posts as $post ) { $lines[] = "- [{$post->post_title}](" . get_permalink( $post ) . ')'; } $lines[] = ''; } } // ── Handmatige secties ─────────────────────────────────── if ( ! empty( $settings['sections'] ) && is_array( $settings['sections'] ) ) { foreach ( $settings['sections'] as $section ) { if ( empty( $section['name'] ) ) continue; $lines[] = "## {$section['name']}"; if ( ! empty( $section['links'] ) ) { foreach ( $section['links'] as $link ) { if ( empty( $link['url'] ) ) continue; $label = ! empty( $link['label'] ) ? $link['label'] : $link['url']; $desc = ! empty( $link['desc'] ) ? ': ' . $link['desc'] : ''; $lines[] = "- [{$label}]({$link['url']}){$desc}"; } } $lines[] = ''; } } // ── Auto: Sitemap (Optional sectie) ───────────────────── if ( ! empty( $settings['auto_sitemap'] ) && ! $this->has_manual_sitemap_link( $settings ) ) { $sitemap_url = $this->get_sitemap_url(); if ( $sitemap_url ) { $lines[] = '## Optional'; $lines[] = "- [Sitemap index]({$sitemap_url})"; $lines[] = ''; } } // Verwijder overbodige lege regels aan het einde. while ( ! empty( $lines ) && end( $lines ) === '' ) { array_pop( $lines ); } return implode( "\n", $lines ) . "\n"; } // ── Hulpfuncties voor detectie ─────────────────────────────── /** * Geeft de sitemap-URL terug op basis van gedetecteerde SEO-plugin. * * @return string */ public function get_sitemap_url() { // Yoast SEO if ( defined( 'WPSEO_VERSION' ) ) { return home_url( '/sitemap_index.xml' ); } // RankMath if ( defined( 'RANK_MATH_VERSION' ) ) { return home_url( '/sitemap_index.xml' ); } // WordPress Core Sitemaps (WP 5.5+, altijd beschikbaar) return home_url( '/wp-sitemap.xml' ); } /** * Geeft de naam van de gedetecteerde sitemap-provider terug. * * @return string */ public function detect_sitemap_provider() { if ( defined( 'WPSEO_VERSION' ) ) return 'Yoast SEO'; if ( defined( 'RANK_MATH_VERSION' ) ) return 'RankMath'; return 'WordPress (ingebouwd, /wp-sitemap.xml)'; } /** * Controleert of de handmatige secties al een "Optional"-sectie met een * sitemap-link bevatten, zodat de auto-sitemap-sectie niet dubbel wordt * toegevoegd (bijv. na import van een bestaand llms.txt dat dit al had). * * @param array $settings * @return bool */ private function has_manual_sitemap_link( array $settings ) { if ( empty( $settings['sections'] ) || ! is_array( $settings['sections'] ) ) { return false; } foreach ( $settings['sections'] as $section ) { if ( empty( $section['name'] ) || 'optional' !== strtolower( $section['name'] ) ) { continue; } foreach ( ( $section['links'] ?? [] ) as $link ) { if ( ! empty( $link['url'] ) && false !== strpos( strtolower( $link['url'] ), 'sitemap' ) ) { return true; } } } return false; } /** * Geeft alle publieke, niet-ingebouwde custom post types terug. * * @return WP_Post_Type[] */ public function get_custom_post_types() { return get_post_types( [ 'public' => true, '_builtin' => false ], 'objects' ); } }