PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.10.3
Subscriptions for WooCommerce with Stripe Recurring Payments v1.10.3
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 1.10.3, at includes/Admin/ProSettingsFields.php

523 lines 16.7 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', array( $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 array(
80 array(
81 'type' => 'select',
82 'group' => 'main',
83 'priority' => 7,
84 'field_data' => array(
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' => array(
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 array(
96 'type' => 'toggle',
97 'group' => 'main',
98 'priority' => 8,
99 'field_data' => array(
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 array(
118 array(
119 'type' => 'heading',
120 'group' => 'grace_period',
121 'priority' => 3,
122 'field_data' => array(
123 'title' => __( 'Grace Period Settings', 'subscription' ),
124 ),
125 ),
126 array(
127 'type' => 'input',
128 'group' => 'grace_period',
129 'priority' => 1,
130 'field_data' => array(
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' => array(
137 'min' => 0,
138 'max' => 30,
139 ),
140 ),
141 ),
142 array(
143 'type' => 'toggle',
144 'group' => 'grace_period',
145 'priority' => 2,
146 'field_data' => array(
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 array(
156 'type' => 'input',
157 'group' => 'grace_period',
158 'priority' => 3,
159 'field_data' => array(
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' => array(
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 array(
181 array(
182 'type' => 'heading',
183 'group' => 'payment_failure',
184 'priority' => 4,
185 'field_data' => array(
186 'title' => __( 'Payment Failure Handling', 'subscription' ),
187 ),
188 ),
189 array(
190 'type' => 'input',
191 'group' => 'payment_failure',
192 'priority' => 1,
193 'field_data' => array(
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' => array(
200 'min' => 0,
201 'max' => 10,
202 ),
203 ),
204 ),
205 array(
206 'type' => 'toggle',
207 'group' => 'payment_failure',
208 'priority' => 2,
209 'field_data' => array(
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 array(
219 'type' => 'input',
220 'group' => 'payment_failure',
221 'priority' => 3,
222 'field_data' => array(
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' => array(
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 array(
244 array(
245 'type' => 'heading',
246 'group' => 'api_settings',
247 'priority' => 99,
248 'field_data' => array(
249 'title' => __( 'API Settings', 'subscription' ),
250 ),
251 ),
252 array(
253 'type' => 'toggle',
254 'group' => 'api_settings',
255 'priority' => 1,
256 'field_data' => array(
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 array(
265 'type' => 'join',
266 'group' => 'api_settings',
267 'priority' => 2,
268 'field_data' => array(
269 'title' => __( 'API Key', 'subscription' ),
270 'description' => __( 'API key for external integrations. Keep this secure.', 'subscription' ),
271 'elements' => array(
272 SettingsHelper::inp_element(
273 array(
274 'id' => 'wpsubscription_api_key',
275 'value' => esc_attr( get_option( 'wpsubscription_api_key', '' ) ),
276 'type' => 'text',
277 'style' => 'min-width:366px;',
278 'attributes' => array(
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 array(
293 'type' => 'input',
294 'group' => 'api_settings',
295 'priority' => 3,
296 'field_data' => array(
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' => array(
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 array(
317 array(
318 'type' => 'heading',
319 'group' => 'health_queue',
320 'priority' => 8,
321 'field_data' => array(
322 'title' => __( 'Subscription Health', 'subscription' ),
323 ),
324 ),
325 array(
326 'type' => 'select',
327 'group' => 'health_queue',
328 'priority' => 2,
329 'field_data' => array(
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' => array(
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 array(
352 array(
353 'type' => 'toggle',
354 'group' => 'payment_gateways',
355 'priority' => 1,
356 'field_data' => array(
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 }
366
367 /**
368 * Module: Switch Subscription (Illuminate/SubscriptionSwitch.php).
369 *
370 * @return array
371 */
372 private function switch_fields() {
373 return array(
374 array(
375 'type' => 'toggle',
376 'group' => 'general',
377 'priority' => 9,
378 'field_data' => array(
379 'id' => 'subscrpt_switch_enabled',
380 'title' => __( 'Switch Subscription', 'subscription' ),
381 'label' => __( 'Allow users to upgrade/downgrade their subscriptions.', 'subscription' ),
382 'description' => __( 'Note: Downgrading subscription is not available at the moment.', 'subscription' ),
383 'value' => '1',
384 'checked' => '1' === get_option( 'subscrpt_switch_enabled', '0' ),
385 ),
386 ),
387 );
388 }
389
390 /**
391 * Module: Role Management (Illuminate/RoleManagement.php).
392 *
393 * @return array
394 */
395 private function role_management_fields() {
396 return array(
397 array(
398 'type' => 'heading',
399 'group' => 'role_based_settings',
400 'priority' => 6,
401 'field_data' => array(
402 'title' => __( 'Role-Based Settings', 'subscription' ),
403 ),
404 ),
405 array(
406 'type' => 'toggle',
407 'group' => 'role_based_settings',
408 'priority' => 1,
409 'field_data' => array(
410 'id' => 'subscrpt_role_based_access',
411 'title' => __( 'Enable Role Based Access', 'subscription' ),
412 'description' => __( 'Show/Hide products based on user roles.', 'subscription' ),
413 'value' => '1',
414 'checked' => '1' === get_option( 'subscrpt_role_based_access', '1' ),
415 ),
416 ),
417 );
418 }
419
420 /**
421 * Module: Live QR (Illuminate/LiveQR/LiveQR.php) — quick details QR.
422 *
423 * @return array
424 */
425 private function live_qr_fields() {
426 return array(
427 array(
428 'type' => 'heading',
429 'group' => 'live_qr_settings',
430 'priority' => 5,
431 'field_data' => array(
432 'title' => __( 'Quick Details QR Settings', 'subscription' ),
433 ),
434 ),
435 array(
436 'type' => 'toggle',
437 'group' => 'live_qr_settings',
438 'priority' => 1,
439 'field_data' => array(
440 'id' => 'subscrpt_live_qr_active',
441 'title' => __( 'Enable Quick Details QR', 'subscription' ),
442 'label' => '',
443 'value' => '1',
444 'checked' => '1' === get_option( 'subscrpt_live_qr_active', '1' ),
445 ),
446 ),
447 array(
448 'type' => 'toggle',
449 'group' => 'live_qr_settings',
450 'priority' => 2,
451 'field_data' => array(
452 'id' => 'subscrpt_live_qr_show_product',
453 'title' => __( 'Product Details', 'subscription' ),
454 'label' => __( 'Show product details in the subscription quick view', 'subscription' ),
455 'value' => '1',
456 'checked' => '1' === get_option( 'subscrpt_live_qr_show_product', '1' ),
457 ),
458 ),
459 array(
460 'type' => 'toggle',
461 'group' => 'live_qr_settings',
462 'priority' => 3,
463 'field_data' => array(
464 'id' => 'subscrpt_live_qr_show_billing',
465 'title' => __( 'Billing Details', 'subscription' ),
466 'label' => __( 'Show billing details in the subscription quick view', 'subscription' ),
467 'value' => '1',
468 'checked' => '1' === get_option( 'subscrpt_live_qr_show_billing', '0' ),
469 ),
470 ),
471 array(
472 'type' => 'toggle',
473 'group' => 'live_qr_settings',
474 'priority' => 4,
475 'field_data' => array(
476 'id' => 'subscrpt_live_qr_show_timeline',
477 'title' => __( 'Timeline', 'subscription' ),
478 'label' => __( 'Show subscription timeline in the subscription quick view', 'subscription' ),
479 'value' => '1',
480 'checked' => '1' === get_option( 'subscrpt_live_qr_show_timeline', '0' ),
481 ),
482 ),
483 );
484 }
485
486 /**
487 * Module: Payment Gateways (Illuminate/Gateways/PaymentGateways.php).
488 *
489 * @return array
490 */
491 private function payment_gateway_fields() {
492 $gateway_options = array();
493 if ( function_exists( 'WC' ) && WC()->payment_gateways ) {
494 foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway_id => $gateway ) {
495 $gateway_options[ $gateway_id ] = $gateway->get_title();
496 }
497 }
498
499 return array(
500 array(
501 'type' => 'heading',
502 'group' => 'payment_gateways',
503 'priority' => 0.1,
504 'field_data' => array(
505 'title' => __( 'Payment Gateway Settings', 'subscription' ),
506 ),
507 ),
508 array(
509 'type' => 'multi_select',
510 'group' => 'payment_gateways',
511 'priority' => 2,
512 'field_data' => array(
513 'id' => 'hidden_payment_gateways',
514 'title' => __( 'Hide Payment Gateways', 'subscription' ),
515 'description' => __( 'Select payment gateways to hide for subscription products. (keep empty for not hiding any)', 'subscription' ),
516 'options' => $gateway_options,
517 'selected' => get_option( 'hidden_payment_gateways', array() ),
518 ),
519 ),
520 );
521 }
522 }
523