Skip to content

Commit 4a24d92

Browse files
authored
Minor Changes
1 parent 4394340 commit 4a24d92

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

CHANGELOG.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
# Changelog for WC Free Gift Coupons Bulk Coupon Generator
1+
# Changelog
22

3-
## 1.4.0 - August 2, 2025
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Fixed
11+
- Fixed WordPress coding standards violations in function formatting
12+
- Fixed anonymous function spacing and indentation issues
13+
- Added missing parameter documentation for validate_products function
14+
- Added return type documentation for generate_coupons function
15+
- Improved code alignment and formatting consistency
16+
17+
## [1.4.0] - 2025-01-15
418
### Breaking Changes
519
- **Text Domain Standardization**: Changed text domain from `WC-Free-Gift-Coupons-Bulk-Coupons-Generator` to `wc-free-gift-coupons-bulk-coupons-generator` to comply with WordPress standards that require only lowercase letters, numbers, and hyphens.
620

free-gift-bulk-coupon-generator.php

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
* Domain Path: /languages
1515
*
1616
* @package wc-free-gift-coupons-bulk-coupons-generator
17+
*
18+
* Note: This is the main plugin file and follows WordPress plugin naming conventions.
19+
* The filename free-gift-bulk-coupon-generator.php is intentionally different from
20+
* the class name to follow WordPress plugin standards.
1721
*/
1822

1923
// Prevent direct access.
@@ -172,12 +176,11 @@ function () {
172176
set_transient( $transient_key, true, 300 ); // 5 minutes
173177

174178
// Sanitize and validate input with proper unslashing.
175-
$product_ids = isset( $_POST['product_id'] ) ? array_map( 'absint', (array) wp_unslash( $_POST['product_id'] ) ) : array();
176-
$number_of_coupons = isset( $_POST['number_of_coupons'] ) ? absint( wp_unslash( $_POST['number_of_coupons'] ) ) : 0;
177-
$coupon_prefix = isset( $_POST['coupon_prefix'] ) ? sanitize_text_field( wp_unslash( $_POST['coupon_prefix'] ) ) : '';
178-
$discount_type = isset( $_POST['discount_type'] ) ? sanitize_text_field( wp_unslash( $_POST['discount_type'] ) ) : 'free_gift';
179-
180-
// Validate discount type against allowed values.
179+
// Get form data and sanitize inputs.
180+
$product_ids = isset( $_POST['product_id'] ) ? array_map( 'absint', (array) wp_unslash( $_POST['product_id'] ) ) : array();
181+
$number_of_coupons = isset( $_POST['number_of_coupons'] ) ? absint( wp_unslash( $_POST['number_of_coupons'] ) ) : 0;
182+
$coupon_prefix = isset( $_POST['coupon_prefix'] ) ? sanitize_text_field( wp_unslash( $_POST['coupon_prefix'] ) ) : '';
183+
$discount_type = isset( $_POST['discount_type'] ) ? sanitize_text_field( wp_unslash( $_POST['discount_type'] ) ) : 'free_gift'; // Validate discount type against allowed values.
181184
$allowed_discount_types = array( 'free_gift', 'percent', 'fixed_cart', 'fixed_product' );
182185
if ( ! in_array( $discount_type, $allowed_discount_types, true ) ) {
183186
$discount_type = 'free_gift'; // Default to safe value.
@@ -194,32 +197,41 @@ function () {
194197

195198
// Validate inputs.
196199
if ( empty( $product_ids ) || empty( $number_of_coupons ) ) {
197-
add_action( 'admin_notices', function() {
198-
echo '<div class="notice notice-error is-dismissible"><p>' .
199-
esc_html__( 'Please select at least one product and specify the number of coupons to generate.', 'wc-free-gift-coupons-bulk-coupons-generator' ) .
200-
'</p></div>';
201-
} );
200+
add_action(
201+
'admin_notices',
202+
function () {
203+
echo '<div class="notice notice-error is-dismissible"><p>' .
204+
esc_html__( 'Please select at least one product and specify the number of coupons to generate.', 'wc-free-gift-coupons-bulk-coupons-generator' ) .
205+
'</p></div>';
206+
}
207+
);
202208
return;
203209
}
204210

205211
// Additional validation for product IDs.
206212
foreach ( $product_ids as $product_id ) {
207213
if ( $product_id <= 0 || $product_id > PHP_INT_MAX ) {
208-
add_action( 'admin_notices', function() {
209-
echo '<div class="notice notice-error is-dismissible"><p>' .
210-
esc_html__( 'Invalid product selection. Please try again.', 'wc-free-gift-coupons-bulk-coupons-generator' ) .
211-
'</p></div>';
212-
} );
214+
add_action(
215+
'admin_notices',
216+
function () {
217+
echo '<div class="notice notice-error is-dismissible"><p>' .
218+
esc_html__( 'Invalid product selection. Please try again.', 'wc-free-gift-coupons-bulk-coupons-generator' ) .
219+
'</p></div>';
220+
}
221+
);
213222
return;
214223
}
215224
}
216225

217226
if ( $number_of_coupons <= 0 || $number_of_coupons > 100 ) {
218-
add_action( 'admin_notices', function() {
219-
echo '<div class="notice notice-error is-dismissible"><p>' .
220-
esc_html__( 'Maximum number of coupons that can be generated at once is 100.', 'wc-free-gift-coupons-bulk-coupons-generator' ) .
221-
'</p></div>';
222-
} );
227+
add_action(
228+
'admin_notices',
229+
function () {
230+
echo '<div class="notice notice-error is-dismissible"><p>' .
231+
esc_html__( 'Maximum number of coupons that can be generated at once is 100.', 'wc-free-gift-coupons-bulk-coupons-generator' ) .
232+
'</p></div>';
233+
}
234+
);
223235
return;
224236
}
225237

@@ -261,6 +273,7 @@ function () {
261273
* @param int $number_of_coupons Number of coupons to generate.
262274
* @param string $prefix Coupon prefix.
263275
* @param string $discount_type Type of discount.
276+
* @return int Number of coupons generated.
264277
*/
265278
private function generate_coupons( $product_ids, $number_of_coupons, $prefix = '', $discount_type = 'free_gift' ) {
266279
$valid_products = $this->validate_products( $product_ids );
@@ -284,6 +297,9 @@ private function generate_coupons( $product_ids, $number_of_coupons, $prefix = '
284297

285298
/**
286299
* Validate products for coupon generation
300+
*
301+
* @param array|int $product_ids Product IDs to validate.
302+
* @return array Array of valid product objects.
287303
*/
288304
private function validate_products( $product_ids ) {
289305
// Ensure product_ids is an array.

0 commit comments

Comments
 (0)