PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.10.2
Subscriptions for WooCommerce with Stripe Recurring Payments v1.10.2
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 / Settings.php

Settings.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.10.2, at includes/Admin/Settings.php

252 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpringDevs\Subscription\Admin;
4
5 /**
6 * Class Settings
7 *
8 * @package SpringDevs\Subscription\Admin
9 */
10 class Settings {
11 /**
12 * Settings fields.
13 *
14 * @var array
15 */
16 public $settings_fields = [];
17
18 /**
19 * Initialize the class.
20 */
21 public function __construct() {
22 // Load the settings helper.
23 SettingsHelper::get_instance();
24
25 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
26 add_action( 'admin_init', array( $this, 'register_settings' ) );
27 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_wc_admin_styles' ) );
28 }
29
30 /**
31 * Register submenu on `Subscriptions` menu.
32 *
33 * @return void
34 */
35 public function admin_menu() {
36 // Initialize & process settings fields.
37 $this->initiate_settings_fields();
38
39 // Add submenu page.
40 $parent_slug = 'wp-subscription';
41 add_submenu_page(
42 $parent_slug,
43 __( 'Settings', 'subscription' ),
44 __( 'Settings', 'subscription' ),
45 'manage_options',
46 'wp-subscription-settings',
47 [ $this, 'settings_content' ]
48 );
49 }
50
51 /**
52 * Initialize settings fields.
53 */
54 public function initiate_settings_fields() {
55 global $wp_roles;
56 $roles = [];
57 foreach ( ( $wp_roles->roles ?? [] ) as $role_key => $role ) {
58 $roles[ $role_key ] = $role['name'];
59 }
60
61 // Setting fields.
62 $settings_fields = [
63 [
64 'type' => 'heading',
65 'group' => 'main',
66 'priority' => 0,
67 'field_data' => [
68 'title' => __( 'General Settings', 'subscription' ),
69 ],
70 ],
71 [
72 'type' => 'select',
73 'group' => 'main',
74 'priority' => 1,
75 'field_data' => [
76 'id' => 'wp_subscription_renewal_process',
77 'title' => __( 'Renewal Process', 'subscription' ),
78 'description' => __( 'How renewal process will be done after Subscription Expired.', 'subscription' ),
79 'options' => [
80 'auto' => __( 'Automatic', 'subscription' ),
81 'manual' => __( 'Manual', 'subscription' ),
82 ],
83 'selected' => esc_attr( get_option( 'wp_subscription_renewal_process', 'auto' ) ),
84 ],
85 ],
86 [
87 'type' => 'input',
88 'group' => 'main',
89 'priority' => 2,
90 'field_data' => [
91 'id' => 'wp_subscription_manual_renew_cart_notice',
92 'title' => __( 'Renewal Cart Notice', 'subscription' ),
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' ) ),
95 ],
96 ],
97 [
98 'type' => 'toggle',
99 'group' => 'main',
100 'priority' => 3,
101 'field_data' => [
102 'id' => 'wp_subscription_stripe_auto_renew',
103 'title' => __( 'Stripe Auto Renewal', 'subscription' ),
104 'label' => __( 'Accept Stripe Auto Renewals', 'subscription' ),
105 'description' => sprintf(
106 /* translators: HTML tags */
107 __( '%1$s WooCommerce Stripe Payment Gateway %2$s plugin is required!', 'subscription' ),
108 '<a href="https://wordpress.org/plugins/woocommerce-gateway-stripe/" target="_blank">',
109 '</a>'
110 ),
111 'value' => '1',
112 'checked' => '1' === get_option( 'wp_subscription_stripe_auto_renew', '1' ),
113 ],
114 ],
115 [
116 'type' => 'toggle',
117 'group' => 'main',
118 'priority' => 4,
119 'field_data' => [
120 'id' => 'wp_subscription_auto_renewal_toggle',
121 'title' => __( 'Auto Renewal Toggle', 'subscription' ),
122 'label' => __( 'Display the auto renewal toggle', 'subscription' ),
123 'description' => __( 'Allow customers to turn on and off automatic renewals from their Subscription details page', 'subscription' ),
124 'value' => '1',
125 'checked' => '1' === get_option( 'wp_subscription_auto_renewal_toggle', '1' ),
126 ],
127 ],
128 [
129 'type' => 'select',
130 'group' => 'main',
131 'priority' => 5,
132 'field_data' => [
133 'id' => 'wp_subscription_active_role',
134 'title' => __( 'Subscriber Default Role', 'subscription' ),
135 'description' => __( 'When a subscription is activated, either manually or after a successful purchase, new users will be assigned this role.', 'subscription' ),
136 'options' => $roles,
137 'selected' => esc_attr( get_option( 'wp_subscription_active_role', 'subscriber' ) ),
138 ],
139 ],
140 [
141 'type' => 'select',
142 'group' => 'main',
143 'priority' => 6,
144 'field_data' => [
145 'id' => 'wp_subscription_unactive_role',
146 'title' => __( 'Subscriber Inactive Role', 'subscription' ),
147 'description' => __( "If a subscriber's subscription is manually cancelled or expires, they will be assigned this role.", 'subscription' ),
148 'options' => $roles,
149 'selected' => esc_attr( get_option( 'wp_subscription_unactive_role', 'customer' ) ),
150 ],
151 ],
152 ];
153
154 // Allow other modules to add/modify settings fields.
155 $settings_fields = apply_filters( 'subscrpt_settings_fields', $settings_fields );
156
157 // Process settings fields (group & sort).
158 $settings_fields = apply_filters( 'process_subscrpt_settings_fields', $settings_fields );
159
160 // Set the settings fields.
161 $this->settings_fields = $settings_fields;
162 }
163
164 /**
165 * Register settings options.
166 **/
167 public function register_settings() {
168 register_setting(
169 'wp_subscription_settings',
170 'wp_subscription_renewal_process',
171 array(
172 'type' => 'string',
173 'sanitize_callback' => 'sanitize_text_field',
174 )
175 );
176 register_setting(
177 'wp_subscription_settings',
178 'wp_subscription_manual_renew_cart_notice',
179 array(
180 'type' => 'string',
181 'sanitize_callback' => 'sanitize_textarea_field',
182 )
183 );
184 register_setting(
185 'wp_subscription_settings',
186 'wp_subscription_active_role',
187 array(
188 'type' => 'string',
189 'sanitize_callback' => 'sanitize_text_field',
190 )
191 );
192 register_setting(
193 'wp_subscription_settings',
194 'wp_subscription_unactive_role',
195 array(
196 'type' => 'string',
197 'sanitize_callback' => 'sanitize_text_field',
198 )
199 );
200 register_setting(
201 'wp_subscription_settings',
202 'wp_subscription_stripe_auto_renew',
203 array(
204 'type' => 'string',
205 'sanitize_callback' => 'sanitize_text_field',
206 )
207 );
208 register_setting(
209 'wp_subscription_settings',
210 'wp_subscription_auto_renewal_toggle',
211 array(
212 'type' => 'string',
213 'sanitize_callback' => 'sanitize_text_field',
214 )
215 );
216
217 do_action( 'subscrpt_register_settings', 'subscrpt_settings' );
218 }
219
220 /**
221 * Settings HTML.
222 */
223 public function settings_content() {
224 $settings_fields = $this->settings_fields;
225
226 // Header.
227 $menu = new Menu();
228 $menu->render_admin_header( __( 'Settings', 'subscription' ) );
229
230 include 'views/settings.php';
231
232 // Footer.
233 $menu->render_admin_footer();
234 }
235
236 /**
237 * Enqueue WooCommerce admin styles for settings page.
238 *
239 * @param string $hook The current admin page hook.
240 */
241 public function enqueue_wc_admin_styles( $hook ) {
242 // Only load on our settings page
243 if ( isset( $_GET['post_type'] ) && strpos( sanitize_text_field( wp_unslash( $_GET['post_type'] ) ), 'subscrpt_order' ) !== false ) {
244 // WooCommerce admin styles
245 wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), SUBSCRPT_VERSION );
246 // Optional: WooCommerce enhanced select2
247 wp_enqueue_style( 'woocommerce_admin_select2', WC()->plugin_url() . '/assets/css/select2.css', array(), SUBSCRPT_VERSION );
248 wp_enqueue_script( 'select2' );
249 }
250 }
251 }
252