<?php
/**
 * WordPress Version Hider
 *
 * Removes WordPress version information from public output for security hardening.
 * This reduces information disclosure and makes version-specific attacks harder.
 *
 * @package VMPFence
 * @since 2.2.2
 */

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

class VMPFence_WP_Version_Hider {

    /**
     * Initialize version hiding hooks
     *
     * @since 2.2.2
     */
    public static function init() {
        // Check if feature is enabled
        $enabled = VMPFence_Config::get('hide_wp_version', 0);
        
        if ($enabled != 1) {
            return;
        }

        // Remove version from HTML head
        remove_action('wp_head', 'wp_generator');
        
        // Remove version from RSS feeds
        add_filter('the_generator', '__return_empty_string');
        
        // Remove version from scripts and styles
        add_filter('style_loader_src', array(__CLASS__, 'remove_version_from_assets'), 9999);
        add_filter('script_loader_src', array(__CLASS__, 'remove_version_from_assets'), 9999);
        
        // Remove version from admin footer
        add_filter('update_footer', '__return_empty_string', 11);
    }

    /**
     * Remove version query string from assets
     *
     * @param string $src Asset URL
     * @return string Modified URL without version
     */
    public static function remove_version_from_assets($src) {
        if (!$src) {
            return $src;
        }
        
        // Remove version parameter (e.g., ?ver=6.4.2)
        $src = remove_query_arg('ver', $src);
        
        return $src;
    }

    /**
     * Check if version hiding is enabled
     *
     * @since 2.2.2
     * @return bool
     */
    public static function is_enabled() {
        return (VMPFence_Config::get('hide_wp_version', 0) == 1);
    }
}
