admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'adct_llms_admin' ), 'i18n' => array( 'generating' => __( 'Generating…', 'adct-llm-index' ), 'done' => __( 'Files generated.', 'adct-llm-index' ), 'error' => __( 'Generation failed.', 'adct-llm-index' ), ), ) ); } public static function handle_disable_yoast() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized', 'adct-llm-index' ) ); } check_admin_referer( 'adct_llms_disable_yoast' ); ADCT_LLMS_Yoast::disable_llms_txt(); wp_safe_redirect( add_query_arg( array( 'page' => 'adct-llm-index', 'tab' => 'tools', 'updated' => '1', ), admin_url( 'options-general.php' ) ) ); exit; } public static function maybe_show_setup_notice() { if ( ! current_user_can( 'manage_options' ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( $screen && 'settings_page_adct-llm-index' === $screen->id ) { return; } $checklist = ADCT_LLMS_Activator::get_setup_checklist(); $pending = array_filter( $checklist, static function ( $item ) { return empty( $item['done'] ); } ); if ( empty( $pending ) ) { return; } $url = admin_url( 'options-general.php?page=adct-llm-index&tab=tools' ); echo '

'; printf( /* translators: %s: settings URL */ esc_html__( 'ADCT LLM Index setup is incomplete (%1$d steps remaining). %2$sOpen setup checklist%3$s.', 'adct-llm-index' ), count( $pending ), '', '' ); echo '

'; } public static function handle_save() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized', 'adct-llm-index' ) ); } check_admin_referer( 'adct_llms_save_settings' ); $raw_input = filter_input( INPUT_POST, 'adct_llms', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); $raw = is_array( $raw_input ) ? wp_unslash( $raw_input ) : array(); if ( ! empty( $_POST['adct_llms_generate_summary'] ) ) { $preview_settings = ADCT_LLMS_Settings::sanitize( ADCT_LLMS_Settings::preprocess_form( $raw ) ); $raw['site_summary'] = self::build_auto_summary( $preview_settings ); } ADCT_LLMS_Settings::update( $raw ); ADCT_LLMS_Cron::reschedule(); $return_tab = isset( $_POST['adct_llms_return_tab'] ) ? sanitize_key( wp_unslash( $_POST['adct_llms_return_tab'] ) ) : 'general'; $allowed_tabs = array( 'general', 'sold', 'cpts', 'llms', 'full', 'tools', 'license' ); if ( ! in_array( $return_tab, $allowed_tabs, true ) ) { $return_tab = 'general'; } $redirect_args = array( 'page' => 'adct-llm-index', 'tab' => $return_tab, 'updated' => '1', ); if ( ! empty( $_POST['adct_llms_generate_summary'] ) ) { $redirect_args['summary_generated'] = '1'; } if ( ! empty( $_POST['adct_llms_regenerate_now'] ) ) { $result = ADCT_LLMS_File_Writer::regenerate_all(); if ( is_wp_error( $result ) ) { unset( $redirect_args['updated'] ); $redirect_args['error'] = rawurlencode( $result->get_error_message() ); wp_safe_redirect( add_query_arg( $redirect_args, admin_url( 'options-general.php' ) ) ); exit; } } wp_safe_redirect( add_query_arg( $redirect_args, admin_url( 'options-general.php' ) ) ); exit; } /** * Builds a factual summary from the current site setup. * * @param array $settings Settings candidate. * @return string */ private static function build_auto_summary( array $settings ) { $site_name = trim( (string) get_bloginfo( 'name' ) ); $tagline = trim( (string) get_bloginfo( 'description' ) ); $host = wp_parse_url( home_url(), PHP_URL_HOST ); $host = is_string( $host ) ? preg_replace( '/^www\./', '', $host ) : ''; $shop_page_title = ''; $shop_page_id = absint( $settings['shop_page_id'] ?? 0 ); if ( $shop_page_id > 0 ) { $shop_page_title = trim( (string) get_the_title( $shop_page_id ) ); } $product_count = 0; if ( post_type_exists( 'product' ) ) { $product_counts = wp_count_posts( 'product' ); if ( isset( $product_counts->publish ) ) { $product_count = max( 0, (int) $product_counts->publish ); } } $post_count = 0; $post_counts = wp_count_posts( 'post' ); if ( isset( $post_counts->publish ) ) { $post_count = max( 0, (int) $post_counts->publish ); } $subject = $site_name ? $site_name : __( 'This website', 'adct-llm-index' ); $sentences = array(); if ( '' !== $tagline ) { $sentences[] = sprintf( '%1$s is %2$s.', $subject, rtrim( $tagline, ". \t\n\r\0\x0B" ) ); } elseif ( '' !== $host ) { /* translators: 1: site name, 2: site URL host */ $sentences[] = sprintf( __( '%1$s operates at %2$s.', 'adct-llm-index' ), $subject, $host ); } else { /* translators: %s: site name */ $sentences[] = sprintf( __( '%s provides content for visitors and AI assistants.', 'adct-llm-index' ), $subject ); } $details = array(); if ( '' !== $shop_page_title ) { /* translators: %s: shop page title */ $details[] = sprintf( __( 'main inventory page: %s', 'adct-llm-index' ), $shop_page_title ); } if ( $product_count > 0 ) { /* translators: %d: number of published products */ $details[] = sprintf( __( '%d published products', 'adct-llm-index' ), $product_count ); } if ( $post_count > 0 ) { /* translators: %d: number of published posts */ $details[] = sprintf( __( '%d published posts', 'adct-llm-index' ), $post_count ); } if ( ! empty( $details ) ) { $sentences[] = ucfirst( implode( ', ', $details ) ) . '.'; } $sentences[] = __( 'This index helps AI assistants discover key pages, inventory, and recent updates.', 'adct-llm-index' ); return trim( implode( ' ', $sentences ) ); } public static function ajax_regenerate() { check_ajax_referer( 'adct_llms_admin', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'Unauthorized', 'adct-llm-index' ) ), 403 ); } if ( ! ADCT_LLMS_License::is_active() ) { wp_send_json_error( array( 'message' => __( 'A valid license is required.', 'adct-llm-index' ) ), 403 ); } $result = ADCT_LLMS_File_Writer::regenerate_all(); if ( is_wp_error( $result ) ) { wp_send_json_error( array( 'message' => $result->get_error_message() ) ); } wp_send_json_success( array( 'message' => $result['message'], 'llms' => $result['llms'], 'full' => $result['full'], 'paths' => $result['paths'], ) ); } public static function ajax_preview() { check_ajax_referer( 'adct_llms_admin', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'Unauthorized', 'adct-llm-index' ) ), 403 ); } $file = isset( $_POST['file'] ) ? sanitize_key( wp_unslash( $_POST['file'] ) ) : 'llms'; wp_send_json_success( array( 'content' => ADCT_LLMS_Generator::build( $file ), ) ); } public static function render_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = ADCT_LLMS_Settings::get(); $last = ADCT_LLMS_File_Writer::get_last_generated(); $tab = sanitize_key( (string) filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ); if ( '' === $tab ) { $tab = 'general'; } $settings_updated = filter_input( INPUT_GET, 'updated', FILTER_VALIDATE_INT ); $summary_generated = filter_input( INPUT_GET, 'summary_generated', FILTER_VALIDATE_INT ); $error_message = sanitize_text_field( (string) filter_input( INPUT_GET, 'error', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ); $pages = get_pages( array( 'sort_column' => 'post_title', 'sort_order' => 'ASC' ) ); $cpts = ADCT_LLMS_Settings::get_public_post_types(); ?>

'adct-llm-index', 'tab' => $slug, ), admin_url( 'options-general.php' ) ); $class = 'nav-tab' . ( $current === $slug ? ' nav-tab-active' : '' ); printf( '%s', esc_url( $url ), esc_attr( $class ), esc_html( $label ) ); } private static function render_general_tab( array $settings, array $pages, $tab ) { $visible = ( 'general' === $tab ) ? '' : ' hidden'; ?>

'product_tag', 'taxonomy' => 'product_tag', 'term' => 'sold-cars' ) ); } ?>

$rule ) : ?>

$object ) : ?> false, 'mode' => 'latest', 'limit' => 5, 'ids' => array(), 'title' => $object->labels->name, ); self::render_section_controls( 'cpts', $post_type, $section, true ); ?>

__( 'Exclude', 'adct-llm-index' ), 'all' => __( 'All published', 'adct-llm-index' ), 'latest' => __( 'Latest N', 'adct-llm-index' ), 'selected' => __( 'Selected IDs only', 'adct-llm-index' ), 'children' => __( 'Child pages of brands hub', 'adct-llm-index' ), ); if ( 'brands' !== $section_key ) { unset( $modes['children'] ); } if ( 'pages' !== $section_key && 'brands' !== $section_key ) { unset( $modes['none'] ); } if ( 'brands' === $section_key ) { unset( $modes['all'], $modes['latest'], $modes['pinned'] ); $modes['taxonomy'] = __( 'WooCommerce / custom brand taxonomy', 'adct-llm-index' ); $modes['children'] = __( 'Child pages of brands hub', 'adct-llm-index' ); $modes['selected'] = __( 'Selected brand page IDs', 'adct-llm-index' ); } ?>

llms.txt

llms-full.txt


· · ·

'; echo ''; foreach ( $pages as $page ) { printf( '', (int) $page->ID, selected( (int) $selected, (int) $page->ID, false ), esc_html( $page->post_title ) ); } echo ''; } private static function render_page_multiselect( $name, array $selected, array $pages ) { echo ''; } private static function auto_regenerate_options() { return array( 'manual' => __( 'Manual only', 'adct-llm-index' ), 'publish' => __( 'On content publish/update (delayed 1 min)', 'adct-llm-index' ), 'daily' => __( 'Daily', 'adct-llm-index' ), 'weekly' => __( 'Weekly', 'adct-llm-index' ), ); } }