<?php
/**
 * Name: Hide WP Version
 * Description: Remove WordPress version number from HTML source, RSS feeds, and admin footer to hide information attackers use for targeting specific version vulnerabilities and exploits
 * Category: Security
 * Icon: -
 * UseCases: [
 *   {
 *     "title": "Security Through Obscurity",
 *     "description": "Remove WordPress version from page source to prevent attackers from identifying sites running specific vulnerable versions."
 *   },
 *   {
 *     "title": "Hide Update Status",
 *     "description": "Conceal whether site is running outdated WordPress version from public view as part of security hardening checklist."
 *   },
 *   {
 *     "title": "Reduce Attack Surface",
 *     "description": "Remove version meta tag that helps automated scanners identify potential targets running known vulnerable versions."
 *   }
 * ]
 * WhereToFind: {
 *   "location": "Page Source (HTML)",
 *   "url": "/",
 *   "instructions": "View page source (Ctrl+U / Cmd+U) - version meta tag should be removed",
 *   "newTab": true
 * }
 * Added: 2025-06-22
 * Tags: version, security, hide, meta, generator
 */

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

class SwitchboardHideWpVersion {

    public function __construct() {
        // Remove version from frontend
        remove_action('wp_head', 'wp_generator');
        add_filter('the_generator', '__return_empty_string');

        // Remove version from CSS/JS query strings
        add_filter('style_loader_src', [$this, 'remove_version_query'], 9999);
        add_filter('script_loader_src', [$this, 'remove_version_query'], 9999);

        // Remove version from admin footer
        add_filter('update_footer', '__return_empty_string', 11);
    }

    /**
     * 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 remove_version_query($src) {
        if (strpos($src, 'ver=' . get_bloginfo('version')) !== false) {
            $src = remove_query_arg('ver', $src);
        }
        return $src;
    }
}

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