PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Settings / SettingService.php
SettingService.php
299 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Settings;
4
5 use SureCart\WordPress\RecaptchaValidationService;
6 use SureCart\Routing\PermalinksSettingsService;
7
8 /**
9 * A service for registering settings.
10 */
11 class SettingService {
12 /**
13 * Boostrap settings.
14 *
15 * @return void
16 */
17 public function bootstrap() {
18 add_action( 'admin_init', [ $this, 'registerSettings' ] );
19 }
20
21 /**
22 * Register settings.
23 *
24 * @return void
25 */
26 public function registerSettings() {
27 $this->register(
28 'surecart',
29 'theme',
30 [
31 'type' => 'string',
32 'show_in_rest' => true,
33 'sanitize_callback' => 'sanitize_text_field',
34 'default' => 'light',
35 ]
36 );
37 $this->register(
38 'surecart',
39 'auto_sync_user_to_customer',
40 [
41 'type' => 'boolean',
42 'show_in_rest' => true,
43 'sanitize_callback' => 'boolval',
44 'default' => false,
45 ]
46 );
47 $this->register(
48 'surecart',
49 'honeypot_enabled',
50 [
51 'type' => 'boolean',
52 'show_in_rest' => true,
53 'sanitize_callback' => 'boolval',
54 'default' => true,
55 ]
56 );
57 $this->register(
58 'surecart',
59 'recaptcha_enabled',
60 [
61 'type' => 'boolean',
62 'show_in_rest' => true,
63 'sanitize_callback' => 'boolval',
64 ]
65 );
66 $this->register(
67 'surecart',
68 'recaptcha_site_key',
69 [
70 'type' => 'string',
71 'show_in_rest' => true,
72 'sanitize_callback' => 'sanitize_text_field',
73 ]
74 );
75 $this->register(
76 'surecart',
77 'recaptcha_secret_key',
78 [
79 'type' => 'string',
80 'show_in_rest' => true,
81 'sanitize_callback' => 'sanitize_text_field',
82 ]
83 );
84 $this->register(
85 'surecart',
86 'recaptcha_min_score',
87 [
88 'type' => 'number',
89 'show_in_rest' => true,
90 'default' => 0.5,
91 'sanitize_callback' => 'sanitize_text_field',
92 ]
93 );
94 $this->register(
95 'surecart',
96 'load_stripe_js',
97 [
98 'type' => 'boolean',
99 'show_in_rest' => true,
100 'sanitize_callback' => 'boolval',
101 ]
102 );
103 $this->register(
104 'surecart',
105 'tracking_confirmation',
106 [
107 'type' => 'boolean',
108 'show_in_rest' => true,
109 'sanitize_callback' => 'boolval',
110 ]
111 );
112 $this->register(
113 'surecart',
114 'tracking_confirmation_message',
115 [
116 'type' => 'string',
117 'show_in_rest' => true,
118 'default' => esc_html__( 'Your email and cart are saved so we can send email reminders about this order.', 'surecart' ),
119 'sanitize_callback' => 'sanitize_text_field',
120 ]
121 );
122 $this->register(
123 'surecart',
124 'buy_link_logo_width',
125 [
126 'type' => 'string',
127 'show_in_rest' => true,
128 'default' => '180px',
129 'sanitize_callback' => 'sanitize_text_field',
130 ]
131 );
132 $this->register(
133 'surecart',
134 'cart_menu_alignment',
135 [
136 'type' => 'string',
137 'show_in_rest' => true,
138 'sanitize_callback' => 'sanitize_text_field',
139 'default' => 'right',
140 ]
141 );
142 $this->register(
143 'surecart',
144 'cart_menu_always_shown',
145 [
146 'type' => 'boolean',
147 'show_in_rest' => true,
148 'sanitize_callback' => 'boolval',
149 'default' => true,
150 ]
151 );
152 $this->register(
153 'surecart',
154 'cart_menu_selected_ids',
155 [
156 'type' => 'array',
157 'items' => 'integer',
158 'show_in_rest' => [
159 'schema' => [
160 'type' => 'array',
161 'items' => [
162 'type' => 'integer',
163 ],
164 ],
165 ],
166 ]
167 );
168 $this->register(
169 'surecart',
170 'cart_icon',
171 [
172 'type' => 'string',
173 'show_in_rest' => true,
174 'sanitize_callback' => 'sanitize_text_field',
175 'default' => 'shopping-bag', // shopping-bag, shopping-cart.
176 ]
177 );
178 $this->register(
179 'surecart',
180 'cart_icon_type',
181 [
182 'type' => 'string',
183 'show_in_rest' => true,
184 'sanitize_callback' => 'sanitize_text_field',
185 'default' => 'floating_icon', // both, floating_icon, menu_icon.
186 ]
187 );
188 $this->register(
189 'surecart',
190 'password_validation_enabled',
191 [
192 'type' => 'boolean',
193 'show_in_rest' => true,
194 'sanitize_callback' => 'boolval',
195 'default' => false,
196 ]
197 );
198 $this->register(
199 'surecart',
200 'shop_admin_menu',
201 [
202 'type' => 'boolean',
203 'show_in_rest' => true,
204 'sanitize_callback' => 'boolval',
205 'default' => true,
206 ]
207 );
208 $this->register(
209 'surecart',
210 'cart_admin_menu',
211 [
212 'type' => 'boolean',
213 'show_in_rest' => true,
214 'sanitize_callback' => 'boolval',
215 'default' => true,
216 ]
217 );
218 $this->register(
219 'surecart',
220 'checkout_admin_menu',
221 [
222 'type' => 'boolean',
223 'show_in_rest' => true,
224 'sanitize_callback' => 'boolval',
225 'default' => true,
226 ]
227 );
228 $this->register(
229 'surecart',
230 'dashboard_admin_menu',
231 [
232 'type' => 'boolean',
233 'show_in_rest' => true,
234 'sanitize_callback' => 'boolval',
235 'default' => true,
236 ]
237 );
238 $this->register(
239 'surecart',
240 'unrestricted_test_mode',
241 [
242 'type' => 'boolean',
243 'show_in_rest' => true,
244 'sanitize_callback' => 'boolval',
245 ]
246 );
247 }
248 /**
249 * Register a setting.
250 *
251 * @param string $option_group A settings group name. Should correspond to an allowed option key name.
252 * Default allowed option key names include 'surecart', 'discussion', 'media',
253 * 'reading', 'writing', and 'options'.
254 * @param string $option_name The name of an option to sanitize and save.
255 * @param array $args {
256 * Data used to describe the setting when registered.
257 *
258 * @type string $type The type of data associated with this setting.
259 * Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
260 * @type string $description A description of the data attached to this setting.
261 * @type callable $sanitize_callback A callback function that sanitizes the option's value.
262 * @type bool|array $show_in_rest Whether data associated with this setting should be included in the REST API.
263 * When registering complex settings, this argument may optionally be an
264 * array with a 'schema' key.
265 * @type mixed $default Default value when calling `get_option()`.
266 */
267 public function register( $option_group, $option_name, $args = [] ) {
268 $service = new RegisterSettingService( $option_group, $option_name, $args );
269 return $service->register();
270 }
271
272 /**
273 * Recaptcha service.
274 *
275 * @return RecaptchaValidationService
276 */
277 public function recaptcha() {
278 return new RecaptchaValidationService();
279 }
280
281 /**
282 * Get the option.
283 *
284 * @return mixed
285 */
286 public function get( $name, $default = false ) {
287 return get_option( 'surecart_' . $name, $default );
288 }
289
290 /**
291 * Get the permalinks settings.
292 *
293 * @return PermalinksSettingsService
294 */
295 public function permalinks() {
296 return new PermalinksSettingsService();
297 }
298 }
299