PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.18
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.18
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 +19 -222 6.336.18 View file →
@@ -4,92 +4,27 @@
4 4 }
5 5
6 6 #[\AllowDynamicProperties]
7 7 class FrmSettings {
8 -
9 - /**
10 - * @var string
11 - */
12 8 public $option_name = 'frm_options';
13 -
14 - /**
15 - * @var int
16 - */
17 9 public $menu;
18 -
19 - /**
20 - * @var int
21 - */
22 10 public $mu_menu;
23 -
24 - /**
25 - * @var int
26 - */
27 11 public $fade_form;
28 -
29 - /**
30 - * @var bool
31 - */
32 12 public $admin_bar;
33 13
34 - /**
35 - * @var string
36 - */
37 14 public $success_msg;
38 -
39 - /**
40 - * @var string
41 - */
42 15 public $blank_msg;
43 -
44 - /**
45 - * @var string
46 - */
47 16 public $unique_msg;
48 -
49 - /**
50 - * @var string
51 - */
52 17 public $invalid_msg;
53 -
54 - /**
55 - * @var string
56 - */
57 18 public $failed_msg;
58 -
59 - /**
60 - * @var string
61 - */
62 19 public $submit_value;
63 -
64 - /**
65 - * @var string
66 - */
67 20 public $login_msg;
68 -
69 - /**
70 - * @var string
71 - */
72 21 public $admin_permission;
73 22
74 - /**
75 - * @var string
76 - */
77 23 public $email_to;
78 -
79 - /**
80 - * @var string|null
81 - */
82 24 public $load_style;
83 -
84 - /**
85 - * @var bool|int|null
86 - */
87 25 public $custom_style;
88 26
89 - /**
90 - * @var string|null
91 - */
92 27 public $active_captcha;
93 28
94 29 /**
95 30 * Settings for reCAPTCHA.
@@ -103,35 +38,14 @@
103 38 /**
104 39 * @var string|null
105 40 */
106 41 public $privkey;
107 -
108 - /**
109 - * @var string|null
110 - */
111 42 public $re_lang;
112 -
113 - /**
114 - * @var string|null
115 - */
116 43 public $re_type;
117 -
118 - /**
119 - * @var string
120 - */
121 44 public $re_msg;
122 -
123 - /**
124 - * @var bool
125 - */
126 45 public $re_multi;
127 46
128 47 /**
129 - * @var float|string|null
130 - */
131 - public $re_threshold;
132 -
133 - /**
134 48 * Settings for hCaptcha.
135 49 */
136 50
137 51 /**
@@ -157,51 +71,17 @@
157 71 * @var string|null
158 72 */
159 73 public $turnstile_privkey;
160 74
161 - /**
162 - * @var bool
163 - */
164 75 public $no_ips;
165 -
166 - /**
167 - * @var string
168 - */
169 76 public $custom_header_ip;
170 -
171 - /**
172 - * @var int
173 - */
174 77 public $current_form = 0;
175 -
176 - /**
177 - * @var bool|int
178 - */
179 78 public $tracking;
180 -
181 - /**
182 - * @var bool
183 - */
184 79 public $summary_emails;
185 -
186 - /**
187 - * @var string
188 - */
189 80 public $summary_emails_recipients;
190 81
191 - /**
192 - * @var string|null
193 - */
194 82 public $default_email;
195 -
196 - /**
197 - * @var string
198 - */
199 83 public $from_email;
200 -
201 - /**
202 - * @var string|null
203 - */
204 84 public $currency;
205 85
206 86 /**
207 87 * @since 6.0
@@ -209,43 +89,8 @@
209 89 * @var false|string|null
210 90 */
211 91 public $custom_css;
212 92
213 - /**
214 - * @var int
215 - */
216 - public $honeypot;
217 -
218 - /**
219 - * @var bool
220 - */
221 - public $wp_spam_check;
222 -
223 - /**
224 - * @var bool
225 - */
226 - public $denylist_check;
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 - */
238 - public $disallowed_words;
239 -
240 - /**
241 - * @var string
242 - */
243 - public $allowed_words;
244 -
245 - /**
246 - * @param array $args
247 - */
248 93 public function __construct( $args = array() ) {
249 94 if ( ! defined( 'ABSPATH' ) ) {
250 95 die( 'You are not allowed to call this page directly.' );
251 96 }
@@ -265,13 +110,8 @@
265 110
266 111 $this->maybe_filter_for_form( $args );
267 112 }
268 113
269 - /**
270 - * @param false|object $settings
271 - *
272 - * @return object
273 - */
274 114 private function translate_settings( $settings ) {
275 115 if ( $settings ) {
276 116 // Workaround for W3 total cache conflict.
277 117 return unserialize( serialize( $settings ) );
@@ -279,9 +119,9 @@
279 119
280 120 // If unserializing didn't work.
281 121 $settings = $this;
282 122
283 - update_option( $this->option_name, $settings, true );
123 + update_option( $this->option_name, $settings, 'yes' );
284 124
285 125 return $settings;
286 126 }
287 127
@@ -309,10 +149,8 @@
309 149 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
310 150 'new_tab_msg' => __( 'The page has been opened in a new tab.', 'formidable' ),
311 151
312 152 'email_to' => '[admin_email]',
313 - 'enable_gdpr' => 0,
314 - 'no_gdpr_cookies' => 0,
315 153 'no_ips' => 0,
316 154 'custom_header_ip' => 0,
317 155 'tracking' => FrmAppHelper::pro_is_installed(),
318 156 // Only enable this by default for the main site.
@@ -321,14 +159,8 @@
321 159
322 160 // Normally custom CSS is a string. A false value is used when nothing has been set.
323 161 // When it is false, we try to use the old custom_key value from the default style's post_content array.
324 162 'custom_css' => false,
325 - 'honeypot' => 1,
326 - 'wp_spam_check' => 0,
327 - 'denylist_check' => 0,
328 - 'disallowed_words' => '',
329 - 'allowed_words' => '',
330 - 'email_style' => 'classic',
331 163 );
332 164 }
333 165
334 166 /**
@@ -348,10 +180,9 @@
348 180 $this->fill_with_defaults();
349 181
350 182 if ( is_multisite() && is_admin() ) {
351 183 $mu_menu = get_site_option( 'frm_admin_menu_name' );
352 -
353 - if ( $mu_menu && $mu_menu ) {
184 + if ( $mu_menu && ! empty( $mu_menu ) ) {
354 185 $this->menu = $mu_menu;
355 186 $this->mu_menu = 1;
356 187 }
357 188 }
@@ -356,9 +187,8 @@
356 187 }
357 188 }
358 189
359 190 $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
360 -
361 191 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
362 192 if ( ! isset( $this->$frm_role ) ) {
363 193 $this->$frm_role = 'administrator';
364 194 }
@@ -374,9 +204,8 @@
374 204 }
375 205
376 206 /**
377 207 * @param array $params
378 - *
379 208 * @return void
380 209 */
381 210 public function fill_with_defaults( $params = array() ) {
382 211 $settings = $this->default_options();
@@ -383,9 +212,8 @@
383 212 $filter_html = ! FrmAppHelper::allow_unfiltered_html();
384 213
385 214 if ( $filter_html ) {
386 215 $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
387 -
388 216 if ( ! empty( $params['additional_filter_keys'] ) ) {
389 217 $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
390 218 }
391 219 } else {
@@ -415,9 +243,8 @@
415 243 *
416 244 * @param mixed $value The unsanitized global setting value.
417 245 * @param string $key The key of the global setting being saved.
418 246 * @param array $filter_keys These keys that are filtered with kses.
419 - *
420 247 * @return mixed
421 248 */
422 249 private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) {
423 250 if ( 'custom_css' === $key ) {
@@ -424,9 +251,8 @@
424 251 if ( false === $value ) {
425 252 // Avoid changing the false default value to an empty string.
426 253 return $value;
427 254 }
428 -
429 255 return sanitize_textarea_field( $value );
430 256 }
431 257
432 258 if ( in_array( $key, $filter_keys, true ) ) {
@@ -457,14 +283,14 @@
457 283
458 284 if ( ! isset( $this->pubkey ) ) {
459 285 // Get the options from the database.
460 286 $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
461 - $this->pubkey = $recaptcha_opt['pubkey'] ?? '';
462 - $privkey = $recaptcha_opt['privkey'] ?? $privkey;
463 - $re_lang = $recaptcha_opt['re_lang'] ?? $re_lang;
287 + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
288 + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
289 + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
464 290 }
465 291
466 - if ( ! $this->re_msg ) {
292 + if ( empty( $this->re_msg ) ) {
467 293 $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
468 294 }
469 295
470 296 if ( ! isset( $this->privkey ) ) {
@@ -504,30 +330,23 @@
504 330 * Allow strings to be filtered when a specific form may be displaying them.
505 331 *
506 332 * @since 3.06.01
507 333 *
508 - * @param array $args
509 - *
510 334 * @return void
511 335 */
512 336 public function maybe_filter_for_form( $args ) {
513 - if ( ! isset( $args['current_form'] ) || ! is_numeric( $args['current_form'] ) ) {
514 - return;
337 + if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
338 + $this->current_form = $args['current_form'];
339 + foreach ( $this->translatable_strings() as $string ) {
340 + $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
341 + $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
342 + }
515 343 }
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 - }
523 344 }
524 345
525 346 /**
526 347 * @param array $params
527 348 * @param array $errors
528 - *
529 - * @return array
530 349 */
531 350 public function validate( $params, $errors ) {
532 351 return apply_filters( 'frm_validate_settings', $errors, $params );
533 352 }
@@ -550,20 +369,17 @@
550 369 $this->update_roles( $params );
551 370
552 371 do_action( 'frm_update_settings', $params );
553 372
554 - if ( ! function_exists( 'get_filesystem_method' ) ) {
555 - return;
373 + if ( function_exists( 'get_filesystem_method' ) ) {
374 + // Save styling settings in case fallback setting changes.
375 + $frm_style = new FrmStyle();
376 + $frm_style->update( 'default' );
556 377 }
557 -
558 - // Save styling settings in case fallback setting changes.
559 - $frm_style = new FrmStyle();
560 - $frm_style->update( 'default' );
561 378 }
562 379
563 380 /**
564 381 * @param array $params
565 - *
566 382 * @return void
567 383 */
568 384 private function update_settings( $params ) {
569 385 $this->active_captcha = $params['frm_active_captcha'];
@@ -581,24 +397,9 @@
581 397 $this->default_email = $params['frm_default_email'];
582 398 $this->from_email = $params['frm_from_email'];
583 399 $this->currency = $params['frm_currency'];
584 400
585 - $checkboxes = array(
586 - 'mu_menu',
587 - 're_multi',
588 - 'fade_form',
589 - 'no_ips',
590 - 'no_gdpr_cookies',
591 - 'enable_gdpr',
592 - 'custom_header_ip',
593 - 'tracking',
594 - 'admin_bar',
595 - 'summary_emails',
596 - 'honeypot',
597 - 'wp_spam_check',
598 - 'denylist_check',
599 - );
600 -
401 + $checkboxes = array( 'mu_menu', 're_multi', 'fade_form', 'no_ips', 'custom_header_ip', 'tracking', 'admin_bar', 'summary_emails' );
601 402 foreach ( $checkboxes as $set ) {
602 403 $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
603 404 }
604 405 }
@@ -603,10 +404,8 @@
603 404 }
604 405 }
605 406
606 407 /**
607 - * @param array $params
608 - *
609 408 * @return void
610 409 */
611 410 private function update_roles( $params ) {
612 411 global $wp_roles;
@@ -612,11 +411,10 @@
612 411 global $wp_roles;
613 412
614 413 $frm_roles = FrmAppHelper::frm_capabilities();
615 414 $roles = get_editable_roles();
616 -
617 415 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
618 - $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' );
416 + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
619 417
620 418 // Make sure administrators always have permissions
621 419 if ( ! in_array( 'administrator', $this->$frm_role, true ) ) {
622 420 array_push( $this->$frm_role, 'administrator' );
@@ -622,9 +420,9 @@
622 420 array_push( $this->$frm_role, 'administrator' );
623 421 }
624 422
625 423 foreach ( $roles as $role => $details ) {
626 - if ( in_array( $role, $this->$frm_role, true ) ) {
424 + if ( in_array( $role, $this->$frm_role ) ) {
627 425 $wp_roles->add_cap( $role, $frm_role );
628 426 } else {
629 427 $wp_roles->remove_cap( $role, $frm_role );
630 428 }
@@ -639,9 +437,8 @@
639 437 *
640 438 * @param string $key The setting key to update.
641 439 * @param mixed $value The new value for the setting.
642 440 * @param string $sanitize The name of the sanitization function to apply to the new value.
643 - *
644 441 * @return bool True on success, false on failure.
645 442 */
646 443 public function update_setting( $key, $value, $sanitize ) {
647 444 if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) {