Added
- AJAX Batch Coupon Generation: Replaced synchronous form POST with AJAX-based batch processing. Coupons are generated in batches of 10 with a real-time progress bar, eliminating timeout risks for large batches.
- WooCommerce Select2 Product Search: Replaced static
<select multiple>dropdown (limited to pre-loaded products) with WooCommerce's built-in AJAX product search (wc-product-search). Scales to unlimited catalog sizes with search-as-you-type. - Progress Bar UI: Added visual progress bar with coupon count during AJAX batch generation.
- CSS Custom Properties: Defined all colors as
:rootCSS custom properties for consistency and maintainability. - Accessibility: Added
aria-describedbyattributes to all form fields linking to their description text. - i18n-safe List Formatting: Product name lists in coupon descriptions now use
wp_sprintf( '%l', ... )for proper localized formatting (Oxford comma, translated conjunctions). - JavaScript Internationalization: All user-facing JS strings are now sourced from
wp_add_inline_script()data - no hardcoded English. - Named Constants: Extracted magic numbers to class constants for batch size, generation delays, prefix length, code length, and default expiry.
Changed
-
Plugin Rename: Renamed plugin from "WC Free Gift Coupons Bulk Coupon Generator" to "Free Gift Coupons Bulk Coupon Generator" to remove WC prefix while maintaining clarity as a companion to the Free Gift Coupons for WooCommerce plugin.
- Renamed main class from
WooCommerceFreeGiftBulkCouponstoFGCBG_Plugin - Updated all plugin constants:
SCG_*->FGCBG_*(Free Gift Coupons Bulk Generator) - Updated all function names and hooks to use
fgcbg_prefix instead ofscg_ - Updated all coupon metadata keys from
_scg_*to_fgcbg_* - Updated helper functions and initialization callbacks
- Updated PHPCS and composer configuration
Migration Notes: External code depending on the old hooks, filters, constants, or function names will need updating. This is considered a major version change due to the breaking API changes.
- Renamed main class from
-
File Architecture: Split monolithic single-file plugin into modular architecture:
includes/class-fgcbg-plugin.php- Main plugin class (singleton, hooks, AJAX handler)includes/class-fgcbg-coupon-generator.php- Coupon generation logicincludes/class-fgcbg-admin-page.php- Admin page renderingfree-gift-bulk-coupon-generator.php- Slim entry point (~60 lines)
-
ESNext JavaScript: Modernized admin.js to use
const/let, arrow functions, template literals, optional chaining (?.), and nullish coalescing (??). WordPress 6.8+ targets modern browsers. -
Admin Notices: Replaced anonymous
add_action('admin_notices', ...)closures with a named notice-queue pattern (unhookable by other plugins). AJAX handler now returns JSON responses directly. -
CSS Standards: Rewrote
admin.csswith tab indentation, alphabetical property ordering, proper section comment headers, and@package/@sincein file header per WordPress Coding Standards. -
PHPDoc: Added
@sincetags to all class properties and constants. Complete@param,@return,@sinceon all methods.
Fixed
- Text Domain Slug: Updated the plugin header, translation calls, PHPCS configuration, and POT file to use
free-gift-bulk-coupon-generator, matching the main plugin file slug expected by WordPress Plugin Check. - CSRF in
admin_init(): Restored nonce verification before processing form data to prevent CSRF. The v1.5.1 removal was incorrect - without it,$_POSTis accessed before any security check. (Now replaced entirely by AJAXcheck_ajax_referer().) - XSS in Success Notice: Wrapped
sprintf()output inesc_html()(using__()instead ofesc_html__()for the format string) to properly escape the final rendered output. - Coupon Generation Parse Error: Restored a missing
catchblock and success return path increate_single_coupon()to fixCannot use try without catch or finally. - Error Logging:
log_coupon_error()now logs$exception->getMessage()instead of the useless$exception->getCode(). - Inline Styles: Removed all inline
styleattributes from PHP and JavaScript; moved to dedicated CSS classes. - wordpress-stubs Version: Updated
composer.jsonfrom^6.8to^6.9to match "Tested up to" version.
Removed
- Static Product Dropdown Cache: Removed
get_products_for_dropdown(),invalidate_product_cache(), and product cache invalidation hooks. Replaced by WooCommerce AJAX search. - Synchronous Form POST: Removed
admin_init()andhandle_coupon_generation()methods. All coupon generation is now via AJAX. - Product Cache Transient Cleanup: Removed
fgcbg_products_dropdowntransient cleanup fromuninstall.php(transient no longer exists).
Installation
- Download the zip file
- Upload to your WordPress site through the Plugins > Add New > Upload menu
- Activate the plugin