Make your WordPress site irresistible. Natural SEO attraction with: - robots.txt management - sitemap.xml generation - LLMs.txt support - Google integration (Analytics, Search Console, Tag Manager) - Schema.org structured data - Open Graph / Twitter Card meta tags - AMP support - Visual elements gallery - Built-in backup/restore module Includes build.sh and .distignore for WordPress-installable release ZIPs.
173 lines
5.3 KiB
PHP
173 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* LLMs.txt Module for TigerStyle Heat
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class TigerStyleSEO_Llms_txt {
|
|
private static $instance = null;
|
|
|
|
public static function instance() {
|
|
if (is_null(self::$instance)) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
private function __construct() {
|
|
$this->init_hooks();
|
|
}
|
|
|
|
/**
|
|
* Initialize hooks
|
|
*/
|
|
private function init_hooks() {
|
|
add_action('template_redirect', array($this, 'handle_llmstxt_request'), 1);
|
|
add_action('admin_post_update_llmstxt', array($this, 'handle_llmstxt_update'));
|
|
}
|
|
|
|
/**
|
|
* Handle llms.txt requests
|
|
*/
|
|
public function handle_llmstxt_request() {
|
|
if (!$this->is_llmstxt_request()) {
|
|
return;
|
|
}
|
|
|
|
// Check if llms.txt is enabled
|
|
if (!TigerStyleSEO_Utils::get_option('llmstxt_enabled', false)) {
|
|
status_header(404);
|
|
return;
|
|
}
|
|
|
|
$content = $this->get_llmstxt_content();
|
|
|
|
// Set headers for markdown content
|
|
header('Content-Type: text/plain; charset=UTF-8');
|
|
header('X-Robots-Tag: noindex, nofollow, nosnippet, noarchive');
|
|
|
|
echo $content;
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Check if current request is for llms.txt
|
|
*/
|
|
private function is_llmstxt_request() {
|
|
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
|
|
return (strpos($request_uri, '/llms.txt') !== false) ||
|
|
(isset($_GET['llms']) && $_GET['llms'] === 'txt');
|
|
}
|
|
|
|
/**
|
|
* Get llms.txt content
|
|
*/
|
|
private function get_llmstxt_content() {
|
|
$custom_content = TigerStyleSEO_Utils::get_option('llmstxt_content', '');
|
|
if (!empty($custom_content)) {
|
|
return $custom_content;
|
|
}
|
|
|
|
// Generate default content
|
|
return $this->get_default_llmstxt();
|
|
}
|
|
|
|
/**
|
|
* Generate default llms.txt content based on WordPress site
|
|
*/
|
|
private function get_default_llmstxt() {
|
|
$site_name = get_bloginfo('name');
|
|
$site_description = get_bloginfo('description');
|
|
|
|
$content = "# {$site_name}\n\n";
|
|
|
|
if (!empty($site_description)) {
|
|
$content .= "> {$site_description}\n\n";
|
|
}
|
|
|
|
$content .= "This is a WordPress website";
|
|
if (!empty($site_description)) {
|
|
$content .= " focused on " . strtolower($site_description);
|
|
}
|
|
$content .= ". Below are the key resources for understanding this site:\n\n";
|
|
|
|
// Add main navigation links
|
|
$content .= "## Main Pages\n";
|
|
|
|
// Get key pages
|
|
$pages = get_pages(array(
|
|
'sort_order' => 'ASC',
|
|
'sort_column' => 'menu_order',
|
|
'number' => 10
|
|
));
|
|
|
|
foreach ($pages as $page) {
|
|
$content .= "- [{$page->post_title}](" . get_permalink($page) . ")";
|
|
if (!empty($page->post_excerpt)) {
|
|
$content .= ": " . wp_strip_all_tags($page->post_excerpt);
|
|
}
|
|
$content .= "\n";
|
|
}
|
|
|
|
// Add recent posts
|
|
$posts = get_posts(array(
|
|
'numberposts' => 5,
|
|
'post_status' => 'publish'
|
|
));
|
|
|
|
if (!empty($posts)) {
|
|
$content .= "\n## Recent Content\n";
|
|
foreach ($posts as $post) {
|
|
$content .= "- [{$post->post_title}](" . get_permalink($post) . ")";
|
|
if (!empty($post->post_excerpt)) {
|
|
$content .= ": " . wp_strip_all_tags($post->post_excerpt);
|
|
}
|
|
$content .= "\n";
|
|
}
|
|
}
|
|
|
|
// Add contact and additional info
|
|
$content .= "\n## Technical Information\n";
|
|
$content .= "- WordPress Version: " . get_bloginfo('version') . "\n";
|
|
$content .= "- Site URL: " . get_bloginfo('url') . "\n";
|
|
$content .= "- Admin Email: " . get_bloginfo('admin_email') . "\n";
|
|
$content .= "- Language: " . get_bloginfo('language') . "\n";
|
|
$content .= "- Content generated: " . current_time('Y-m-d H:i:s T') . "\n\n";
|
|
$content .= "---\n";
|
|
$content .= "*This llms.txt file is automatically generated by TigerStyle Heat Manager*";
|
|
|
|
return $content;
|
|
}
|
|
|
|
/**
|
|
* Handle llms.txt settings update
|
|
*/
|
|
public function handle_llmstxt_update() {
|
|
// Verify nonce and permissions
|
|
if (!TigerStyleSEO_Utils::verify_nonce('llmstxt_nonce', 'update_llmstxt') ||
|
|
!TigerStyleSEO_Utils::current_user_can_manage()) {
|
|
wp_die(__('Security check failed.', 'tigerstyle-heat'));
|
|
}
|
|
|
|
// Update settings
|
|
$enabled = isset($_POST['llmstxt_enabled']) ? 1 : 0;
|
|
$content = isset($_POST['llmstxt_content']) ? TigerStyleSEO_Utils::sanitize_textarea($_POST['llmstxt_content']) : '';
|
|
|
|
TigerStyleSEO_Utils::update_option('llmstxt_enabled', $enabled);
|
|
TigerStyleSEO_Utils::update_option('llmstxt_content', $content);
|
|
|
|
TigerStyleSEO_Utils::redirect_with_message('llmstxt_updated');
|
|
}
|
|
|
|
/**
|
|
* Render admin page
|
|
*/
|
|
public function render_admin_page() {
|
|
include TIGERSTYLE_HEAT_PLUGIN_DIR . 'admin/pages/llms-txt.php';
|
|
}
|
|
}
|