<?php
/**
 * STB Theme — SEO Bootstrap
 * Single entry point loaded from functions.php.
 *
 * @package STB
 */

if (!defined('ABSPATH')) exit;

require_once __DIR__ . '/seo-data.php';
require_once __DIR__ . '/seo.php';
require_once __DIR__ . '/schema.php';
require_once __DIR__ . '/sitemap.php';

/**
 * One-time rewrite flush after activation/update.
 */
add_action('after_switch_theme', function () {
    flush_rewrite_rules(false);
});

/**
 * Strip legacy inline schema blocks from post content at render time.
 * The blocks live between STB_SCHEMA_START / STB_SCHEMA_END markers in the DB.
 * We do NOT modify the DB — only filter the_content for display.
 * Our /inc/schema.php emits clean head-level JSON-LD instead.
 */
add_filter('the_content', function ($content) {
    if (strpos($content, 'STB_SCHEMA_START') === false) return $content;
    return preg_replace(
        '/<!--\s*STB_SCHEMA_START\s*-->.*?<!--\s*STB_SCHEMA_END\s*-->/s',
        '',
        $content
    );
}, 1);
