Winden

Custom save path

We have added filter to save Winden files to additional location as well.

In this example we are saving files to themes/custom-theme/winden/ so we can pack products with compiled css only without Winden.

<?php
/**
 * Plugin Name: Winden Theme Files
 * Description: Save Winden files in custom-theme directory
 * Version: 1.0.0
 * Author: Your Name
 */

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

class WindenThemeFiles {
    private $theme_dir;
    
    public function __construct() {
        // Specifically set path to custom-theme
        $this->theme_dir = WP_CONTENT_DIR . '/themes/custom-theme';
        
        // Add filters for all file types
        add_filter('winden_config_file_path', [$this, 'save_to_theme'], 10, 1);
        add_filter('winden_scss_file_path', [$this, 'save_to_theme'], 10, 1);
        add_filter('winden_js_file_path', [$this, 'save_to_theme'], 10, 1);
        add_filter('winden_cache_file_path', [$this, 'save_to_theme'], 10, 1);
        
        // Create theme directory on activation
        register_activation_hook(__FILE__, [$this, 'create_theme_directory']);
    }

    /**
     * Save files to both default and theme locations
     */
    public function save_to_theme($default_path) {
        if (file_exists($default_path)) {
            $content = file_get_contents($default_path);
            
            // Get the filename from the default path
            $filename = basename($default_path);
            
            // Create theme path
            $theme_path = $this->theme_dir . '/winden/' . $filename;
            
            // Ensure directory exists
            wp_mkdir_p(dirname($theme_path));
            
            // Save to theme directory
            file_put_contents($theme_path, $content);
        }

        // Return default path to maintain original functionality
        return $default_path;
    }

    /**
     * Create winden directory in theme
     */
    public function create_theme_directory() {
        wp_mkdir_p($this->theme_dir . '/winden');
    }
}

// Initialize the plugin
new WindenThemeFiles();