EZ Customizer in WP Rig
WP Rig includes the EZ_Customizer component, which allows developers to register Customizer sections, settings, and controls using a declarative JSON configuration file.
Configuration File
The Customizer settings are defined in inc/EZ_Customizer/themeCustomizeSettings.json.
Basic JSON Structure
{
"theme_name": "My Theme",
"settings_id": "my_theme",
"sections": [
{
"id": "my_section",
"title": "My Section",
"description": "Description of the section.",
"priority": 30
}
],
"settings": [
{
"id": "my_setting",
"label": "My Setting",
"section": "my_section",
"type": "text",
"default": "Default Value",
"refresh": false
}
]
}
Key Properties
theme_name: Used as a prefix for control IDs.
settings_id: Used as a prefix for section IDs.
sections: An array of objects defining Customizer sections.
settings: An array of objects defining individual settings.
Field Configuration
type: Supported types include:
text, checkbox, radio, select, textarea, dropdown-pages, email, url, number, range, tel, search, password, date, time.
- Special types (handled by classes):
color, date, media.
refresh: If set to false, transport is set to postMessage (live preview). Defaults to true (full refresh).
default: Default value for the setting.
choices: An object or array for select, radio, or checkbox types.
Accessing Customizer Settings
Use the standard WordPress get_theme_mod() function to retrieve Customizer settings.
$my_setting_value = get_theme_mod( 'my_setting', 'Default Value' );
Verification & Iteration (Ralph Loop)
Use Playwright to verify your Customizer settings:
- Setting Persistence: Automate navigating to the Customizer and setting a value to ensure it saves and renders correctly.
- Visual Verification: Use
npm run test:e2e:screenshot to verify that the frontend reflects the changes made via Customizer.
- Live Preview: Verify that
postMessage refreshes are working for settings with refresh: false.
Best Practices for Agents
- Declarative First: Always prefer adding settings via
themeCustomizeSettings.json before writing manual PHP Customizer code.
- Naming Conventions: Use descriptive IDs and ensure they are unique within the project.
- Live Preview: Set
refresh: false for settings that can be updated via JavaScript (CSS changes, text swaps) to provide a better user experience.
- Section Grouping: Group related settings into sections to keep the Customizer organized.
- Sanitization: Standard WordPress Customizer sanitization is used. For complex validation, you may need to hook into
customize_register in inc/EZ_Customizer/Component.php.
- Filters: Use the
wp_rig_customizer_settings filter if you need to dynamically modify settings at runtime.
1---2name: ez-customizer3description: EZ Customizer in WP Rig4---5# EZ Customizer in WP Rig67WP Rig includes the `EZ_Customizer` component, which allows developers to register Customizer sections, settings, and controls using a declarative JSON configuration file.89## Configuration File1011The Customizer settings are defined in `inc/EZ_Customizer/themeCustomizeSettings.json`.1213### Basic JSON Structure14```json15{16 "theme_name": "My Theme",17 "settings_id": "my_theme",18 "sections": [19 {20 "id": "my_section",21 "title": "My Section",22 "description": "Description of the section.",23 "priority": 3024 }25 ],26 "settings": [27 {28 "id": "my_setting",29 "label": "My Setting",30 "section": "my_section",31 "type": "text",32 "default": "Default Value",33 "refresh": false34 }35 ]36}37```3839### Key Properties4041- **`theme_name`**: Used as a prefix for control IDs.42- **`settings_id`**: Used as a prefix for section IDs.43- **`sections`**: An array of objects defining Customizer sections.44- **`settings`**: An array of objects defining individual settings.4546### Field Configuration4748- **`type`**: Supported types include:49 - `text`, `checkbox`, `radio`, `select`, `textarea`, `dropdown-pages`, `email`, `url`, `number`, `range`, `tel`, `search`, `password`, `date`, `time`.50 - Special types (handled by classes): `color`, `date`, `media`.51- **`refresh`**: If set to `false`, `transport` is set to `postMessage` (live preview). Defaults to `true` (full refresh).52- **`default`**: Default value for the setting.53- **`choices`**: An object or array for `select`, `radio`, or `checkbox` types.5455## Accessing Customizer Settings5657Use the standard WordPress `get_theme_mod()` function to retrieve Customizer settings.5859```php60$my_setting_value = get_theme_mod( 'my_setting', 'Default Value' );61```6263## Verification & Iteration (Ralph Loop)6465Use Playwright to verify your Customizer settings:66671. **Setting Persistence**: Automate navigating to the Customizer and setting a value to ensure it saves and renders correctly.682. **Visual Verification**: Use `npm run test:e2e:screenshot` to verify that the frontend reflects the changes made via Customizer.693. **Live Preview**: Verify that `postMessage` refreshes are working for settings with `refresh: false`.7071## Best Practices for Agents72731. **Declarative First**: Always prefer adding settings via `themeCustomizeSettings.json` before writing manual PHP Customizer code.742. **Naming Conventions**: Use descriptive IDs and ensure they are unique within the project.753. **Live Preview**: Set `refresh: false` for settings that can be updated via JavaScript (CSS changes, text swaps) to provide a better user experience.764. **Section Grouping**: Group related settings into sections to keep the Customizer organized.775. **Sanitization**: Standard WordPress Customizer sanitization is used. For complex validation, you may need to hook into `customize_register` in `inc/EZ_Customizer/Component.php`.786. **Filters**: Use the `wp_rig_customizer_settings` filter if you need to dynamically modify settings at runtime.