Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/jcs-company-work/tm-product-colours/archive/refs/heads/main.zipNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
TM Product Colours Plugin
TM Product Colours is a WordPress plugin designed to extend WAPF by allowing store owners to manage custom product colour options, layers, and swatches. It provides a user-friendly admin interface for adding, editing, and cleaning up colour data for products, including powerful bulk actions and orphaned layer removal.
Features
- Add, edit, and delete colour options for WAPF products
- Organize colours into layers for advanced product customization
- Bulk select products for colour management using checkboxes
- Remove orphaned colour layers and slugs to keep product data clean
- "Select All" and "Orphan All" controls for efficient bulk actions
- AJAX-powered admin actions for fast, seamless updates
- Modular JavaScript and PHP for maintainable code
How It Works
- Admin UI: The plugin adds a dedicated admin page for managing product colours. You can select products individually or in bulk, assign colours and layers, and perform cleanup actions.
- Bulk Actions: Use "Select All" or "Orphan All" checkboxes to quickly select multiple products for batch operations.
- Orphan Removal & Sync: The plugin guarantees that fieldgroup and layer images are always perfectly linked by slug. When a colour is added or updated, any previous entry with the same slug or label is removed and replaced, preventing orphaned images and mismatches. Only the latest colour and image mapping for that slug/layer remain, ensuring perfect sync between fieldgroup and layer images.
- AJAX Integration: All admin actions are performed via AJAX, providing instant feedback and avoiding page reloads.
- Backend Logic: PHP classes handle all data mutation, validation, and cleanup, including batch operations for multiple products.
Code Structure
js/checkbox-utils.js: Handles checkbox selection logic, syncing "Select All" and "Orphan All" controls.js/form-orphan-remove.js: Manages the orphan removal form and AJAX requests for cleaning up orphaned layers.js/ui-state.js: Updates UI state and selected product display.src/TMCOL_AJAX.php: Handles AJAX requests and batch operations in PHP.src/TMCOL_ColourUpdate.php: Contains backend logic for updating and cleaning product colour data. Ensures fieldgroup and layer images are always in sync, overwriting previous entries for the same slug and preventing orphans.
Usage
- Install the plugin in your WordPress site.
- Go to the TM Product Colours admin page to manage colour options and layers for your products.
- Select products using checkboxes or bulk controls for colour management.
- Add, edit, or remove colours and layers as needed. When you add or update a colour, the plugin will automatically overwrite any previous entry for the same slug/layer, keeping fieldgroup and layer images perfectly in sync.
- Use the orphan removal feature to clean up invalid colour data. The plugin ensures no orphaned slugs or images remain after updates.
- Review admin notices for feedback on actions performed.
Development Notes
- All JavaScript modules use ES6 imports/exports for maintainability.
- AJAX requests use FormData and expect JSON responses from the backend.
- Checkbox state is managed by utility functions for consistency.
- Backend PHP is modular and uses static methods for batch operations.
Future Reference
- Extend the plugin by adding new features to the modular JS and PHP classes.
- Keep all checkbox and selection logic in
checkbox-utils.jsfor consistency. - Use AJAX for all admin actions to maintain a fast, modern UI.
- Document any new admin actions or backend logic in this README.