| @@ -61,17 +61,17 @@ | ||
| 61 | 61 | // Setting fields. |
| 62 | 62 | $settings_fields = [ |
| 63 | 63 | [ |
| 64 | 64 | 'type' => 'heading', |
| 65 | - 'group' => 'main', | |
| 65 | + 'group' => 'renewals', | |
| 66 | 66 | 'priority' => 0, |
| 67 | 67 | 'field_data' => [ |
| 68 | - 'title' => __( 'General Settings', 'subscription' ), | |
| 68 | + 'title' => __( 'Renewals', 'subscription' ), | |
| 69 | 69 | ], |
| 70 | 70 | ], |
| 71 | 71 | [ |
| 72 | 72 | 'type' => 'select', |
| 73 | - 'group' => 'main', | |
| 73 | + 'group' => 'renewals', | |
| 74 | 74 | 'priority' => 1, |
| 75 | 75 | 'field_data' => [ |
| 76 | 76 | 'id' => 'wp_subscription_renewal_process', |
| 77 | 77 | 'title' => __( 'Renewal Process', 'subscription' ), |
| @@ -79,25 +79,25 @@ | ||
| 79 | 79 | 'options' => [ |
| 80 | 80 | 'auto' => __( 'Automatic', 'subscription' ), |
| 81 | 81 | 'manual' => __( 'Manual', 'subscription' ), |
| 82 | 82 | ], |
| 83 | - 'selected' => esc_attr( get_option( 'wp_subscription_renewal_process', 'auto' ) ), | |
| 83 | + 'selected' => esc_attr( subscrpt_get_renewal_process() ), | |
| 84 | 84 | ], |
| 85 | 85 | ], |
| 86 | 86 | [ |
| 87 | 87 | 'type' => 'input', |
| 88 | - 'group' => 'main', | |
| 88 | + 'group' => 'renewals', | |
| 89 | 89 | 'priority' => 2, |
| 90 | 90 | 'field_data' => [ |
| 91 | 91 | 'id' => 'wp_subscription_manual_renew_cart_notice', |
| 92 | 92 | 'title' => __( 'Renewal Cart Notice', 'subscription' ), |
| 93 | 93 | 'description' => __( 'Display Notice when Renewal Subscription product add to cart. Only available for Manual Renewal Process.', 'subscription' ), |
| 94 | - 'value' => esc_attr( get_option( 'wp_subscription_manual_renew_cart_notice' ) ), | |
| 94 | + 'value' => esc_attr( subscrpt_get_manual_renew_cart_notice() ), | |
| 95 | 95 | ], |
| 96 | 96 | ], |
| 97 | 97 | [ |
| 98 | 98 | 'type' => 'toggle', |
| 99 | - 'group' => 'main', | |
| 99 | + 'group' => 'renewals', | |
| 100 | 100 | 'priority' => 3, |
| 101 | 101 | 'field_data' => [ |
| 102 | 102 | 'id' => 'wp_subscription_stripe_auto_renew', |
| 103 | 103 | 'title' => __( 'Stripe Auto Renewal', 'subscription' ), |
| @@ -113,9 +113,9 @@ | ||
| 113 | 113 | ], |
| 114 | 114 | ], |
| 115 | 115 | [ |
| 116 | 116 | 'type' => 'toggle', |
| 117 | - 'group' => 'main', | |
| 117 | + 'group' => 'renewals', | |
| 118 | 118 | 'priority' => 4, |
| 119 | 119 | 'field_data' => [ |
| 120 | 120 | 'id' => 'wp_subscription_auto_renewal_toggle', |
| 121 | 121 | 'title' => __( 'Auto Renewal Toggle', 'subscription' ), |
| @@ -126,10 +126,10 @@ | ||
| 126 | 126 | ], |
| 127 | 127 | ], |
| 128 | 128 | [ |
| 129 | 129 | 'type' => 'select', |
| 130 | - 'group' => 'main', | |
| 131 | - 'priority' => 5, | |
| 130 | + 'group' => 'role_based_settings', | |
| 131 | + 'priority' => 2, | |
| 132 | 132 | 'field_data' => [ |
| 133 | 133 | 'id' => 'wp_subscription_active_role', |
| 134 | 134 | 'title' => __( 'Subscriber Default Role', 'subscription' ), |
| 135 | 135 | 'description' => __( 'When a subscription is activated, either manually or after a successful purchase, new users will be assigned this role.', 'subscription' ), |
| @@ -138,10 +138,10 @@ | ||
| 138 | 138 | ], |
| 139 | 139 | ], |
| 140 | 140 | [ |
| 141 | 141 | 'type' => 'select', |
| 142 | - 'group' => 'main', | |
| 143 | - 'priority' => 6, | |
| 142 | + 'group' => 'role_based_settings', | |
| 143 | + 'priority' => 3, | |
| 144 | 144 | 'field_data' => [ |
| 145 | 145 | 'id' => 'wp_subscription_unactive_role', |
| 146 | 146 | 'title' => __( 'Subscriber Inactive Role', 'subscription' ), |
| 147 | 147 | 'description' => __( "If a subscriber's subscription is manually cancelled or expires, they will be assigned this role.", 'subscription' ), |
| @@ -221,8 +221,10 @@ | ||
| 221 | 221 | * Settings HTML. |
| 222 | 222 | */ |
| 223 | 223 | public function settings_content() { |
| 224 | 224 | $settings_fields = $this->settings_fields; |
| 225 | + $category_groups = SettingsHelper::category_groups( $settings_fields ); | |
| 226 | + $active_cat = $this->get_active_category( $category_groups ); | |
| 225 | 227 | |
| 226 | 228 | // Header. |
| 227 | 229 | $menu = new Menu(); |
| 228 | 230 | $menu->render_admin_header( __( 'Settings', 'subscription' ) ); |
| @@ -230,8 +232,44 @@ | ||
| 230 | 232 | include 'views/settings.php'; |
| 231 | 233 | |
| 232 | 234 | // Footer. |
| 233 | 235 | $menu->render_admin_footer(); |
| 236 | + } | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * Which settings section the page opens on. | |
| 240 | + * | |
| 241 | + * Read from `?cat=`, and it has to be a query argument rather than a | |
| 242 | + * fragment: the form posts to `options.php`, which redirects back to | |
| 243 | + * `_wp_http_referer`, and a fragment never reaches the server. Keeping the | |
| 244 | + * section in the query string is what returns you to the panel you saved | |
| 245 | + * from. | |
| 246 | + * | |
| 247 | + * Validated against the sections that actually hold groups, so an unknown | |
| 248 | + * or hostile value — or one naming a section only Pro fills — opens the | |
| 249 | + * first real section rather than an empty panel. | |
| 250 | + * | |
| 251 | + * @param array<string,string[]> $category_groups Section key => group keys. | |
| 252 | + * @return string Section key, or an empty string when there are no groups. | |
| 253 | + */ | |
| 254 | + private function get_active_category( array $category_groups ) { | |
| 255 | + $cats = array_keys( $category_groups ); | |
| 256 | + | |
| 257 | + if ( empty( $cats ) ) { | |
| 258 | + return ''; | |
| 259 | + } | |
| 260 | + | |
| 261 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only section selection, validated against the list above. | |
| 262 | + $requested = isset( $_GET['cat'] ) ? sanitize_key( wp_unslash( $_GET['cat'] ) ) : ''; | |
| 263 | + | |
| 264 | + // `all` stacks every section on one page; a known section opens just that | |
| 265 | + // one. With nothing requested (or something invalid), open the first | |
| 266 | + // section rather than the stacked "All Settings" view. | |
| 267 | + if ( 'all' === $requested || in_array( $requested, $cats, true ) ) { | |
| 268 | + return $requested; | |
| 269 | + } | |
| 270 | + | |
| 271 | + return $cats[0]; | |
| 234 | 272 | } |
| 235 | 273 | |
| 236 | 274 | /** |
| 237 | 275 | * Enqueue WooCommerce admin styles for settings page. |