<?php
/**
 * Name: Disable Feeds
 * Description: Disable all RSS, Atom, and RDF feeds site-wide to prevent content scraping, reduce server load, and stop automated bots from accessing feed
 * Category: Optimization
 * Icon: -
  * UseCases: [
 *   {
 *     "title": "Block Content Scrapers",
 *     "description": "Prevent automated bots from scraping your content via RSS feeds and republishing it elsewhere."
 *   },
 *   {
 *     "title": "Reduce Server Load",
 *     "description": "Disable unused RSS/Atom feeds to save server resources, especially if you don\'t have subscribers using them."
 *   }
 * ]
 * Added: 2025-06-15
 * Tags: rss, atom, feed, disable, syndication
 * WhereToFind: {
 *   "location": "Works automatically",
 *   "url": "",
 *   "instructions": "All RSS/Atom feeds disabled - returns 404 if accessed",
 *   "newTab": false
 * }
 */

// Prevent direct access
if (!defined('ABSPATH')) exit;

class SwitchboardDisableFeeds {

    public function __construct() {
        add_action('do_feed', [$this, 'disable_feed'], 1);
        add_action('do_feed_rdf', [$this, 'disable_feed'], 1);
        add_action('do_feed_rss', [$this, 'disable_feed'], 1);
        add_action('do_feed_rss2', [$this, 'disable_feed'], 1);
        add_action('do_feed_atom', [$this, 'disable_feed'], 1);
        add_action('do_feed_rss2_comments', [$this, 'disable_feed'], 1);
        add_action('do_feed_atom_comments', [$this, 'disable_feed'], 1);
        remove_action('wp_head', 'feed_links', 2);
        remove_action('wp_head', 'feed_links_extra', 3);
    }

    /**
     * Register data locations for cleanup system
     *
     * @return array Data storage locations
     */
    public function register_data_locations() {
        return [
            'options' => [],
            'option_patterns' => [],
            'tables' => [],
            'post_meta' => [],
            'user_meta' => [],
        ];
    }

    public function disable_feed() {
        status_header(404);
        wp_die(esc_html__('Feeds are not available.', 'wpswitchboard'), '', ['response' => 404]);
    }
}

// Initialize and register with data system
$switchboard_instance = new SwitchboardDisableFeeds();
Switchboard_Data_Registry::get_instance()->auto_register($switchboard_instance, __FILE__);
