PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.2.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.2.0
2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 All 65 releases
subscription / includes / Admin / ProSettingsFields.php

ProSettingsFields.php in Subscriptions for WooCommerce with Stripe Recurring Payments 2.2.0, at includes/Admin/ProSettingsFields.php

656 lines 20.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Pro Settings Fields — the single source of the Pro settings UI.
4 *
5 * Defines every Pro settings field (the UI only — no options are registered or
6 * saved here; the real settings are registered and processed by the Pro plugin).
7 * The fields are always added to the settings page via the
8 * `subscrpt_settings_fields` filter. When Pro is **not** active they render
9 * locked (disabled, with a "Pro" badge); when Pro is active they become
10 * interactive and the Pro plugin saves their values.
11 *
12 * The lock state is derived from `subscrpt_pro_activated()` and injected onto
13 * every field as `pro_locked`, which SettingsHelper uses for the badge and the
14 * non-interactive styling.
15 *
16 * @package SpringDevs\Subscription\Admin
17 */
18
19 namespace SpringDevs\Subscription\Admin;
20
21 // Exit if accessed directly.
22 defined( 'ABSPATH' ) || exit;
23
24 /**
25 * Class ProSettingsFields
26 *
27 * @package SpringDevs\Subscription\Admin
28 */
29 class ProSettingsFields {
30
31 /**
32 * Initialize the class.
33 */
34 public function __construct() {
35 add_filter( 'subscrpt_settings_fields', [ $this, 'add_pro_preview_fields' ] );
36 }
37
38 /**
39 * Merge the Pro settings fields into the settings fields list.
40 *
41 * Fields are locked (disabled + Pro badge) only while Pro is inactive.
42 *
43 * @param array $settings_fields Existing settings fields.
44 * @return array
45 */
46 public function add_pro_preview_fields( $settings_fields ) {
47 $pro_fields = array_merge(
48 $this->pro_core_fields(),
49 $this->license_fields(),
50 $this->grace_period_fields(),
51 $this->payment_failure_fields(),
52 $this->api_fields(),
53 $this->health_queue_fields(),
54 $this->order_fields(),
55 $this->switch_fields(),
56 $this->role_management_fields(),
57 $this->live_qr_fields(),
58 $this->payment_gateway_fields()
59 );
60
61 // Lock the fields only when Pro is not active.
62 $locked = ! subscrpt_pro_activated();
63 foreach ( $pro_fields as &$field ) {
64 $field['field_data']['pro_locked'] = $locked;
65 if ( $locked ) {
66 $field['field_data']['disabled'] = true;
67 }
68 }
69 unset( $field );
70
71 return array_merge( $settings_fields, $pro_fields );
72 }
73
74 /**
75 * Module: Pro Core (Admin/Settings.php) — general settings additions.
76 *
77 * @return array
78 */
79 private function pro_core_fields() {
80 return [
81 [
82 'type' => 'select',
83 'group' => 'renewals',
84 'priority' => 7,
85 'field_data' => [
86 'id' => 'subscrpt_renewal_price',
87 'title' => __( 'Renewal Price', 'subscription' ),
88 'description' => __( 'Choose a price that will be used for subscription renewal.', 'subscription' ),
89 'options' => [
90 'subscribed' => __( 'Subscribed Price', 'subscription' ),
91 'updated' => __( 'New/Updated Price', 'subscription' ),
92 ],
93 'selected' => esc_attr( get_option( 'subscrpt_renewal_price', 'subscribed' ) ),
94 ],
95 ],
96 [
97 'type' => 'toggle',
98 'group' => 'renewals',
99 'priority' => 8,
100 'field_data' => [
101 'id' => 'subscrpt_early_renew',
102 'title' => __( 'Early Renewal', 'subscription' ),
103 'label' => __( 'Accept Early Renewal Payments', 'subscription' ),
104 'description' => __( 'With early renewals enabled, customers can renew their subscriptions before the next payment date.', 'subscription' ),
105 'value' => '1',
106 'checked' => '1' === get_option( 'subscrpt_early_renew', '1' ),
107 ],
108 ],
109 ];
110 }
111
112 /**
113 * Module: License integrations (Integrations/LicenseManagerWoo.php).
114 *
115 * @return array
116 */
117 private function license_fields() {
118 return [
119 [
120 'type' => 'heading',
121 'group' => 'license_settings',
122 'priority' => 4,
123 'field_data' => [
124 'title' => __( 'License Settings', 'subscription' ),
125 ],
126 ],
127 [
128 'type' => 'toggle',
129 'group' => 'license_settings',
130 'priority' => 1,
131 'field_data' => [
132 'id' => 'subscrpt_regenerate_license_on_renewal',
133 'title' => __( 'Regenerate License on Renewal', 'subscription' ),
134 'description' => __( 'Enable this option if you want to invalidate the old key and issue a fresh license key whenever a subscription renews.', 'subscription' ),
135 'value' => '1',
136 'checked' => '1' === get_option( 'subscrpt_regenerate_license_on_renewal', '0' ),
137 ],
138 ],
139 [
140 'type' => 'toggle',
141 'group' => 'license_settings',
142 'priority' => 2,
143 'field_data' => [
144 'id' => 'subscrpt_deactivate_old_license_on_renewal',
145 'title' => __( 'Deactivate Previous License', 'subscription' ),
146 'description' => __( 'When a fresh license key is issued on renewal, deactivate the previous key. Turn off to let the previous key keep working until it expires.', 'subscription' ),
147 'value' => '1',
148 'checked' => '1' === get_option( 'subscrpt_deactivate_old_license_on_renewal', '1' ),
149 ],
150 ],
151 ];
152 }
153
154 /**
155 * Module: Grace Period (Admin/Settings.php).
156 *
157 * @return array
158 */
159 private function grace_period_fields() {
160 return [
161 [
162 'type' => 'heading',
163 'group' => 'grace_period',
164 'priority' => 5,
165 'field_data' => [
166 'title' => __( 'Grace Period Settings', 'subscription' ),
167 ],
168 ],
169 [
170 'type' => 'input',
171 'group' => 'grace_period',
172 'priority' => 1,
173 'field_data' => [
174 'id' => 'subscrpt_default_payment_grace_period',
175 'title' => __( 'Grace Period (Days)', 'subscription' ),
176 'description' => __( 'Days to maintain access after subscriptions expires. (0 = No grace period. Max 30 days)', 'subscription' ),
177 'value' => esc_attr( get_option( 'subscrpt_default_payment_grace_period', '7' ) ),
178 'type' => 'number',
179 'attributes' => [
180 'min' => 0,
181 'max' => 30,
182 ],
183 ],
184 ],
185 [
186 'type' => 'toggle',
187 'group' => 'grace_period',
188 'priority' => 2,
189 'field_data' => [
190 'id' => 'subscrpt_enable_grace_period_notifications',
191 'title' => __( 'Grace Period Notifications', 'subscription' ),
192 'label' => __( 'Send notifications during grace period', 'subscription' ),
193 'description' => __( 'Customers will receive warnings before their access is suspended.', 'subscription' ),
194 'value' => '1',
195 'checked' => '1' === get_option( 'subscrpt_enable_grace_period_notifications', '1' ),
196 ],
197 ],
198 [
199 'type' => 'input',
200 'group' => 'grace_period',
201 'priority' => 3,
202 'field_data' => [
203 'id' => 'subscrpt_grace_period_warning_days',
204 'title' => __( 'Grace Period Warning (Days Before)', 'subscription' ),
205 'description' => __( 'Send warning emails this many days before grace period expires. (1-7 days)', 'subscription' ),
206 'value' => esc_attr( get_option( 'subscrpt_grace_period_warning_days', '2' ) ),
207 'type' => 'number',
208 'attributes' => [
209 'min' => 1,
210 'max' => 7,
211 ],
212 ],
213 ],
214 ];
215 }
216
217 /**
218 * Module: Payment Failure Handling (Admin/Settings.php).
219 *
220 * @return array
221 */
222 private function payment_failure_fields() {
223 return [
224 [
225 'type' => 'heading',
226 'group' => 'payment_failure',
227 'priority' => 6,
228 'field_data' => [
229 'title' => __( 'Payment Failure Handling', 'subscription' ),
230 ],
231 ],
232 [
233 'type' => 'input',
234 'group' => 'payment_failure',
235 'priority' => 1,
236 'field_data' => [
237 'id' => 'subscrpt_default_max_payment_retries',
238 'title' => __( 'Default Max Payment Retries', 'subscription' ),
239 'description' => __( 'Default number of automatic retry attempts for failed payments. (0 = No retries. Max 10 retries)', 'subscription' ),
240 'value' => esc_attr( get_option( 'subscrpt_default_max_payment_retries', '3' ) ),
241 'type' => 'number',
242 'attributes' => [
243 'min' => 0,
244 'max' => 10,
245 ],
246 ],
247 ],
248 [
249 'type' => 'toggle',
250 'group' => 'payment_failure',
251 'priority' => 2,
252 'field_data' => [
253 'id' => 'subscrpt_enable_payment_failure_emails',
254 'title' => __( 'Enable Payment Failure Emails', 'subscription' ),
255 'label' => __( 'Send email notifications when payments fail', 'subscription' ),
256 'description' => __( 'Customers will receive emails about failed payments and retry attempts.', 'subscription' ),
257 'value' => '1',
258 'checked' => '1' === get_option( 'subscrpt_enable_payment_failure_emails', '1' ),
259 ],
260 ],
261 [
262 'type' => 'input',
263 'group' => 'payment_failure',
264 'priority' => 3,
265 'field_data' => [
266 'id' => 'subscrpt_payment_failure_email_delay',
267 'title' => __( 'Payment Failure Email Delay (Hours)', 'subscription' ),
268 'description' => __( 'Delay before sending payment failure emails to avoid spam during temporary issues. (0-168 hours)', 'subscription' ),
269 'value' => esc_attr( get_option( 'subscrpt_payment_failure_email_delay', '24' ) ),
270 'type' => 'number',
271 'attributes' => [
272 'min' => 0,
273 'max' => 168,
274 ],
275 ],
276 ],
277 ];
278 }
279
280 /**
281 * Module: API Settings (Admin/Settings.php).
282 *
283 * @return array
284 */
285 private function api_fields() {
286 return [
287 [
288 'type' => 'heading',
289 'group' => 'api_settings',
290 'priority' => 99,
291 'field_data' => [
292 'title' => __( 'API Settings', 'subscription' ),
293 ],
294 ],
295 [
296 'type' => 'toggle',
297 'group' => 'api_settings',
298 'priority' => 1,
299 'field_data' => [
300 'id' => 'wpsubscription_api_enabled',
301 'title' => __( 'Enable API', 'subscription' ),
302 'description' => __( 'Enable REST API endpoints for subscription actions', 'subscription' ),
303 'value' => 'on',
304 'checked' => 'on' === get_option( 'wpsubscription_api_enabled', 'on' ),
305 ],
306 ],
307 [
308 'type' => 'join',
309 'group' => 'api_settings',
310 'priority' => 2,
311 'field_data' => [
312 'title' => __( 'API Key', 'subscription' ),
313 'description' => __( 'API key for external integrations. Keep this secure.', 'subscription' ),
314 'elements' => [
315 SettingsHelper::inp_element(
316 [
317 'id' => 'wpsubscription_api_key',
318 'value' => esc_attr( get_option( 'wpsubscription_api_key', '' ) ),
319 'type' => 'text',
320 'style' => 'min-width:366px;',
321 'attributes' => [
322 'readonly' => true,
323 ],
324 ],
325 true
326 ),
327 '<span class="wpsubs-tooltip" data-tip="' . esc_attr__( 'Regenerate API Key', 'subscription' ) . '">'
328 . '<button type="button" class="wpsubs-btn wpsubs-btn--outline wpsubs-btn--icon" id="regenerate_api_key" aria-label="' . esc_attr__( 'Regenerate API Key', 'subscription' ) . '">'
329 . '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>'
330 . '</button>'
331 . '</span>',
332 ],
333 ],
334 ],
335 [
336 'type' => 'input',
337 'group' => 'api_settings',
338 'priority' => 3,
339 'field_data' => [
340 'id' => 'subscrpt_api_endpoint_url',
341 'title' => __( 'REST API Endpoint URL', 'subscription' ),
342 'description' => __( 'Copy and use this endpoint for all API actions.', 'subscription' ),
343 'value' => esc_url( home_url( '/wp-json/wpsubscription/v1/action' ) ),
344 'type' => 'text',
345 'attributes' => [
346 'readonly' => true,
347 ],
348 ],
349 ],
350 ];
351 }
352
353 /**
354 * Module: Subscription Health (Admin/Settings.php).
355 *
356 * @return array
357 */
358 private function health_queue_fields() {
359 return [
360 [
361 'type' => 'heading',
362 'group' => 'health_queue',
363 'priority' => 9,
364 'field_data' => [
365 'title' => __( 'Subscription Health', 'subscription' ),
366 ],
367 ],
368 [
369 'type' => 'select',
370 'group' => 'health_queue',
371 'priority' => 2,
372 'field_data' => [
373 'id' => 'subscrpt_health_queue_email_frequency',
374 'title' => __( 'Health Queue Email Frequency', 'subscription' ),
375 'description' => __( 'How often to send the admin health queue reminder email. The email is only sent when subscriptions need attention.', 'subscription' ),
376 'options' => [
377 'daily' => __( 'Daily', 'subscription' ),
378 'subscrpt_weekly' => __( 'Weekly', 'subscription' ),
379 'subscrpt_monthly' => __( 'Monthly', 'subscription' ),
380 'never' => __( 'Never', 'subscription' ),
381 ],
382 'selected' => esc_attr( get_option( 'subscrpt_health_queue_email_frequency', 'subscrpt_weekly' ) ),
383 ],
384 ],
385 ];
386 }
387
388 /**
389 * Module: Order (Illuminate/Order.php) — auto complete orders.
390 *
391 * @return array
392 */
393 private function order_fields() {
394 return [
395 [
396 'type' => 'toggle',
397 'group' => 'payment_gateways',
398 'priority' => 1,
399 'field_data' => [
400 'id' => 'wp_subscription_auto_complete_order',
401 'title' => __( 'Auto Complete Orders', 'subscription' ),
402 'description' => __( 'Automatically change status of processing orders to completed.', 'subscription' ),
403 'value' => '1',
404 'checked' => '1' === get_option( 'wp_subscription_auto_complete_order', '1' ),
405 ],
406 ],
407 [
408 'type' => 'toggle',
409 'group' => 'payment_gateways',
410 'priority' => 2,
411 'field_data' => [
412 'id' => 'subscrpt_require_payment_on_trial',
413 'title' => __( 'Require Payment for Free Trials', 'subscription' ),
414 'label' => __( 'Collect payment details at checkout for trial subscriptions', 'subscription' ),
415 'description' => __( 'Collect payment details up front on free trials so renewals charge automatically.', 'subscription' ),
416 'value' => '1',
417 'checked' => '1' === get_option( 'subscrpt_require_payment_on_trial', '1' ),
418 ],
419 ],
420 ];
421 }
422
423 /**
424 * Module: Switch Subscription (Illuminate/SubscriptionSwitch.php).
425 *
426 * @return array
427 */
428 private function switch_fields() {
429 return [
430 [
431 'type' => 'heading',
432 'group' => 'switching',
433 'priority' => 3,
434 'field_data' => [
435 'title' => __( 'Switching & Upgrades', 'subscription' ),
436 ],
437 ],
438 [
439 'type' => 'toggle',
440 'group' => 'switching',
441 'priority' => 9,
442 'field_data' => [
443 'id' => 'subscrpt_switch_enabled',
444 'title' => __( 'Switch Subscription', 'subscription' ),
445 'label' => __( 'Allow users to upgrade/downgrade their subscriptions.', 'subscription' ),
446 'description' => '',
447 'value' => '1',
448 'checked' => '1' === get_option( 'subscrpt_switch_enabled', '0' ),
449 ],
450 ],
451 [
452 'type' => 'toggle',
453 'group' => 'switching',
454 'priority' => 10,
455 'field_data' => [
456 'id' => 'subscrpt_downgrade_allowed',
457 'title' => __( 'Downgrade Subscription', 'subscription' ),
458 'label' => __( 'Allow users to downgrade their subscriptions.', 'subscription' ),
459 'description' => '',
460 'value' => '1',
461 'checked' => '1' === get_option( 'subscrpt_downgrade_allowed', '1' ),
462 ],
463 ],
464 [
465 'type' => 'join',
466 'group' => 'switching',
467 'priority' => 11,
468 'field_data' => [
469 'title' => __( 'Switch Fee', 'subscription' ),
470 'description' => __( 'Optional fee charged when a customer switches plans. Use a flat amount or a percentage of the new plan price. (0 = no fee)', 'subscription' ),
471 'elements' => [
472 SettingsHelper::inp_element(
473 [
474 'id' => 'subscrpt_switch_fee_amount',
475 'value' => esc_attr( get_option( 'subscrpt_switch_fee_amount', '0' ) ),
476 'type' => 'number',
477 'style' => 'min-width:170px;width:170px;',
478 'attributes' => [
479 'min' => 0,
480 'step' => '0.01',
481 ],
482 ],
483 true
484 ),
485 SettingsHelper::select_element(
486 [
487 'id' => 'subscrpt_switch_fee_type',
488 'class' => 'subscrpt-switch-fee-type',
489 'options' => [
490 'flat' => sprintf(
491 /* translators: %s: store currency symbol. */
492 __( 'Flat (%s)', 'subscription' ),
493 get_woocommerce_currency_symbol()
494 ),
495 'percent' => __( 'Percentage (%)', 'subscription' ),
496 ],
497 'selected' => esc_attr( get_option( 'subscrpt_switch_fee_type', 'flat' ) ),
498 ],
499 true
500 ),
501 ],
502 ],
503 ],
504 [
505 'type' => 'select',
506 'group' => 'switching',
507 'priority' => 12,
508 'field_data' => [
509 'id' => 'subscrpt_switch_fee_apply_to',
510 'title' => __( 'Apply Fee To', 'subscription' ),
511 'description' => __( 'Choose which switch directions the fee applies to.', 'subscription' ),
512 'options' => [
513 'both' => __( 'Both upgrade and downgrade', 'subscription' ),
514 'upgrade' => __( 'Upgrade only', 'subscription' ),
515 'downgrade' => __( 'Downgrade only', 'subscription' ),
516 ],
517 'selected' => esc_attr( get_option( 'subscrpt_switch_fee_apply_to', 'both' ) ),
518 ],
519 ],
520 ];
521 }
522
523 /**
524 * Module: Role Management (Illuminate/RoleManagement.php).
525 *
526 * @return array
527 */
528 private function role_management_fields() {
529 return [
530 [
531 'type' => 'heading',
532 'group' => 'role_based_settings',
533 'priority' => 7,
534 'field_data' => [
535 'title' => __( 'Role-Based Settings', 'subscription' ),
536 ],
537 ],
538 [
539 'type' => 'toggle',
540 'group' => 'role_based_settings',
541 'priority' => 1,
542 'field_data' => [
543 'id' => 'subscrpt_role_based_access',
544 'title' => __( 'Enable Role Based Access', 'subscription' ),
545 'description' => __( 'Show/Hide products based on user roles.', 'subscription' ),
546 'value' => '1',
547 'checked' => '1' === get_option( 'subscrpt_role_based_access', '1' ),
548 ],
549 ],
550 ];
551 }
552
553 /**
554 * Module: Live QR (Illuminate/LiveQR/LiveQR.php) — quick details QR.
555 *
556 * @return array
557 */
558 private function live_qr_fields() {
559 return [
560 [
561 'type' => 'heading',
562 'group' => 'live_qr_settings',
563 'priority' => 8,
564 'field_data' => [
565 'title' => __( 'Quick Details QR Settings', 'subscription' ),
566 ],
567 ],
568 [
569 'type' => 'toggle',
570 'group' => 'live_qr_settings',
571 'priority' => 1,
572 'field_data' => [
573 'id' => 'subscrpt_live_qr_active',
574 'title' => __( 'Enable Quick Details QR', 'subscription' ),
575 'label' => '',
576 'value' => '1',
577 'checked' => '1' === get_option( 'subscrpt_live_qr_active', '1' ),
578 ],
579 ],
580 [
581 'type' => 'toggle',
582 'group' => 'live_qr_settings',
583 'priority' => 2,
584 'field_data' => [
585 'id' => 'subscrpt_live_qr_show_product',
586 'title' => __( 'Product Details', 'subscription' ),
587 'label' => __( 'Show product details in the subscription quick view', 'subscription' ),
588 'value' => '1',
589 'checked' => '1' === get_option( 'subscrpt_live_qr_show_product', '1' ),
590 ],
591 ],
592 [
593 'type' => 'toggle',
594 'group' => 'live_qr_settings',
595 'priority' => 3,
596 'field_data' => [
597 'id' => 'subscrpt_live_qr_show_billing',
598 'title' => __( 'Billing Details', 'subscription' ),
599 'label' => __( 'Show billing details in the subscription quick view', 'subscription' ),
600 'value' => '1',
601 'checked' => '1' === get_option( 'subscrpt_live_qr_show_billing', '0' ),
602 ],
603 ],
604 [
605 'type' => 'toggle',
606 'group' => 'live_qr_settings',
607 'priority' => 4,
608 'field_data' => [
609 'id' => 'subscrpt_live_qr_show_timeline',
610 'title' => __( 'Timeline', 'subscription' ),
611 'label' => __( 'Show subscription timeline in the subscription quick view', 'subscription' ),
612 'value' => '1',
613 'checked' => '1' === get_option( 'subscrpt_live_qr_show_timeline', '0' ),
614 ],
615 ],
616 ];
617 }
618
619 /**
620 * Module: Payment Gateways (Illuminate/Gateways/PaymentGateways.php).
621 *
622 * @return array
623 */
624 private function payment_gateway_fields() {
625 $gateway_options = [];
626 if ( function_exists( 'WC' ) && WC()->payment_gateways ) {
627 foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway_id => $gateway ) {
628 $gateway_options[ $gateway_id ] = $gateway->get_title();
629 }
630 }
631
632 return [
633 [
634 'type' => 'heading',
635 'group' => 'payment_gateways',
636 'priority' => 1,
637 'field_data' => [
638 'title' => __( 'Payment Gateway Settings', 'subscription' ),
639 ],
640 ],
641 [
642 'type' => 'multi_select',
643 'group' => 'payment_gateways',
644 'priority' => 2,
645 'field_data' => [
646 'id' => 'hidden_payment_gateways',
647 'title' => __( 'Hide Payment Gateways', 'subscription' ),
648 'description' => __( 'Select payment gateways to hide for subscription products. (keep empty for not hiding any)', 'subscription' ),
649 'options' => $gateway_options,
650 'selected' => get_option( 'hidden_payment_gateways', [] ),
651 ],
652 ],
653 ];
654 }
655 }
656