| @@ -1,170 +1,141 @@ | ||
| 1 | -<div class="woocommerce"> | |
| 2 | - <h1 class="wp-heading-inline"><?php esc_html_e( 'Subscription Settings', 'wp_subscription' ); ?></h1> | |
| 3 | - <hr class="wp-header-end"> | |
| 4 | - <form method="post" action="options.php" class="woocommerce-settings"> | |
| 5 | - <div class="woocommerce-card"> | |
| 6 | - <?php settings_fields( 'wp_subscription_settings' ); ?> | |
| 7 | - <?php do_settings_sections( 'wp_subscription_settings' ); ?> | |
| 8 | - <table class="form-table"> | |
| 9 | - <tbody> | |
| 10 | - <tr> | |
| 11 | - <th scope="row"> | |
| 12 | - <label for="wp_subscription_renewal_process"> | |
| 13 | - <?php esc_html_e( 'Renewal Process', 'wp_subscription' ); ?> | |
| 14 | - </label> | |
| 15 | - </th> | |
| 16 | - <td> | |
| 17 | - <select name="wp_subscription_renewal_process" id="wp_subscription_renewal_process" class="wc-enhanced-select"> | |
| 18 | - <option value="auto" <?php selected( get_option( 'wp_subscription_renewal_process', 'auto' ), 'auto' ); ?>><?php esc_html_e( 'Automatic', 'wp_subscription' ); ?></option> | |
| 19 | - <option value="manual" <?php selected( get_option( 'wp_subscription_renewal_process', 'auto' ), 'manual' ); ?>><?php esc_html_e( 'Manual', 'wp_subscription' ); ?></option> | |
| 20 | - </select> | |
| 21 | - <p class="description"><?php esc_html_e( 'How renewal process will be done after Subscription Expired.', 'wp_subscription' ); ?></p> | |
| 22 | - </td> | |
| 23 | - </tr> | |
| 24 | - <tr> | |
| 25 | - <th scope="row"> | |
| 26 | - <label for="wp_subscription_manual_renew_cart_notice"> | |
| 27 | - <?php esc_html_e( 'Renewal Cart Notice', 'wp_subscription' ); ?> | |
| 28 | - </label> | |
| 29 | - </th> | |
| 30 | - <td> | |
| 31 | - <input id="wp_subscription_manual_renew_cart_notice" name="wp_subscription_manual_renew_cart_notice" class="large-text" value="<?php echo esc_attr( get_option( 'wp_subscription_manual_renew_cart_notice' ) ); ?>" type="text"/> | |
| 32 | - <p class="description"><?php esc_html_e( 'Display Notice when Renewal Subscription product add to cart. Only available for Manual Renewal Process.', 'wp_subscription' ); ?></p> | |
| 33 | - </td> | |
| 34 | - </tr> | |
| 35 | - <tr> | |
| 36 | - <th scope="row"> | |
| 37 | - <label for="wp_subscription_active_role"> | |
| 38 | - <?php esc_html_e( 'Subscriber Default Role', 'wp_subscription' ); ?> | |
| 39 | - </label> | |
| 40 | - </th> | |
| 41 | - <td> | |
| 42 | - <select name="wp_subscription_active_role" id="wp_subscription_active_role" class="wc-enhanced-select"> | |
| 43 | - <?php wp_dropdown_roles( get_option( 'wp_subscription_active_role', 'subscriber' ) ); ?> | |
| 44 | - </select> | |
| 45 | - <p class="description"><?php esc_html_e( 'When a subscription is activated, either manually or after a successful purchase, new users will be assigned this role.', 'wp_subscription' ); ?></p> | |
| 46 | - </td> | |
| 47 | - </tr> | |
| 48 | - <tr> | |
| 49 | - <th scope="row"> | |
| 50 | - <label for="wp_subscription_unactive_role"> | |
| 51 | - <?php esc_html_e( 'Subscriber Inactive Role', 'wp_subscription' ); ?> | |
| 52 | - </label> | |
| 53 | - </th> | |
| 54 | - <td> | |
| 55 | - <select name="wp_subscription_unactive_role" id="wp_subscription_unactive_role" class="wc-enhanced-select"> | |
| 56 | - <?php wp_dropdown_roles( get_option( 'wp_subscription_unactive_role', 'customer' ) ); ?> | |
| 57 | - </select> | |
| 58 | - <p class="description"><?php esc_html_e( "If a subscriber's subscription is manually cancelled or expires, they will be assigned this role.", 'wp_subscription' ); ?></p> | |
| 59 | - </td> | |
| 60 | - </tr> | |
| 61 | - <tr valign="top"> | |
| 62 | - <th scope="row" class="titledesc"><?php esc_html_e( 'Stripe Auto Renewal', 'wp_subscription' ); ?></th> | |
| 63 | - <td class="forminp forminp-checkbox"> | |
| 64 | - <fieldset> | |
| 65 | - <legend class="screen-reader-text"><span><?php esc_html_e( 'Accept Stripe Auto Renewals', 'wp_subscription' ); ?></span></legend> | |
| 66 | - <label for="wp_subscription_stripe_auto_renew"> | |
| 67 | - <input name="wp_subscription_stripe_auto_renew" id="wp_subscription_stripe_auto_renew" type="checkbox" value="1" <?php checked( get_option( 'wp_subscription_stripe_auto_renew', '1' ), '1' ); ?> /> | |
| 68 | - <?php esc_html_e( 'Accept Stripe Auto Renewals', 'wp_subscription' ); ?> | |
| 69 | - </label> | |
| 70 | - <p class="description"> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Subscription settings admin view. | |
| 4 | + * | |
| 5 | + * One form, every panel rendered, one panel visible. The form posts to | |
| 6 | + * `options.php`, which saves whatever it is given — so a panel that is not | |
| 7 | + * rendered is a panel whose settings do not save. Hiding is therefore CSS, not | |
| 8 | + * a conditional, and every one of the fields below submits on every save | |
| 9 | + * whichever section happens to be open. | |
| 10 | + * | |
| 11 | + * One level of navigation: the rail picks a section and the section's panel | |
| 12 | + * stacks whatever groups belong to it. A section holding a single group drops | |
| 13 | + * that group's heading, because the rail item beside it already says the same | |
| 14 | + * word. | |
| 15 | + * | |
| 16 | + * @package SpringDevs\Subscription\Admin | |
| 17 | + * | |
| 18 | + * @var array $settings_fields Grouped and sorted settings fields. | |
| 19 | + * @var string $active_cat Section currently open. | |
| 20 | + * @var array $category_groups Section key => ordered group keys (empty ones dropped). | |
| 21 | + */ | |
| 22 | + | |
| 23 | +// Exit if accessed directly. | |
| 24 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 25 | + exit; | |
| 26 | +} | |
| 27 | + | |
| 28 | +use SpringDevs\Subscription\Admin\SettingsHelper; | |
| 29 | + | |
| 30 | +wp_enqueue_style( 'wp-subscription-admin-settings', SUBSCRPT_ASSETS . '/css/admin-settings.css', [], SUBSCRPT_VERSION ); | |
| 31 | +wp_enqueue_script( 'wp-subscription-admin-settings', SUBSCRPT_ASSETS . '/js/admin-settings.js', [ 'jquery' ], SUBSCRPT_VERSION, true ); | |
| 32 | + | |
| 33 | +$subscrpt_settings_base = admin_url( 'admin.php?page=wp-subscription-settings' ); | |
| 34 | +?> | |
| 35 | +<div class="wp-subscription-admin-content list-page"> | |
| 36 | + | |
| 37 | + <form method="post" action="options.php" class="subscrpt-settings" data-subscrpt-settings> | |
| 38 | + <?php settings_fields( 'wp_subscription_settings' ); ?> | |
| 39 | + <?php do_settings_sections( 'wp_subscription_settings' ); ?> | |
| 40 | + | |
| 41 | + <?php | |
| 42 | + // Shared page header (title + description + dashed rule) with the Save | |
| 43 | + // button pinned to the right of the title row. | |
| 44 | + wpsubs_render_page_header( | |
| 45 | + array( | |
| 46 | + 'title' => __( 'Settings', 'subscription' ), | |
| 47 | + 'description' => __( 'Configure how subscriptions renew, charge and behave for your customers.', 'subscription' ), | |
| 48 | + 'actions' => sprintf( | |
| 49 | + '<button type="submit" class="wpsubs-btn wpsubs-btn--primary subscrpt-settings__save">%s</button>', | |
| 50 | + esc_html__( 'Save changes', 'subscription' ) | |
| 51 | + ), | |
| 52 | + ) | |
| 53 | + ); | |
| 54 | + ?> | |
| 55 | + | |
| 56 | + <div class="subscrpt-settings__layout"> | |
| 57 | + | |
| 58 | + <aside class="subscrpt-settings__sidebar"> | |
| 59 | + <nav class="wpsubs-vnav" aria-label="<?php esc_attr_e( 'Settings sections', 'subscription' ); ?>"> | |
| 60 | + <?php $subscrpt_all_active = 'all' === $active_cat; ?> | |
| 61 | + <a | |
| 62 | + class="wpsubs-vnav__item<?php echo $subscrpt_all_active ? ' is-active' : ''; ?>" | |
| 63 | + href="<?php echo esc_url( add_query_arg( 'cat', 'all', $subscrpt_settings_base ) ); ?>" | |
| 64 | + data-subscrpt-cat="all" | |
| 65 | + aria-current="<?php echo $subscrpt_all_active ? 'page' : 'false'; ?>" | |
| 66 | + > | |
| 67 | + <span class="wpsubs-vnav__label"><?php esc_html_e( 'All Settings', 'subscription' ); ?></span> | |
| 68 | + </a> | |
| 69 | + <?php | |
| 70 | + $subscrpt_cat_labels = SettingsHelper::categories(); | |
| 71 | + foreach ( $category_groups as $subscrpt_cat_id => $subscrpt_cat_group_ids ) : | |
| 72 | + $subscrpt_cat_active = $subscrpt_cat_id === $active_cat; | |
| 73 | + ?> | |
| 74 | + <a | |
| 75 | + class="wpsubs-vnav__item<?php echo $subscrpt_cat_active ? ' is-active' : ''; ?>" | |
| 76 | + href="<?php echo esc_url( add_query_arg( 'cat', $subscrpt_cat_id, $subscrpt_settings_base ) ); ?>" | |
| 77 | + data-subscrpt-cat="<?php echo esc_attr( $subscrpt_cat_id ); ?>" | |
| 78 | + aria-current="<?php echo $subscrpt_cat_active ? 'page' : 'false'; ?>" | |
| 79 | + > | |
| 80 | + <span class="wpsubs-vnav__label"><?php echo esc_html( $subscrpt_cat_labels[ $subscrpt_cat_id ] ?? $subscrpt_cat_id ); ?></span> | |
| 81 | + <?php if ( SettingsHelper::category_is_pro_locked( $subscrpt_cat_group_ids, $settings_fields ) ) : ?> | |
| 82 | + <?php echo wp_kses_post( SettingsHelper::pro_badge_html() ); ?> | |
| 83 | + <?php endif; ?> | |
| 84 | + </a> | |
| 85 | + <?php endforeach; ?> | |
| 86 | + </nav> | |
| 87 | + </aside> | |
| 88 | + | |
| 89 | + <div class="subscrpt-settings__content"> | |
| 90 | + | |
| 91 | + <div class="subscrpt-settings__panels"> | |
| 92 | + <?php | |
| 93 | + // One card per settings group, so groups stay visually separate | |
| 94 | + // instead of running together in a single section card. The rail | |
| 95 | + // shows a group's whole section; "All Settings" shows every card. | |
| 96 | + foreach ( $category_groups as $subscrpt_cat_id => $subscrpt_cat_group_ids ) : | |
| 97 | + $subscrpt_cat_open = 'all' === $active_cat || $subscrpt_cat_id === $active_cat; | |
| 98 | + foreach ( $subscrpt_cat_group_ids as $subscrpt_group_id ) : | |
| 99 | + $subscrpt_group = $settings_fields[ $subscrpt_group_id ] ?? array(); | |
| 100 | + $subscrpt_fields = array_values( $subscrpt_group['fields'] ?? array() ); | |
| 101 | + $subscrpt_count = count( $subscrpt_fields ); | |
| 102 | + if ( 0 === $subscrpt_count ) { | |
| 103 | + continue; | |
| 104 | + } | |
| 105 | + $subscrpt_label = SettingsHelper::group_label( $subscrpt_group_id, $subscrpt_group ); | |
| 106 | + ?> | |
| 107 | + <section | |
| 108 | + class="subscrpt-settings__panel wpsubs-table-card" | |
| 109 | + id="subscrpt-panel-<?php echo esc_attr( $subscrpt_group_id ); ?>" | |
| 110 | + role="region" | |
| 111 | + aria-label="<?php echo esc_attr( $subscrpt_label ); ?>" | |
| 112 | + data-subscrpt-panel="<?php echo esc_attr( $subscrpt_group_id ); ?>" | |
| 113 | + data-subscrpt-cat="<?php echo esc_attr( $subscrpt_cat_id ); ?>" | |
| 114 | + <?php echo $subscrpt_cat_open ? '' : 'hidden'; ?> | |
| 115 | + > | |
| 116 | + <?php foreach ( $subscrpt_fields as $subscrpt_idx => $subscrpt_field ) : ?> | |
| 71 | 117 | <?php |
| 72 | - echo wp_kses_post( | |
| 73 | - sprintf( | |
| 74 | - /* translators: HTML tags */ | |
| 75 | - __( '%1$s WooCommerce Stripe Payment Gateway %2$s plugin is required!', 'wp_subscription' ), | |
| 76 | - '<a href="https://wordpress.org/plugins/woocommerce-gateway-stripe/" target="_blank">', | |
| 77 | - '</a>' | |
| 78 | - ) | |
| 79 | - ); | |
| 118 | + $subscrpt_type = $subscrpt_field['type'] ?? 'input'; | |
| 119 | + SettingsHelper::render_settings_field( $subscrpt_type, $subscrpt_field['field_data'] ?? array() ); | |
| 120 | + | |
| 121 | + // No rule before a heading — the heading is itself the break. | |
| 122 | + $subscrpt_next = $subscrpt_fields[ $subscrpt_idx + 1 ] ?? null; | |
| 123 | + $subscrpt_rule = 'heading' !== $subscrpt_type | |
| 124 | + && $subscrpt_idx + 1 < $subscrpt_count | |
| 125 | + && 'heading' !== ( $subscrpt_next['type'] ?? '' ); | |
| 80 | 126 | ?> |
| 81 | - </p> | |
| 82 | - </fieldset> | |
| 83 | - </td> | |
| 84 | - </tr> | |
| 85 | - <tr valign="top"> | |
| 86 | - <th scope="row" class="titledesc"><?php esc_html_e( 'Auto Renewal Toggle', 'wp_subscription' ); ?></th> | |
| 87 | - <td class="forminp forminp-checkbox"> | |
| 88 | - <fieldset> | |
| 89 | - <legend class="screen-reader-text"><span><?php esc_html_e( 'Auto Renewal Toggle', 'wp_subscription' ); ?></span></legend> | |
| 90 | - <label for="wp_subscription_auto_renewal_toggle"> | |
| 91 | - <input name="wp_subscription_auto_renewal_toggle" id="wp_subscription_auto_renewal_toggle" type="checkbox" value="1" <?php checked( get_option( 'wp_subscription_auto_renewal_toggle', '1' ), '1' ); ?> /> | |
| 92 | - <?php esc_html_e( 'Display the auto renewal toggle', 'wp_subscription' ); ?> | |
| 93 | - </label> | |
| 94 | - <p class="description"><?php esc_html_e( 'Allow customers to turn on and off automatic renewals from their Subscription details page.', 'wp_subscription' ); ?></p> | |
| 95 | - </fieldset> | |
| 96 | - </td> | |
| 97 | - </tr> | |
| 98 | - <?php do_action( 'wp_subscription_setting_fields' ); ?> | |
| 99 | - <?php if ( ! class_exists('Sdevs_Wc_Subscription_Pro') ) : ?> | |
| 100 | - <!-- PRO Features (subtle, grayed out) --> | |
| 101 | - <tr class="wp-subscription-pro-setting-row" style="opacity:0.55;pointer-events:none;"> | |
| 102 | - <th scope="row"> | |
| 103 | - <label><?php esc_html_e( 'Variable Product Options', 'wp_subscription' ); ?></label> | |
| 104 | - </th> | |
| 105 | - <td> | |
| 106 | - <input type="text" disabled placeholder="Available in PRO" style="width:220px;" /> | |
| 107 | - <p class="description">Set flexible options for variable subscription products <span style="color:#2196f3;font-weight:600;">PRO</span></p> | |
| 108 | - </td> | |
| 109 | - </tr> | |
| 110 | - <tr class="wp-subscription-pro-setting-row" style="opacity:0.55;pointer-events:none;"> | |
| 111 | - <th scope="row"> | |
| 112 | - <label><?php esc_html_e( 'Delivery Schedule', 'wp_subscription' ); ?></label> | |
| 113 | - </th> | |
| 114 | - <td> | |
| 115 | - <select disabled><option><?php esc_html_e('Available in PRO', 'wp_subscription'); ?></option></select> | |
| 116 | - <p class="description">Custom delivery intervals for subscriptions <span style="color:#2196f3;font-weight:600;">PRO</span></p> | |
| 117 | - </td> | |
| 118 | - </tr> | |
| 119 | - <tr class="wp-subscription-pro-setting-row" style="opacity:0.55;pointer-events:none;"> | |
| 120 | - <th scope="row"> | |
| 121 | - <label><?php esc_html_e( 'Subscription History', 'wp_subscription' ); ?></label> | |
| 122 | - </th> | |
| 123 | - <td> | |
| 124 | - <input type="text" disabled placeholder="Available in PRO" style="width:220px;" /> | |
| 125 | - <p class="description">View detailed subscription change history <span style="color:#2196f3;font-weight:600;">PRO</span></p> | |
| 126 | - </td> | |
| 127 | - </tr> | |
| 128 | - <tr class="wp-subscription-pro-setting-row" style="opacity:0.55;pointer-events:none;"> | |
| 129 | - <th scope="row"> | |
| 130 | - <label><?php esc_html_e( 'More Subscription Durations', 'wp_subscription' ); ?></label> | |
| 131 | - </th> | |
| 132 | - <td> | |
| 133 | - <input type="text" disabled placeholder="Available in PRO" style="width:220px;" /> | |
| 134 | - <p class="description">Offer more flexible/custom subscription periods <span style="color:#2196f3;font-weight:600;">PRO</span></p> | |
| 135 | - </td> | |
| 136 | - </tr> | |
| 137 | - <tr class="wp-subscription-pro-setting-row" style="opacity:0.55;pointer-events:none;"> | |
| 138 | - <th scope="row"> | |
| 139 | - <label><?php esc_html_e( 'Sign Up Fee', 'wp_subscription' ); ?></label> | |
| 140 | - </th> | |
| 141 | - <td> | |
| 142 | - <input type="number" disabled placeholder="Available in PRO" style="width:120px;" /> | |
| 143 | - <p class="description">Charge a one-time sign up fee <span style="color:#2196f3;font-weight:600;">PRO</span></p> | |
| 144 | - </td> | |
| 145 | - </tr> | |
| 146 | - <tr class="wp-subscription-pro-setting-row" style="opacity:0.55;pointer-events:none;"> | |
| 147 | - <th scope="row"> | |
| 148 | - <label><?php esc_html_e( 'Early Renewal', 'wp_subscription' ); ?></label> | |
| 149 | - </th> | |
| 150 | - <td> | |
| 151 | - <input type="checkbox" disabled /> | |
| 152 | - <p class="description">Allow early renewal for subscriptions <span style="color:#2196f3;font-weight:600;">PRO</span></p> | |
| 153 | - </td> | |
| 154 | - </tr> | |
| 155 | - <tr class="wp-subscription-pro-setting-row" style="opacity:0.55;pointer-events:none;"> | |
| 156 | - <th scope="row"> | |
| 157 | - <label><?php esc_html_e( 'Renewal Price', 'wp_subscription' ); ?></label> | |
| 158 | - </th> | |
| 159 | - <td> | |
| 160 | - <input type="number" disabled placeholder="Available in PRO" style="width:120px;" /> | |
| 161 | - <p class="description">Set a different price for renewals <span style="color:#2196f3;font-weight:600;">PRO</span></p> | |
| 162 | - </td> | |
| 163 | - </tr> | |
| 164 | - <?php endif; ?> | |
| 165 | - </tbody> | |
| 166 | - </table> | |
| 167 | - <?php submit_button( __( 'Save changes', 'wp_subscription' ), 'primary large' ); ?> | |
| 127 | + <?php if ( $subscrpt_rule ) : ?> | |
| 128 | + <div class="subscrpt-settings__rule"></div> | |
| 129 | + <?php endif; ?> | |
| 130 | + <?php endforeach; ?> | |
| 131 | + </section> | |
| 132 | + <?php endforeach; ?> | |
| 133 | + <?php endforeach; ?> | |
| 134 | + </div> | |
| 135 | + | |
| 136 | + </div> | |
| 137 | + | |
| 168 | 138 | </div> |
| 169 | 139 | </form> |
| 140 | + | |
| 170 | 141 | </div> |