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 +184 -14 6.25 → 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,18 +209,43 @@
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
228 + /**
229 + * @since 6.25.1
230 + *
231 + * @var int|null 1 if installed after welcome tour update, null otherwise.
232 + */
233 + public $installed_after_welcome_tour_update;
234 +
235 + /**
236 + * @var string
237 + */
100 238 public $disallowed_words;
101 239
240 + /**
241 + * @var string
242 + */
102 243 public $allowed_words;
103 244
245 + /**
246 + * @param array $args
247 + */
104 248 public function __construct( $args = array() ) {
105 249 if ( ! defined( 'ABSPATH' ) ) {
106 250 die( 'You are not allowed to call this page directly.' );
107 251 }
@@ -121,8 +265,13 @@
121 265
122 266 $this->maybe_filter_for_form( $args );
123 267 }
124 268
269 + /**
270 + * @param false|object $settings
271 + *
272 + * @return object
273 + */
125 274 private function translate_settings( $settings ) {
126 275 if ( $settings ) {
127 276 // Workaround for W3 total cache conflict.
128 277 return unserialize( serialize( $settings ) );
@@ -130,9 +279,9 @@
130 279
131 280 // If unserializing didn't work.
132 281 $settings = $this;
133 282
134 - update_option( $this->option_name, $settings, 'yes' );
283 + update_option( $this->option_name, $settings, true );
135 284
136 285 return $settings;
137 286 }
138 287
@@ -199,9 +348,10 @@
199 348 $this->fill_with_defaults();
200 349
201 350 if ( is_multisite() && is_admin() ) {
202 351 $mu_menu = get_site_option( 'frm_admin_menu_name' );
203 - if ( $mu_menu && ! empty( $mu_menu ) ) {
352 +
353 + if ( $mu_menu && $mu_menu ) {
204 354 $this->menu = $mu_menu;
205 355 $this->mu_menu = 1;
206 356 }
207 357 }
@@ -206,8 +356,9 @@
206 356 }
207 357 }
208 358
209 359 $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
360 +
210 361 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
211 362 if ( ! isset( $this->$frm_role ) ) {
212 363 $this->$frm_role = 'administrator';
213 364 }
@@ -223,8 +374,9 @@
223 374 }
224 375
225 376 /**
226 377 * @param array $params
378 + *
227 379 * @return void
228 380 */
229 381 public function fill_with_defaults( $params = array() ) {
230 382 $settings = $this->default_options();
@@ -231,8 +383,9 @@
231 383 $filter_html = ! FrmAppHelper::allow_unfiltered_html();
232 384
233 385 if ( $filter_html ) {
234 386 $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
387 +
235 388 if ( ! empty( $params['additional_filter_keys'] ) ) {
236 389 $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
237 390 }
238 391 } else {
@@ -262,8 +415,9 @@
262 415 *
263 416 * @param mixed $value The unsanitized global setting value.
264 417 * @param string $key The key of the global setting being saved.
265 418 * @param array $filter_keys These keys that are filtered with kses.
419 + *
266 420 * @return mixed
267 421 */
268 422 private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) {
269 423 if ( 'custom_css' === $key ) {
@@ -270,8 +424,9 @@
270 424 if ( false === $value ) {
271 425 // Avoid changing the false default value to an empty string.
272 426 return $value;
273 427 }
428 +
274 429 return sanitize_textarea_field( $value );
275 430 }
276 431
277 432 if ( in_array( $key, $filter_keys, true ) ) {
@@ -307,9 +462,9 @@
307 462 $privkey = $recaptcha_opt['privkey'] ?? $privkey;
308 463 $re_lang = $recaptcha_opt['re_lang'] ?? $re_lang;
309 464 }
310 465
311 - if ( empty( $this->re_msg ) ) {
466 + if ( ! $this->re_msg ) {
312 467 $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
313 468 }
314 469
315 470 if ( ! isset( $this->privkey ) ) {
@@ -349,23 +504,30 @@
349 504 * Allow strings to be filtered when a specific form may be displaying them.
350 505 *
351 506 * @since 3.06.01
352 507 *
508 + * @param array $args
509 + *
353 510 * @return void
354 511 */
355 512 public function maybe_filter_for_form( $args ) {
356 - if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
357 - $this->current_form = $args['current_form'];
358 - foreach ( $this->translatable_strings() as $string ) {
359 - $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
360 - $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
361 - }
513 + if ( ! isset( $args['current_form'] ) || ! is_numeric( $args['current_form'] ) ) {
514 + return;
362 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 + }
363 523 }
364 524
365 525 /**
366 526 * @param array $params
367 527 * @param array $errors
528 + *
529 + * @return array
368 530 */
369 531 public function validate( $params, $errors ) {
370 532 return apply_filters( 'frm_validate_settings', $errors, $params );
371 533 }
@@ -388,17 +550,20 @@
388 550 $this->update_roles( $params );
389 551
390 552 do_action( 'frm_update_settings', $params );
391 553
392 - if ( function_exists( 'get_filesystem_method' ) ) {
393 - // Save styling settings in case fallback setting changes.
394 - $frm_style = new FrmStyle();
395 - $frm_style->update( 'default' );
554 + if ( ! function_exists( 'get_filesystem_method' ) ) {
555 + return;
396 556 }
557 +
558 + // Save styling settings in case fallback setting changes.
559 + $frm_style = new FrmStyle();
560 + $frm_style->update( 'default' );
397 561 }
398 562
399 563 /**
400 564 * @param array $params
565 + *
401 566 * @return void
402 567 */
403 568 private function update_settings( $params ) {
404 569 $this->active_captcha = $params['frm_active_captcha'];
@@ -431,8 +596,9 @@
431 596 'honeypot',
432 597 'wp_spam_check',
433 598 'denylist_check',
434 599 );
600 +
435 601 foreach ( $checkboxes as $set ) {
436 602 $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
437 603 }
438 604 }
@@ -437,8 +603,10 @@
437 603 }
438 604 }
439 605
440 606 /**
607 + * @param array $params
608 + *
441 609 * @return void
442 610 */
443 611 private function update_roles( $params ) {
444 612 global $wp_roles;
@@ -444,8 +612,9 @@
444 612 global $wp_roles;
445 613
446 614 $frm_roles = FrmAppHelper::frm_capabilities();
447 615 $roles = get_editable_roles();
616 +
448 617 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
449 618 $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' );
450 619
451 620 // Make sure administrators always have permissions
@@ -453,9 +622,9 @@
453 622 array_push( $this->$frm_role, 'administrator' );
454 623 }
455 624
456 625 foreach ( $roles as $role => $details ) {
457 - if ( in_array( $role, $this->$frm_role ) ) {
626 + if ( in_array( $role, $this->$frm_role, true ) ) {
458 627 $wp_roles->add_cap( $role, $frm_role );
459 628 } else {
460 629 $wp_roles->remove_cap( $role, $frm_role );
461 630 }
@@ -470,8 +639,9 @@
470 639 *
471 640 * @param string $key The setting key to update.
472 641 * @param mixed $value The new value for the setting.
473 642 * @param string $sanitize The name of the sanitization function to apply to the new value.
643 + *
474 644 * @return bool True on success, false on failure.
475 645 */
476 646 public function update_setting( $key, $value, $sanitize ) {
477 647 if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) {