'on'); $s = get_option(CITAMI_LLMS_SETTINGS_OPT, array()); if (is_array($s) && isset($s['enabled']) && $s['enabled'] === 'off') { $d['enabled'] = 'off'; } return $d; } add_action('admin_init', function () { register_setting('citami_seo', CITAMI_LLMS_SETTINGS_OPT, array( 'type' => 'array', 'sanitize_callback' => function ($v) { return array('enabled' => (is_array($v) && isset($v['enabled']) && $v['enabled'] === 'off') ? 'off' : 'on'); }, 'default' => array(), )); register_setting('citami_seo', CITAMI_LLMS_MANUAL_OPT, array( 'type' => 'string', 'sanitize_callback' => function ($v) { return mb_substr(trim(wp_strip_all_tags((string) $v)), 0, 20000); }, 'default' => '', )); }); /** Manual part: option, else a minimal header from the site identity. */ function citami_llms_manual_part() { $manual = trim((string) get_option(CITAMI_LLMS_MANUAL_OPT, '')); if ($manual !== '') { return $manual; } $lines = array('# ' . get_bloginfo('name')); $tagline = get_bloginfo('description'); if ($tagline !== '') { $lines[] = ''; $lines[] = '> ' . $tagline; } return implode("\n", $lines); } /** Full virtual document. */ function citami_llms_virtual_body() { return citami_llms_manual_part() . "\n\n" . citami_build_llms_auto_section() . "\n"; } function citami_llms_physical_exists() { return is_file(ABSPATH . 'llms.txt'); } /** 2.60 — pinning into llms.txt only matters when our virtual llms.txt is the one served. */ function citami_llms_pin_available() { return citami_llms_settings()['enabled'] === 'on' && !citami_llms_physical_exists(); } /** 2.60 — pinned page ids (option citami_llms_pinned), in order. */ function citami_llms_pinned_ids() { return array_values(array_filter(array_map('intval', (array) get_option('citami_llms_pinned', array())))); } /** 2.60 — link that takes one page out of the "Important pages" section. */ function citami_llms_unpin_url($post_id) { return add_query_arg( array('action' => 'citami_llms_unpin', 'id' => (int) $post_id, '_citami_llms_nonce' => wp_create_nonce('citami_llms_unpin')), admin_url('admin-post.php') ); } function citami_handle_llms_unpin() { if (!current_user_can('manage_options')) { wp_die('Permesso negato.', '', array('response' => 403)); } $nonce = isset($_REQUEST['_citami_llms_nonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_citami_llms_nonce'])) : ''; if (!wp_verify_nonce($nonce, 'citami_llms_unpin')) { wp_die('Nonce non valido.', '', array('response' => 403)); } $id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; $before = citami_llms_pinned_ids(); $after = array_values(array_diff($before, array($id))); if ($id > 0 && count($after) < count($before)) { update_option('citami_llms_pinned', $after, false); $title = $id > 0 ? wp_strip_all_tags((string) get_the_title($id)) : ''; $notice = array('type' => 'success', 'message' => sprintf(citami_t('"%s" tolta dalle pagine in cima a llms.txt.', '"%s" removed from the pages at the top of llms.txt.'), $title !== '' ? $title : '#' . $id)); if (function_exists('citami_activity_log')) { citami_activity_log('llms', sprintf(citami_t('Pagina tolta da llms.txt: %s', 'Page removed from llms.txt: %s'), $title !== '' ? $title : '#' . $id), 1); } } else { $notice = array('type' => 'info', 'message' => citami_t('Quella pagina non era in cima a llms.txt: nulla è cambiato.', 'That page was not at the top of llms.txt: nothing changed.')); } set_transient('citami_action_notice', $notice, 30); wp_safe_redirect(citami_admin_url('seo', array('open' => 1)) . '#citami-seo-llms'); exit; } add_action('admin_post_citami_llms_unpin', 'citami_handle_llms_unpin'); add_action('init', function () { if (is_admin() || citami_llms_settings()['enabled'] !== 'on' || empty($_SERVER['REQUEST_URI'])) { return; } $path = wp_parse_url(esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])), PHP_URL_PATH); if ($path !== '/llms.txt' || citami_llms_physical_exists()) { return; } if (!headers_sent()) { header('Content-Type: text/plain; charset=UTF-8'); header('X-Robots-Tag: noindex'); } echo citami_llms_virtual_body(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- text/plain response (llms.txt), not HTML. exit; }, 20); // 2.70.2 — after WooCommerce registers product_cat (init 5): at priority 2 the "Product categories" section was silently empty on every store. add_action('citami_seo_settings_rows', function () { $s = citami_llms_settings(); ?>
| llms.txt | |
|---|---|