PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmSettings.php +177 -14 6.25.1 → trunk View file →
@@ -4,27 +4,92 @@
4 4 }
5 5
6 6 #[\AllowDynamicProperties]
7 7 class FrmSettings {
8 +
9 + /**
10 + * @var string
11 + */
8 12 public $option_name = 'frm_options';
13 +
14 + /**
15 + * @var int
16 + */
9 17 public $menu;
18 +
19 + /**
20 + * @var int
21 + */
10 22 public $mu_menu;
23 +
24 + /**
25 + * @var int
26 + */
11 27 public $fade_form;
28 +
29 + /**
30 + * @var bool
31 + */
12 32 public $admin_bar;
13 33
34 + /**
35 + * @var string
36 + */
14 37 public $success_msg;
38 +
39 + /**
40 + * @var string
41 + */
15 42 public $blank_msg;
43 +
44 + /**
45 + * @var string
46 + */
16 47 public $unique_msg;
48 +
49 + /**
50 + * @var string
51 + */
17 52 public $invalid_msg;
53 +
54 + /**
55 + * @var string
56 + */
18 57 public $failed_msg;
58 +
59 + /**
60 + * @var string
61 + */
19 62 public $submit_value;
63 +
64 + /**
65 + * @var string
66 + */
20 67 public $login_msg;
68 +
69 + /**
70 + * @var string
71 + */
21 72 public $admin_permission;
22 73
74 + /**
75 + * @var string
76 + */
23 77 public $email_to;
78 +
79 + /**
80 + * @var string|null
81 + */
24 82 public $load_style;
83 +
84 + /**
85 + * @var bool|int|null
86 + */
25 87 public $custom_style;
26 88
89 + /**
90 + * @var string|null
91 + */
27 92 public $active_captcha;
28 93
29 94 /**
30 95 * Settings for reCAPTCHA.
@@ -38,12 +103,32 @@
38 103 /**
39 104 * @var string|null
40 105 */
41 106 public $privkey;
107 +
108 + /**
109 + * @var string|null
110 + */
42 111 public $re_lang;
112 +
113 + /**
114 + * @var string|null
115 + */
43 116 public $re_type;
117 +
118 + /**
119 + * @var string
120 + */
44 121 public $re_msg;
122 +
123 + /**
124 + * @var bool
125 + */
45 126 public $re_multi;
127 +
128 + /**
129 + * @var float|string|null
130 + */
46 131 public $re_threshold;
47 132
48 133 /**
49 134 * Settings for hCaptcha.
@@ -72,17 +157,51 @@
72 157 * @var string|null
73 158 */
74 159 public $turnstile_privkey;
75 160
161 + /**
162 + * @var bool
163 + */
76 164 public $no_ips;
165 +
166 + /**
167 + * @var string
168 + */
77 169 public $custom_header_ip;
170 +
171 + /**
172 + * @var int
173 + */
78 174 public $current_form = 0;
175 +
176 + /**
177 + * @var bool|int
178 + */
79 179 public $tracking;
180 +
181 + /**
182 + * @var bool
183 + */
80 184 public $summary_emails;
185 +
186 + /**
187 + * @var string
188 + */
81 189 public $summary_emails_recipients;
82 190
191 + /**
192 + * @var string|null
193 + */
83 194 public $default_email;
195 +
196 + /**
197 + * @var string
198 + */
84 199 public $from_email;
200 +
201 + /**
202 + * @var string|null
203 + */
85 204 public $currency;
86 205
87 206 /**
88 207 * @since 6.0
@@ -90,12 +209,21 @@
90 209 * @var false|string|null
91 210 */
92 211 public $custom_css;
93 212
213 + /**
214 + * @var int
215 + */
94 216 public $honeypot;
95 217
218 + /**
219 + * @var bool
220 + */
96 221 public $wp_spam_check;
97 222
223 + /**
224 + * @var bool
225 + */
98 226 public $denylist_check;
99 227
100 228 /**
101 229 * @since 6.25.1
@@ -103,12 +231,21 @@
103 231 * @var int|null 1 if installed after welcome tour update, null otherwise.
104 232 */
105 233 public $installed_after_welcome_tour_update;
106 234
235 + /**
236 + * @var string
237 + */
107 238 public $disallowed_words;
108 239
240 + /**
241 + * @var string
242 + */
109 243 public $allowed_words;
110 244
245 + /**
246 + * @param array $args
247 + */
111 248 public function __construct( $args = array() ) {
112 249 if ( ! defined( 'ABSPATH' ) ) {
113 250 die( 'You are not allowed to call this page directly.' );
114 251 }
@@ -128,8 +265,13 @@
128 265
129 266 $this->maybe_filter_for_form( $args );
130 267 }
131 268
269 + /**
270 + * @param false|object $settings
271 + *
272 + * @return object
273 + */
132 274 private function translate_settings( $settings ) {
133 275 if ( $settings ) {
134 276 // Workaround for W3 total cache conflict.
135 277 return unserialize( serialize( $settings ) );
@@ -137,9 +279,9 @@
137 279
138 280 // If unserializing didn't work.
139 281 $settings = $this;
140 282
141 - update_option( $this->option_name, $settings, 'yes' );
283 + update_option( $this->option_name, $settings, true );
142 284
143 285 return $settings;
144 286 }
145 287
@@ -206,9 +348,10 @@
206 348 $this->fill_with_defaults();
207 349
208 350 if ( is_multisite() && is_admin() ) {
209 351 $mu_menu = get_site_option( 'frm_admin_menu_name' );
210 - if ( $mu_menu && ! empty( $mu_menu ) ) {
352 +
353 + if ( $mu_menu && $mu_menu ) {
211 354 $this->menu = $mu_menu;
212 355 $this->mu_menu = 1;
213 356 }
214 357 }
@@ -213,8 +356,9 @@
213 356 }
214 357 }
215 358
216 359 $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
360 +
217 361 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
218 362 if ( ! isset( $this->$frm_role ) ) {
219 363 $this->$frm_role = 'administrator';
220 364 }
@@ -230,8 +374,9 @@
230 374 }
231 375
232 376 /**
233 377 * @param array $params
378 + *
234 379 * @return void
235 380 */
236 381 public function fill_with_defaults( $params = array() ) {
237 382 $settings = $this->default_options();
@@ -238,8 +383,9 @@
238 383 $filter_html = ! FrmAppHelper::allow_unfiltered_html();
239 384
240 385 if ( $filter_html ) {
241 386 $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
387 +
242 388 if ( ! empty( $params['additional_filter_keys'] ) ) {
243 389 $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
244 390 }
245 391 } else {
@@ -269,8 +415,9 @@
269 415 *
270 416 * @param mixed $value The unsanitized global setting value.
271 417 * @param string $key The key of the global setting being saved.
272 418 * @param array $filter_keys These keys that are filtered with kses.
419 + *
273 420 * @return mixed
274 421 */
275 422 private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) {
276 423 if ( 'custom_css' === $key ) {
@@ -277,8 +424,9 @@
277 424 if ( false === $value ) {
278 425 // Avoid changing the false default value to an empty string.
279 426 return $value;
280 427 }
428 +
281 429 return sanitize_textarea_field( $value );
282 430 }
283 431
284 432 if ( in_array( $key, $filter_keys, true ) ) {
@@ -314,9 +462,9 @@
314 462 $privkey = $recaptcha_opt['privkey'] ?? $privkey;
315 463 $re_lang = $recaptcha_opt['re_lang'] ?? $re_lang;
316 464 }
317 465
318 - if ( empty( $this->re_msg ) ) {
466 + if ( ! $this->re_msg ) {
319 467 $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
320 468 }
321 469
322 470 if ( ! isset( $this->privkey ) ) {
@@ -356,23 +504,30 @@
356 504 * Allow strings to be filtered when a specific form may be displaying them.
357 505 *
358 506 * @since 3.06.01
359 507 *
508 + * @param array $args
509 + *
360 510 * @return void
361 511 */
362 512 public function maybe_filter_for_form( $args ) {
363 - if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
364 - $this->current_form = $args['current_form'];
365 - foreach ( $this->translatable_strings() as $string ) {
366 - $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
367 - $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
368 - }
513 + if ( ! isset( $args['current_form'] ) || ! is_numeric( $args['current_form'] ) ) {
514 + return;
369 515 }
516 +
517 + $this->current_form = $args['current_form'];
518 +
519 + foreach ( $this->translatable_strings() as $string ) {
520 + $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
521 + $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
522 + }
370 523 }
371 524
372 525 /**
373 526 * @param array $params
374 527 * @param array $errors
528 + *
529 + * @return array
375 530 */
376 531 public function validate( $params, $errors ) {
377 532 return apply_filters( 'frm_validate_settings', $errors, $params );
378 533 }
@@ -395,17 +550,20 @@
395 550 $this->update_roles( $params );
396 551
397 552 do_action( 'frm_update_settings', $params );
398 553
399 - if ( function_exists( 'get_filesystem_method' ) ) {
400 - // Save styling settings in case fallback setting changes.
401 - $frm_style = new FrmStyle();
402 - $frm_style->update( 'default' );
554 + if ( ! function_exists( 'get_filesystem_method' ) ) {
555 + return;
403 556 }
557 +
558 + // Save styling settings in case fallback setting changes.
559 + $frm_style = new FrmStyle();
560 + $frm_style->update( 'default' );
404 561 }
405 562
406 563 /**
407 564 * @param array $params
565 + *
408 566 * @return void
409 567 */
410 568 private function update_settings( $params ) {
411 569 $this->active_captcha = $params['frm_active_captcha'];
@@ -438,8 +596,9 @@
438 596 'honeypot',
439 597 'wp_spam_check',
440 598 'denylist_check',
441 599 );
600 +
442 601 foreach ( $checkboxes as $set ) {
443 602 $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
444 603 }
445 604 }
@@ -444,8 +603,10 @@
444 603 }
445 604 }
446 605
447 606 /**
607 + * @param array $params
608 + *
448 609 * @return void
449 610 */
450 611 private function update_roles( $params ) {
451 612 global $wp_roles;
@@ -451,8 +612,9 @@
451 612 global $wp_roles;
452 613
453 614 $frm_roles = FrmAppHelper::frm_capabilities();
454 615 $roles = get_editable_roles();
616 +
455 617 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
456 618 $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' );
457 619
458 620 // Make sure administrators always have permissions
@@ -460,9 +622,9 @@
460 622 array_push( $this->$frm_role, 'administrator' );
461 623 }
462 624
463 625 foreach ( $roles as $role => $details ) {
464 - if ( in_array( $role, $this->$frm_role ) ) {
626 + if ( in_array( $role, $this->$frm_role, true ) ) {
465 627 $wp_roles->add_cap( $role, $frm_role );
466 628 } else {
467 629 $wp_roles->remove_cap( $role, $frm_role );
468 630 }
@@ -477,8 +639,9 @@
477 639 *
478 640 * @param string $key The setting key to update.
479 641 * @param mixed $value The new value for the setting.
480 642 * @param string $sanitize The name of the sanitization function to apply to the new value.
643 + *
481 644 * @return bool True on success, false on failure.
482 645 */
483 646 public function update_setting( $key, $value, $sanitize ) {
484 647 if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) {