-
-
Notifications
You must be signed in to change notification settings - Fork 75
Add Settings API and more #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
6d79778
c101dc4
0f94b89
a1df46f
d0bc595
58d27e5
9998c00
a5b944d
ab41443
e2bc76d
a808f21
30f1ac2
af6276c
a8b1edb
28692a2
d905829
76e4874
f4ca4ec
93dd859
eb12793
a3b1bfd
d181e94
1d66ab8
e4537be
c65339c
a76cee6
e95460b
4655401
08f14d0
0ba2b71
01cbcb6
3a09c64
7dda86b
98ef974
b50502b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -113,6 +113,23 @@ public function render_add_new_membership_modal(): void { | |||||||||||||||||||||||||||||
| 'data-max-items' => 99, | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| 'billing_period' => [ | ||||||||||||||||||||||||||||||
| 'type' => 'select', | ||||||||||||||||||||||||||||||
| 'title' => __('Billing Period', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| 'desc' => __('Select the billing period for this membership. Must match a price variation in the selected product.', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| 'tooltip' => '', | ||||||||||||||||||||||||||||||
| 'value' => '1-month', | ||||||||||||||||||||||||||||||
| 'options' => [ | ||||||||||||||||||||||||||||||
| '1-day' => __('Daily', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| '1-week' => __('Weekly', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| '1-month' => __('Monthly', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| '3-month' => __('Quarterly (3 months)', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| '6-month' => __('Semi-annually (6 months)', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| '1-year' => __('Yearly', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| '2-year' => __('Every 2 years', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| '3-year' => __('Every 3 years', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| 'status' => [ | ||||||||||||||||||||||||||||||
| 'type' => 'select', | ||||||||||||||||||||||||||||||
| 'title' => __('Status', 'ultimate-multisite'), | ||||||||||||||||||||||||||||||
|
|
@@ -213,13 +230,28 @@ public function handle_add_new_membership_modal(): void { | |||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Parse the billing period into duration and duration_unit. | ||||||||||||||||||||||||||||||
| $billing_period = wu_request('billing_period', '1-month'); | ||||||||||||||||||||||||||||||
| $billing_parts = explode('-', $billing_period, 2); | ||||||||||||||||||||||||||||||
| $duration = isset($billing_parts[0]) ? absint($billing_parts[0]) : 1; | ||||||||||||||||||||||||||||||
| $duration_unit = isset($billing_parts[1]) ? $billing_parts[1] : 'month'; | ||||||||||||||||||||||||||||||
|
Comment on lines
+233
to
+237
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate and clamp the billing period inputs before building the cart. ✅ Suggested hardening- $billing_period = wu_request('billing_period', '1-month');
- $billing_parts = explode('-', $billing_period, 2);
- $duration = isset($billing_parts[0]) ? absint($billing_parts[0]) : 1;
- $duration_unit = isset($billing_parts[1]) ? $billing_parts[1] : 'month';
+ $billing_period = wu_request('billing_period', '1-month');
+ $billing_parts = explode('-', $billing_period, 2);
+ $duration = max(1, absint($billing_parts[0] ?? 1));
+ $duration_unit = $billing_parts[1] ?? 'month';
+ $allowed_units = ['day', 'week', 'month', 'year'];
+ if ( ! in_array($duration_unit, $allowed_units, true)) {
+ $duration_unit = 'month';
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| $cart = new \WP_Ultimo\Checkout\Cart( | ||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||
| 'products' => $products, | ||||||||||||||||||||||||||||||
| 'country' => $customer->get_country(), | ||||||||||||||||||||||||||||||
| 'products' => $products, | ||||||||||||||||||||||||||||||
| 'country' => $customer->get_country(), | ||||||||||||||||||||||||||||||
| 'duration' => $duration, | ||||||||||||||||||||||||||||||
| 'duration_unit' => $duration_unit, | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Check for cart errors (e.g., missing price variations). | ||||||||||||||||||||||||||||||
| $cart_errors = $cart->get_errors(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if ($cart_errors->has_errors()) { | ||||||||||||||||||||||||||||||
| wp_send_json_error($cart_errors); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| $data = $cart->to_membership_data(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| $data['customer_id'] = $customer->get_id(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 33826
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 14004
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 30256
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 1616
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 50394
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 36757
PWYW recurring products with
force_recurringmode won't appear in available billing periods.The method relies on
is_recurring()which checks therecurringflag and amount > 0, but doesn't account forpwyw_recurring_mode. A PWYW product configured withforce_recurringmay haverecurring=false, causingis_recurring()to return false and the product to be skipped entirely. This means its billing period information never reaches the discount code admin form, preventing admins from restricting codes to periods that only exist on PWYW products.🤖 Prompt for AI Agents