<?php
/**
 * Name: Disable Author Archives
 * Description: Disable author archive pages and remove all author links from site to prevent username discovery, reduce crawl footprint, and eliminate unnecessary archive pages
 * Category: Security
 * Icon: -
 * UseCases: [
 *   {
 *     "title": "Prevent Username Discovery",
 *     "description": "Block /author/username pages to prevent hackers from discovering admin usernames for brute force attacks."
 *   },
 *   {
 *     "title": "Single-Author Blogs",
 *     "description": "Disable unused author archives on personal blogs where author pages serve no purpose and only expose security information."
 *   },
 *   {
 *     "title": "Security Hardening",
 *     "description": "Return 404 for all author archive URLs to eliminate common username enumeration attack vector."
 *   }
 * ]
 * Added: 2025-07-12
 * Tags: author, archives, security, username, enumeration, disable
 * WhereToFind: {
 *   "location": "Works automatically",
 *   "url": "",
 *   "instructions": "All author archive pages return 404",
 *   "newTab": false
 * }
 */

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

class SwitchboardDisableAuthorArchives {

    public function __construct() {
        add_action('template_redirect', [$this, 'disable_author_pages']);
        add_filter('author_link', [$this, 'disable_author_link'], 10, 3);
        remove_filter('template_redirect', 'redirect_canonical');
    }

    /**
     * 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_author_pages() {
        if (is_author()) {
            global $wp_query;
            if (isset($wp_query) && is_object($wp_query)) {
                $wp_query->set_404();
                status_header(404);
            }
        }
    }
    
    public function disable_author_link($link, $author_id, $author_nicename) {
        return '#';
    }
}

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