PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.0.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.0.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 1.4.1 1.4.2 1.5.0 1.5.1 All 61 releases
subscription / includes / Admin / ProSettingsFields.php

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

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