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.
757 lines
33 KiB
PHP
757 lines
33 KiB
PHP
<?php
|
|
/**
|
|
* Sitemap XML Module for TigerStyle Heat
|
|
*
|
|
* Provides comprehensive XML sitemap generation and management with support for
|
|
* posts, pages, categories, tags, and custom post types with intelligent defaults.
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class TigerStyleSEO_Sitemap_xml {
|
|
|
|
/**
|
|
* Single instance
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Option name for sitemap settings
|
|
*/
|
|
private $option_name = 'tigerstyle_heat_sitemap_xml';
|
|
|
|
/**
|
|
* Default sitemap settings
|
|
*/
|
|
private $default_settings = array();
|
|
|
|
/**
|
|
* Get instance
|
|
*/
|
|
public static function instance() {
|
|
if (is_null(self::$instance)) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
private function __construct() {
|
|
$this->init_default_settings();
|
|
$this->init_hooks();
|
|
}
|
|
|
|
/**
|
|
* Initialize WordPress hooks
|
|
*/
|
|
private function init_hooks() {
|
|
// Handle sitemap generation
|
|
add_action('init', array($this, 'register_sitemap_endpoints'));
|
|
|
|
// Handle admin form submissions
|
|
add_action('admin_post_tigerstyle_save_sitemap_xml', array($this, 'save_settings'));
|
|
|
|
// Add admin scripts
|
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
|
|
|
|
// Flush rewrite rules when settings change
|
|
add_action('update_option_' . $this->option_name, array($this, 'flush_rewrite_rules'));
|
|
}
|
|
|
|
/**
|
|
* Initialize default sitemap settings
|
|
*/
|
|
private function init_default_settings() {
|
|
$this->default_settings = array(
|
|
'enabled' => true,
|
|
'include_posts' => true,
|
|
'include_pages' => true,
|
|
'include_categories' => true,
|
|
'include_tags' => true,
|
|
'include_custom_post_types' => array(),
|
|
'exclude_post_ids' => '',
|
|
'max_entries' => 50000,
|
|
'split_by_post_type' => false,
|
|
'include_images' => true,
|
|
'include_lastmod' => true,
|
|
'include_changefreq' => true,
|
|
'include_priority' => true,
|
|
'default_changefreq' => 'monthly',
|
|
'ping_search_engines' => true,
|
|
'cache_duration' => 24, // hours
|
|
'exclude_noindex' => true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Register sitemap endpoints
|
|
*/
|
|
public function register_sitemap_endpoints() {
|
|
$settings = $this->get_settings();
|
|
|
|
if (!$settings['enabled']) {
|
|
return;
|
|
}
|
|
|
|
// Main sitemap index
|
|
add_rewrite_rule('^sitemap\.xml$', 'index.php?tigerstyle_sitemap=index', 'top');
|
|
add_rewrite_rule('^sitemap_index\.xml$', 'index.php?tigerstyle_sitemap=index', 'top');
|
|
|
|
// Individual sitemaps
|
|
add_rewrite_rule('^sitemap-([^/]+)\.xml$', 'index.php?tigerstyle_sitemap=$matches[1]', 'top');
|
|
|
|
// Add query vars
|
|
add_filter('query_vars', array($this, 'add_query_vars'));
|
|
|
|
// Handle template redirects
|
|
add_action('template_redirect', array($this, 'handle_sitemap_request'));
|
|
}
|
|
|
|
/**
|
|
* Add query vars
|
|
*/
|
|
public function add_query_vars($vars) {
|
|
$vars[] = 'tigerstyle_sitemap';
|
|
return $vars;
|
|
}
|
|
|
|
/**
|
|
* Handle sitemap requests
|
|
*/
|
|
public function handle_sitemap_request() {
|
|
$sitemap = get_query_var('tigerstyle_sitemap');
|
|
|
|
if (empty($sitemap)) {
|
|
return;
|
|
}
|
|
|
|
// Set XML headers
|
|
header('Content-Type: application/xml; charset=utf-8');
|
|
|
|
if ($sitemap === 'index') {
|
|
$this->generate_sitemap_index();
|
|
} else {
|
|
$this->generate_sitemap($sitemap);
|
|
}
|
|
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Generate sitemap index
|
|
*/
|
|
private function generate_sitemap_index() {
|
|
$settings = $this->get_settings();
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
|
|
|
|
// Posts sitemap
|
|
if ($settings['include_posts']) {
|
|
$this->add_sitemap_to_index('posts');
|
|
}
|
|
|
|
// Pages sitemap
|
|
if ($settings['include_pages']) {
|
|
$this->add_sitemap_to_index('pages');
|
|
}
|
|
|
|
// Categories sitemap
|
|
if ($settings['include_categories']) {
|
|
$this->add_sitemap_to_index('categories');
|
|
}
|
|
|
|
// Tags sitemap
|
|
if ($settings['include_tags']) {
|
|
$this->add_sitemap_to_index('tags');
|
|
}
|
|
|
|
// Custom post types
|
|
if (!empty($settings['include_custom_post_types'])) {
|
|
foreach ($settings['include_custom_post_types'] as $post_type) {
|
|
$this->add_sitemap_to_index($post_type);
|
|
}
|
|
}
|
|
|
|
echo '</sitemapindex>' . "\n";
|
|
}
|
|
|
|
/**
|
|
* Add sitemap to index
|
|
*/
|
|
private function add_sitemap_to_index($type) {
|
|
$url = home_url("/sitemap-{$type}.xml");
|
|
$lastmod = date('c');
|
|
|
|
echo " <sitemap>\n";
|
|
echo " <loc>" . esc_xml($url) . "</loc>\n";
|
|
echo " <lastmod>" . esc_xml($lastmod) . "</lastmod>\n";
|
|
echo " </sitemap>\n";
|
|
}
|
|
|
|
/**
|
|
* Generate individual sitemap
|
|
*/
|
|
private function generate_sitemap($type) {
|
|
$settings = $this->get_settings();
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
|
|
|
|
if ($settings['include_images']) {
|
|
echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"';
|
|
}
|
|
|
|
echo '>' . "\n";
|
|
|
|
switch ($type) {
|
|
case 'posts':
|
|
$this->generate_posts_sitemap();
|
|
break;
|
|
case 'pages':
|
|
$this->generate_pages_sitemap();
|
|
break;
|
|
case 'categories':
|
|
$this->generate_categories_sitemap();
|
|
break;
|
|
case 'tags':
|
|
$this->generate_tags_sitemap();
|
|
break;
|
|
default:
|
|
// Handle custom post types
|
|
$this->generate_custom_post_type_sitemap($type);
|
|
break;
|
|
}
|
|
|
|
echo '</urlset>' . "\n";
|
|
}
|
|
|
|
/**
|
|
* Generate posts sitemap
|
|
*/
|
|
private function generate_posts_sitemap() {
|
|
$settings = $this->get_settings();
|
|
$exclude_ids = array_filter(array_map('trim', explode(',', $settings['exclude_post_ids'])));
|
|
|
|
$posts = get_posts(array(
|
|
'post_type' => 'post',
|
|
'post_status' => 'publish',
|
|
'numberposts' => $settings['max_entries'],
|
|
'exclude' => $exclude_ids,
|
|
'meta_query' => $settings['exclude_noindex'] ? array(
|
|
array(
|
|
'key' => '_yoast_wpseo_meta-robots-noindex',
|
|
'value' => '1',
|
|
'compare' => '!='
|
|
)
|
|
) : array()
|
|
));
|
|
|
|
foreach ($posts as $post) {
|
|
$this->add_url_to_sitemap($post);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generate pages sitemap
|
|
*/
|
|
private function generate_pages_sitemap() {
|
|
$settings = $this->get_settings();
|
|
$exclude_ids = array_filter(array_map('trim', explode(',', $settings['exclude_post_ids'])));
|
|
|
|
$pages = get_posts(array(
|
|
'post_type' => 'page',
|
|
'post_status' => 'publish',
|
|
'numberposts' => $settings['max_entries'],
|
|
'exclude' => $exclude_ids,
|
|
'meta_query' => $settings['exclude_noindex'] ? array(
|
|
array(
|
|
'key' => '_yoast_wpseo_meta-robots-noindex',
|
|
'value' => '1',
|
|
'compare' => '!='
|
|
)
|
|
) : array()
|
|
));
|
|
|
|
foreach ($pages as $page) {
|
|
$this->add_url_to_sitemap($page);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generate categories sitemap
|
|
*/
|
|
private function generate_categories_sitemap() {
|
|
$categories = get_categories(array(
|
|
'hide_empty' => true,
|
|
'number' => $this->get_settings()['max_entries']
|
|
));
|
|
|
|
foreach ($categories as $category) {
|
|
$this->add_taxonomy_url_to_sitemap($category);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generate tags sitemap
|
|
*/
|
|
private function generate_tags_sitemap() {
|
|
$tags = get_tags(array(
|
|
'hide_empty' => true,
|
|
'number' => $this->get_settings()['max_entries']
|
|
));
|
|
|
|
foreach ($tags as $tag) {
|
|
$this->add_taxonomy_url_to_sitemap($tag);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generate custom post type sitemap
|
|
*/
|
|
private function generate_custom_post_type_sitemap($post_type) {
|
|
$settings = $this->get_settings();
|
|
|
|
if (!in_array($post_type, $settings['include_custom_post_types'])) {
|
|
return;
|
|
}
|
|
|
|
$posts = get_posts(array(
|
|
'post_type' => $post_type,
|
|
'post_status' => 'publish',
|
|
'numberposts' => $settings['max_entries']
|
|
));
|
|
|
|
foreach ($posts as $post) {
|
|
$this->add_url_to_sitemap($post);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add URL to sitemap for posts/pages
|
|
*/
|
|
private function add_url_to_sitemap($post) {
|
|
$settings = $this->get_settings();
|
|
$url = get_permalink($post);
|
|
|
|
echo " <url>\n";
|
|
echo " <loc>" . esc_xml($url) . "</loc>\n";
|
|
|
|
if ($settings['include_lastmod']) {
|
|
echo " <lastmod>" . esc_xml(date('c', strtotime($post->post_modified))) . "</lastmod>\n";
|
|
}
|
|
|
|
if ($settings['include_changefreq']) {
|
|
echo " <changefreq>" . esc_xml($settings['default_changefreq']) . "</changefreq>\n";
|
|
}
|
|
|
|
if ($settings['include_priority']) {
|
|
$priority = ($post->post_type === 'page') ? '0.8' : '0.6';
|
|
echo " <priority>" . esc_xml($priority) . "</priority>\n";
|
|
}
|
|
|
|
// Add images if enabled
|
|
if ($settings['include_images']) {
|
|
$this->add_post_images_to_sitemap($post);
|
|
}
|
|
|
|
echo " </url>\n";
|
|
}
|
|
|
|
/**
|
|
* Add URL to sitemap for taxonomy terms
|
|
*/
|
|
private function add_taxonomy_url_to_sitemap($term) {
|
|
$settings = $this->get_settings();
|
|
$url = get_term_link($term);
|
|
|
|
if (is_wp_error($url)) {
|
|
return;
|
|
}
|
|
|
|
echo " <url>\n";
|
|
echo " <loc>" . esc_xml($url) . "</loc>\n";
|
|
|
|
if ($settings['include_changefreq']) {
|
|
echo " <changefreq>weekly</changefreq>\n";
|
|
}
|
|
|
|
if ($settings['include_priority']) {
|
|
echo " <priority>0.5</priority>\n";
|
|
}
|
|
|
|
echo " </url>\n";
|
|
}
|
|
|
|
/**
|
|
* Add post images to sitemap
|
|
*/
|
|
private function add_post_images_to_sitemap($post) {
|
|
// Get featured image
|
|
$featured_image_id = get_post_thumbnail_id($post->ID);
|
|
if ($featured_image_id) {
|
|
$image_url = wp_get_attachment_image_url($featured_image_id, 'full');
|
|
if ($image_url) {
|
|
echo " <image:image>\n";
|
|
echo " <image:loc>" . esc_xml($image_url) . "</image:loc>\n";
|
|
echo " </image:image>\n";
|
|
}
|
|
}
|
|
|
|
// Get images from content
|
|
preg_match_all('/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $post->post_content, $matches);
|
|
if (!empty($matches[1])) {
|
|
foreach (array_slice($matches[1], 0, 10) as $image_url) {
|
|
if (filter_var($image_url, FILTER_VALIDATE_URL)) {
|
|
echo " <image:image>\n";
|
|
echo " <image:loc>" . esc_xml($image_url) . "</image:loc>\n";
|
|
echo " </image:image>\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get current settings
|
|
*/
|
|
private function get_settings() {
|
|
$settings = get_option($this->option_name, array());
|
|
return wp_parse_args($settings, $this->default_settings);
|
|
}
|
|
|
|
/**
|
|
* Save settings from admin form
|
|
*/
|
|
public function save_settings() {
|
|
// Verify nonce
|
|
if (!wp_verify_nonce($_POST['tigerstyle_sitemap_nonce'], 'tigerstyle_sitemap_save')) {
|
|
wp_die('Security check failed');
|
|
}
|
|
|
|
// Check user permissions
|
|
if (!current_user_can('manage_options')) {
|
|
wp_die('Insufficient permissions');
|
|
}
|
|
|
|
$settings = array();
|
|
|
|
// Basic settings
|
|
$settings['enabled'] = isset($_POST['enabled']) ? true : false;
|
|
$settings['include_posts'] = isset($_POST['include_posts']) ? true : false;
|
|
$settings['include_pages'] = isset($_POST['include_pages']) ? true : false;
|
|
$settings['include_categories'] = isset($_POST['include_categories']) ? true : false;
|
|
$settings['include_tags'] = isset($_POST['include_tags']) ? true : false;
|
|
$settings['include_custom_post_types'] = isset($_POST['include_custom_post_types']) ? $_POST['include_custom_post_types'] : array();
|
|
$settings['exclude_post_ids'] = sanitize_text_field($_POST['exclude_post_ids']);
|
|
$settings['max_entries'] = intval($_POST['max_entries']);
|
|
$settings['split_by_post_type'] = isset($_POST['split_by_post_type']) ? true : false;
|
|
$settings['include_images'] = isset($_POST['include_images']) ? true : false;
|
|
$settings['include_lastmod'] = isset($_POST['include_lastmod']) ? true : false;
|
|
$settings['include_changefreq'] = isset($_POST['include_changefreq']) ? true : false;
|
|
$settings['include_priority'] = isset($_POST['include_priority']) ? true : false;
|
|
$settings['default_changefreq'] = sanitize_text_field($_POST['default_changefreq']);
|
|
$settings['ping_search_engines'] = isset($_POST['ping_search_engines']) ? true : false;
|
|
$settings['cache_duration'] = intval($_POST['cache_duration']);
|
|
$settings['exclude_noindex'] = isset($_POST['exclude_noindex']) ? true : false;
|
|
|
|
// Save settings
|
|
update_option($this->option_name, $settings);
|
|
|
|
// Flush rewrite rules
|
|
flush_rewrite_rules();
|
|
|
|
// Redirect back with success message
|
|
wp_redirect(add_query_arg(array(
|
|
'page' => 'tigerstyle-heat',
|
|
'message' => 'sitemap_xml_updated'
|
|
), admin_url('admin.php')));
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Flush rewrite rules when settings change
|
|
*/
|
|
public function flush_rewrite_rules() {
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
/**
|
|
* Enqueue admin scripts
|
|
*/
|
|
public function enqueue_admin_scripts($hook) {
|
|
if ($hook !== 'toplevel_page_tigerstyle-heat') {
|
|
return;
|
|
}
|
|
|
|
wp_enqueue_script('tigerstyle-sitemap-admin', TIGERSTYLE_HEAT_PLUGIN_URL . 'admin/js/sitemap-admin.js', array('jquery'), TIGERSTYLE_HEAT_VERSION, true);
|
|
}
|
|
|
|
/**
|
|
* Render admin page
|
|
*/
|
|
public function render_admin_page() {
|
|
$settings = $this->get_settings();
|
|
$sitemap_index_url = home_url('/sitemap.xml');
|
|
$available_post_types = get_post_types(array('public' => true), 'objects');
|
|
unset($available_post_types['attachment']);
|
|
|
|
?>
|
|
<div class="tigerstyle-sitemap-container">
|
|
<div class="seo-info-box">
|
|
<h3><?php _e('XML Sitemap Configuration', 'tigerstyle-heat'); ?></h3>
|
|
<p><?php _e('Generate and configure XML sitemaps to help search engines discover and index your content efficiently.', 'tigerstyle-heat'); ?></p>
|
|
|
|
<div class="sitemap-current-status">
|
|
<h4><?php _e('Current Sitemap Status', 'tigerstyle-heat'); ?></h4>
|
|
<p>
|
|
<strong><?php _e('Sitemap Index URL:', 'tigerstyle-heat'); ?></strong>
|
|
<a href="<?php echo esc_url($sitemap_index_url); ?>" target="_blank"><?php echo esc_url($sitemap_index_url); ?></a>
|
|
<span class="dashicons dashicons-external"></span>
|
|
</p>
|
|
<button type="button" id="test-sitemap-btn" class="button"><?php _e('Test Sitemap Access', 'tigerstyle-heat'); ?></button>
|
|
<button type="button" id="validate-sitemap-btn" class="button"><?php _e('Validate XML Structure', 'tigerstyle-heat'); ?></button>
|
|
<div id="sitemap-test-result" style="margin-top: 10px;"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
|
|
<input type="hidden" name="action" value="tigerstyle_save_sitemap_xml">
|
|
<?php wp_nonce_field('tigerstyle_sitemap_save', 'tigerstyle_sitemap_nonce'); ?>
|
|
|
|
<div class="sitemap-config-grid">
|
|
<div class="sitemap-config-section">
|
|
<h4><?php _e('Basic Settings', 'tigerstyle-heat'); ?></h4>
|
|
<table class="form-table">
|
|
<tr>
|
|
<th scope="row"><?php _e('Enable XML Sitemaps', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<label>
|
|
<input type="checkbox" name="enabled" value="1" <?php checked($settings['enabled']); ?>>
|
|
<?php _e('Generate XML sitemaps for this website', 'tigerstyle-heat'); ?>
|
|
</label>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><?php _e('Maximum Entries per Sitemap', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<input type="number" name="max_entries" value="<?php echo esc_attr($settings['max_entries']); ?>" min="100" max="50000" step="100" class="regular-text">
|
|
<p class="description"><?php _e('Maximum number of URLs in each sitemap file (recommended: 50,000 or less)', 'tigerstyle-heat'); ?></p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="sitemap-config-section">
|
|
<h4><?php _e('Content Types', 'tigerstyle-heat'); ?></h4>
|
|
<table class="form-table">
|
|
<tr>
|
|
<th scope="row"><?php _e('Include in Sitemap', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<label><input type="checkbox" name="include_posts" value="1" <?php checked($settings['include_posts']); ?>> <?php _e('Posts', 'tigerstyle-heat'); ?></label><br>
|
|
<label><input type="checkbox" name="include_pages" value="1" <?php checked($settings['include_pages']); ?>> <?php _e('Pages', 'tigerstyle-heat'); ?></label><br>
|
|
<label><input type="checkbox" name="include_categories" value="1" <?php checked($settings['include_categories']); ?>> <?php _e('Categories', 'tigerstyle-heat'); ?></label><br>
|
|
<label><input type="checkbox" name="include_tags" value="1" <?php checked($settings['include_tags']); ?>> <?php _e('Tags', 'tigerstyle-heat'); ?></label><br>
|
|
</td>
|
|
</tr>
|
|
<?php if (!empty($available_post_types)): ?>
|
|
<tr>
|
|
<th scope="row"><?php _e('Custom Post Types', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<?php foreach ($available_post_types as $post_type): ?>
|
|
<?php if (!in_array($post_type->name, array('post', 'page'))): ?>
|
|
<label>
|
|
<input type="checkbox" name="include_custom_post_types[]" value="<?php echo esc_attr($post_type->name); ?>" <?php checked(in_array($post_type->name, $settings['include_custom_post_types'])); ?>>
|
|
<?php echo esc_html($post_type->label); ?>
|
|
</label><br>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sitemap-config-grid">
|
|
<div class="sitemap-config-section">
|
|
<h4><?php _e('XML Structure Settings', 'tigerstyle-heat'); ?></h4>
|
|
<table class="form-table">
|
|
<tr>
|
|
<th scope="row"><?php _e('Include Additional Data', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<label><input type="checkbox" name="include_lastmod" value="1" <?php checked($settings['include_lastmod']); ?>> <?php _e('Last Modified Date', 'tigerstyle-heat'); ?></label><br>
|
|
<label><input type="checkbox" name="include_changefreq" value="1" <?php checked($settings['include_changefreq']); ?>> <?php _e('Change Frequency', 'tigerstyle-heat'); ?></label><br>
|
|
<label><input type="checkbox" name="include_priority" value="1" <?php checked($settings['include_priority']); ?>> <?php _e('Priority Values', 'tigerstyle-heat'); ?></label><br>
|
|
<label><input type="checkbox" name="include_images" value="1" <?php checked($settings['include_images']); ?>> <?php _e('Images (Google Image Sitemap)', 'tigerstyle-heat'); ?></label><br>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><?php _e('Default Change Frequency', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<select name="default_changefreq">
|
|
<option value="always" <?php selected($settings['default_changefreq'], 'always'); ?>><?php _e('Always', 'tigerstyle-heat'); ?></option>
|
|
<option value="hourly" <?php selected($settings['default_changefreq'], 'hourly'); ?>><?php _e('Hourly', 'tigerstyle-heat'); ?></option>
|
|
<option value="daily" <?php selected($settings['default_changefreq'], 'daily'); ?>><?php _e('Daily', 'tigerstyle-heat'); ?></option>
|
|
<option value="weekly" <?php selected($settings['default_changefreq'], 'weekly'); ?>><?php _e('Weekly', 'tigerstyle-heat'); ?></option>
|
|
<option value="monthly" <?php selected($settings['default_changefreq'], 'monthly'); ?>><?php _e('Monthly', 'tigerstyle-heat'); ?></option>
|
|
<option value="yearly" <?php selected($settings['default_changefreq'], 'yearly'); ?>><?php _e('Yearly', 'tigerstyle-heat'); ?></option>
|
|
<option value="never" <?php selected($settings['default_changefreq'], 'never'); ?>><?php _e('Never', 'tigerstyle-heat'); ?></option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="sitemap-config-section">
|
|
<h4><?php _e('Advanced Options', 'tigerstyle-heat'); ?></h4>
|
|
<table class="form-table">
|
|
<tr>
|
|
<th scope="row"><?php _e('Exclude Posts/Pages', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<input type="text" name="exclude_post_ids" value="<?php echo esc_attr($settings['exclude_post_ids']); ?>" class="regular-text" placeholder="1,2,3">
|
|
<p class="description"><?php _e('Comma-separated list of post/page IDs to exclude from sitemap', 'tigerstyle-heat'); ?></p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><?php _e('Additional Settings', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<label><input type="checkbox" name="exclude_noindex" value="1" <?php checked($settings['exclude_noindex']); ?>> <?php _e('Exclude noindex pages', 'tigerstyle-heat'); ?></label><br>
|
|
<label><input type="checkbox" name="ping_search_engines" value="1" <?php checked($settings['ping_search_engines']); ?>> <?php _e('Ping search engines when sitemap updates', 'tigerstyle-heat'); ?></label><br>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><?php _e('Cache Duration (hours)', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<input type="number" name="cache_duration" value="<?php echo esc_attr($settings['cache_duration']); ?>" min="1" max="168" step="1" class="small-text">
|
|
<p class="description"><?php _e('How long to cache sitemap files before regenerating', 'tigerstyle-heat'); ?></p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sitemap-preview-section">
|
|
<h4><?php _e('Sitemap URLs', 'tigerstyle-heat'); ?></h4>
|
|
<button type="button" id="generate-sitemap-urls-btn" class="button"><?php _e('Generate Sitemap URLs', 'tigerstyle-heat'); ?></button>
|
|
<div id="sitemap-urls-preview" class="sitemap-preview-content"></div>
|
|
</div>
|
|
|
|
<?php submit_button(__('Save Sitemap Configuration', 'tigerstyle-heat'), 'primary', 'submit'); ?>
|
|
</form>
|
|
</div>
|
|
|
|
<style>
|
|
.tigerstyle-sitemap-container { max-width: 1200px; }
|
|
.sitemap-config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0; }
|
|
.sitemap-config-section { background: #f9f9f9; padding: 15px; border-radius: 5px; }
|
|
.sitemap-current-status { background: #e7f3ff; padding: 15px; border-left: 4px solid #0073aa; margin: 15px 0; }
|
|
.sitemap-preview-content { background: #f1f1f1; padding: 15px; border: 1px solid #ddd; max-height: 300px; overflow-y: auto; }
|
|
.sitemap-preview-section { margin: 20px 0; }
|
|
@media (max-width: 768px) { .sitemap-config-grid { grid-template-columns: 1fr; } }
|
|
</style>
|
|
|
|
<script>
|
|
jQuery(document).ready(function($) {
|
|
// Test sitemap access
|
|
$('#test-sitemap-btn').click(function() {
|
|
var btn = $(this);
|
|
var result = $('#sitemap-test-result');
|
|
|
|
btn.prop('disabled', true).text('<?php _e('Testing...', 'tigerstyle-heat'); ?>');
|
|
|
|
$.get('<?php echo esc_js($sitemap_index_url); ?>')
|
|
.done(function(data) {
|
|
result.html('<div class="notice notice-success inline"><p><strong><?php _e('Success!', 'tigerstyle-heat'); ?></strong> <?php _e('Sitemap is accessible and working.', 'tigerstyle-heat'); ?></p></div>');
|
|
})
|
|
.fail(function() {
|
|
result.html('<div class="notice notice-error inline"><p><strong><?php _e('Error!', 'tigerstyle-heat'); ?></strong> <?php _e('Could not access sitemap file.', 'tigerstyle-heat'); ?></p></div>');
|
|
})
|
|
.always(function() {
|
|
btn.prop('disabled', false).text('<?php _e('Test Sitemap Access', 'tigerstyle-heat'); ?>');
|
|
});
|
|
});
|
|
|
|
// Validate XML structure
|
|
$('#validate-sitemap-btn').click(function() {
|
|
var btn = $(this);
|
|
var result = $('#sitemap-test-result');
|
|
|
|
btn.prop('disabled', true).text('<?php _e('Validating...', 'tigerstyle-heat'); ?>');
|
|
|
|
$.get('<?php echo esc_js($sitemap_index_url); ?>')
|
|
.done(function(data) {
|
|
try {
|
|
var parser = new DOMParser();
|
|
var xmlDoc = parser.parseFromString(data, "text/xml");
|
|
var parseError = xmlDoc.getElementsByTagName("parsererror");
|
|
|
|
if (parseError.length > 0) {
|
|
result.html('<div class="notice notice-error inline"><p><strong><?php _e('Invalid XML!', 'tigerstyle-heat'); ?></strong> <?php _e('The sitemap contains XML syntax errors.', 'tigerstyle-heat'); ?></p></div>');
|
|
} else {
|
|
result.html('<div class="notice notice-success inline"><p><strong><?php _e('Valid XML!', 'tigerstyle-heat'); ?></strong> <?php _e('The sitemap XML structure is valid.', 'tigerstyle-heat'); ?></p></div>');
|
|
}
|
|
} catch (e) {
|
|
result.html('<div class="notice notice-error inline"><p><strong><?php _e('Validation Error!', 'tigerstyle-heat'); ?></strong> <?php _e('Could not validate XML structure.', 'tigerstyle-heat'); ?></p></div>');
|
|
}
|
|
})
|
|
.fail(function() {
|
|
result.html('<div class="notice notice-error inline"><p><strong><?php _e('Error!', 'tigerstyle-heat'); ?></strong> <?php _e('Could not access sitemap for validation.', 'tigerstyle-heat'); ?></p></div>');
|
|
})
|
|
.always(function() {
|
|
btn.prop('disabled', false).text('<?php _e('Validate XML Structure', 'tigerstyle-heat'); ?>');
|
|
});
|
|
});
|
|
|
|
// Generate sitemap URLs preview
|
|
$('#generate-sitemap-urls-btn').click(function() {
|
|
var btn = $(this);
|
|
var preview = $('#sitemap-urls-preview');
|
|
var enabled = $('input[name="enabled"]').is(':checked');
|
|
|
|
btn.prop('disabled', true).text('<?php _e('Generating...', 'tigerstyle-heat'); ?>');
|
|
|
|
if (!enabled) {
|
|
preview.html('<p><?php _e('XML Sitemaps are disabled. Enable them to see sitemap URLs.', 'tigerstyle-heat'); ?></p>');
|
|
btn.prop('disabled', false).text('<?php _e('Generate Sitemap URLs', 'tigerstyle-heat'); ?>');
|
|
return;
|
|
}
|
|
|
|
var urls = ['<?php echo esc_js($sitemap_index_url); ?>'];
|
|
|
|
if ($('input[name="include_posts"]').is(':checked')) {
|
|
urls.push('<?php echo esc_js(home_url('/sitemap-posts.xml')); ?>');
|
|
}
|
|
if ($('input[name="include_pages"]').is(':checked')) {
|
|
urls.push('<?php echo esc_js(home_url('/sitemap-pages.xml')); ?>');
|
|
}
|
|
if ($('input[name="include_categories"]').is(':checked')) {
|
|
urls.push('<?php echo esc_js(home_url('/sitemap-categories.xml')); ?>');
|
|
}
|
|
if ($('input[name="include_tags"]').is(':checked')) {
|
|
urls.push('<?php echo esc_js(home_url('/sitemap-tags.xml')); ?>');
|
|
}
|
|
|
|
$('input[name="include_custom_post_types[]"]:checked').each(function() {
|
|
urls.push('<?php echo esc_js(home_url('/sitemap-')); ?>' + $(this).val() + '.xml');
|
|
});
|
|
|
|
var html = '<h5><?php _e('Generated Sitemap URLs:', 'tigerstyle-heat'); ?></h5><ul>';
|
|
urls.forEach(function(url) {
|
|
html += '<li><a href="' + url + '" target="_blank">' + url + '</a></li>';
|
|
});
|
|
html += '</ul>';
|
|
|
|
preview.html(html);
|
|
btn.prop('disabled', false).text('<?php _e('Generate Sitemap URLs', 'tigerstyle-heat'); ?>');
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
}
|