Fix critical Twig filter error in product selector template

Fixed "Unknown 'esc_attr' filter" error that occurred when rendering
the product selector template. The issue was caused by WordPress
escaping functions being registered only as Twig functions, not filters.

Changes:
- Added TwigFilter registrations for esc_html, esc_attr, esc_url
- Template now supports both filter syntax (|esc_attr) and function syntax
- Fixes compatibility issues when other plugins use their own Twig instances
- Version bump to 1.1.5

This resolves the bug documented in logs/fatal-errors-2025-12-31.log

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-31 21:06:08 +01:00
parent 867abc8f63
commit 8fc0614334
3 changed files with 45 additions and 2 deletions

View File

@@ -5,6 +5,44 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.5] - 2025-12-31
### Fixed
- **CRITICAL**: Fixed Twig template error "Unknown 'esc_attr' filter" when rendering product selector
- Template compatibility issue when other plugins (e.g., WooCommerce Tier and Package Prices) use Twig
- WordPress escaping functions now properly registered as both Twig functions AND filters
### Technical
- Added `TwigFilter` registrations for `esc_html`, `esc_attr`, and `esc_url` in `Plugin::init_twig()`
- Template can now use both syntax styles: `{{ value|esc_attr }}` (filter) and `{{ esc_attr(value) }}` (function)
- Prevents conflicts when multiple plugins bundle their own Twig installations
### Notes
- Previous versions only registered escaping functions as Twig functions, not filters
- Template used filter syntax (`|esc_attr`) which failed when parsed by external Twig instances
- Fix ensures compatibility regardless of which Twig instance processes the template
## [1.1.4] - 2025-12-31
### Added
- Fixed price field in Composable Options tab for easier price configuration
- JavaScript toggle to show/hide fixed price field based on selected pricing mode
### Changed
- Simplified pricing mode description text in admin interface
- Fixed price field now appears dynamically when "Fixed" pricing mode is selected
### Technical
- Added `_regular_price` field with `composable_fixed_price_field` CSS class in `Product_Data.php`
- Implemented `toggleFixedPriceField()` JavaScript function in `assets/js/admin.js`
- Progressive disclosure pattern improves admin UX by showing relevant fields only
## [1.1.3] - 2024-12-31
### Added

View File

@@ -84,6 +84,11 @@ class Plugin {
$this->twig->addFunction(new \Twig\TwigFunction('esc_html', 'esc_html'));
$this->twig->addFunction(new \Twig\TwigFunction('esc_attr', 'esc_attr'));
$this->twig->addFunction(new \Twig\TwigFunction('esc_url', 'esc_url'));
// Add WordPress escaping functions as Twig filters
$this->twig->addFilter(new \Twig\TwigFilter('esc_html', 'esc_html'));
$this->twig->addFilter(new \Twig\TwigFilter('esc_attr', 'esc_attr'));
$this->twig->addFilter(new \Twig\TwigFilter('esc_url', 'esc_url'));
}
/**

View File

@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Composable Products
* Plugin URI: https://github.com/magdev/wc-composable-product
* Description: Create composable products where customers select a limited number of items from a configurable set
* Version: 1.1.3
* Version: 1.1.5
* Author: Marco Graetsch
* Author URI: https://example.com
* License: GPL v3 or later
@@ -19,7 +19,7 @@
defined('ABSPATH') || exit;
// Define plugin constants
define('WC_COMPOSABLE_PRODUCT_VERSION', '1.1.3');
define('WC_COMPOSABLE_PRODUCT_VERSION', '1.1.5');
define('WC_COMPOSABLE_PRODUCT_FILE', __FILE__);
define('WC_COMPOSABLE_PRODUCT_PATH', plugin_dir_path(__FILE__));
define('WC_COMPOSABLE_PRODUCT_URL', plugin_dir_url(__FILE__));