PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +66 -208 6.256.0 View file →
@@ -2,14 +2,17 @@
2 2 if ( ! defined( 'ABSPATH' ) ) {
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 -#[\AllowDynamicProperties]
7 6 class FrmSettings {
8 7 public $option_name = 'frm_options';
9 8 public $menu;
10 9 public $mu_menu;
10 + public $use_html;
11 + public $jquery_css;
12 + public $accordion_js;
11 13 public $fade_form;
14 + public $old_css;
12 15 public $admin_bar;
13 16
14 17 public $success_msg;
15 18 public $blank_msg;
@@ -24,90 +27,34 @@
24 27 public $load_style;
25 28 public $custom_style;
26 29
27 30 public $active_captcha;
28 -
29 - /**
30 - * Settings for reCAPTCHA.
31 - */
32 -
33 - /**
34 - * @var string|null
35 - */
31 + public $hcaptcha_pubkey;
32 + public $hcaptcha_privkey;
36 33 public $pubkey;
37 -
38 - /**
39 - * @var string|null
40 - */
41 34 public $privkey;
42 35 public $re_lang;
43 36 public $re_type;
44 37 public $re_msg;
45 38 public $re_multi;
46 - public $re_threshold;
47 39
48 - /**
49 - * Settings for hCaptcha.
50 - */
51 -
52 - /**
53 - * @var string
54 - */
55 - public $hcaptcha_pubkey;
56 -
57 - /**
58 - * @var string|null
59 - */
60 - public $hcaptcha_privkey;
61 -
62 - /**
63 - * Settings for Turnstile.
64 - */
65 -
66 - /**
67 - * @var string
68 - */
69 - public $turnstile_pubkey;
70 -
71 - /**
72 - * @var string|null
73 - */
74 - public $turnstile_privkey;
75 -
76 40 public $no_ips;
77 - public $custom_header_ip;
78 41 public $current_form = 0;
79 42 public $tracking;
80 - public $summary_emails;
81 - public $summary_emails_recipients;
82 43
83 - public $default_email;
84 - public $from_email;
85 - public $currency;
86 -
87 44 /**
88 45 * @since 6.0
89 46 *
90 - * @var false|string|null
47 + * @var string|false|null
91 48 */
92 49 public $custom_css;
93 50
94 - public $honeypot;
95 -
96 - public $wp_spam_check;
97 -
98 - public $denylist_check;
99 -
100 - public $disallowed_words;
101 -
102 - public $allowed_words;
103 -
104 51 public function __construct( $args = array() ) {
105 52 if ( ! defined( 'ABSPATH' ) ) {
106 53 die( 'You are not allowed to call this page directly.' );
107 54 }
108 55
109 - $settings = get_option( $this->option_name );
56 + $settings = get_transient( $this->option_name );
110 57
111 58 if ( ! is_object( $settings ) ) {
112 59 $settings = $this->translate_settings( $settings );
113 60 }
@@ -122,18 +69,29 @@
122 69 $this->maybe_filter_for_form( $args );
123 70 }
124 71
125 72 private function translate_settings( $settings ) {
126 - if ( $settings ) {
127 - // Workaround for W3 total cache conflict.
73 + if ( $settings ) { //workaround for W3 total cache conflict
128 74 return unserialize( serialize( $settings ) );
129 75 }
130 76
131 - // If unserializing didn't work.
132 - $settings = $this;
77 + $settings = get_option( $this->option_name );
78 + if ( is_object( $settings ) ) {
79 + set_transient( $this->option_name, $settings );
133 80
134 - update_option( $this->option_name, $settings, 'yes' );
81 + return $settings;
82 + }
135 83
84 + // If unserializing didn't work
85 + if ( $settings ) { //workaround for W3 total cache conflict
86 + $settings = unserialize( serialize( $settings ) );
87 + } else {
88 + $settings = $this;
89 + }
90 +
91 + update_option( $this->option_name, $settings );
92 + set_transient( $this->option_name, $settings );
93 +
136 94 return $settings;
137 95 }
138 96
139 97 /**
@@ -140,52 +98,36 @@
140 98 * @return array
141 99 */
142 100 public function default_options() {
143 101 return array(
144 - 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
145 - 'mu_menu' => 0,
146 - 'fade_form' => false,
147 - 'admin_bar' => false,
102 + 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
103 + 'mu_menu' => 0,
104 + 'use_html' => true,
105 + 'jquery_css' => false,
106 + 'accordion_js' => false,
107 + 'fade_form' => false,
108 + 'old_css' => false,
109 + 'admin_bar' => false,
148 110
149 - 're_multi' => 1,
111 + 're_multi' => 1,
150 112
151 - 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
152 - // translators: %s: [field_name] shortcode.
153 - 'blank_msg' => sprintf( __( '%s cannot be blank.', 'formidable' ), '[field_name]' ),
154 - // translators: %s: [field_name] shortcode.
155 - 'unique_msg' => sprintf( __( '%s must be unique.', 'formidable' ), '[field_name]' ),
156 - 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
157 - 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
158 - 'submit_value' => __( 'Submit', 'formidable' ),
159 - 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
160 - 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
161 - 'new_tab_msg' => __( 'The page has been opened in a new tab.', 'formidable' ),
113 + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
114 + 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
115 + 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
116 + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
117 + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
118 + 'submit_value' => __( 'Submit', 'formidable' ),
119 + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
120 + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
162 121
163 - 'email_to' => '[admin_email]',
164 - 'enable_gdpr' => 0,
165 - 'no_gdpr_cookies' => 0,
166 - 'no_ips' => 0,
167 - 'custom_header_ip' => 0,
168 - 'tracking' => FrmAppHelper::pro_is_installed(),
169 - // Only enable this by default for the main site.
170 - 'summary_emails' => get_current_blog_id() === get_main_site_id(),
171 - 'summary_emails_recipients' => '[admin_email]',
122 + 'email_to' => '[admin_email]',
123 + 'no_ips' => 0,
124 + 'tracking' => FrmAppHelper::pro_is_installed(),
172 125
173 - // Normally custom CSS is a string. A false value is used when nothing has been set.
174 - // When it is false, we try to use the old custom_key value from the default style's post_content array.
175 - 'custom_css' => false,
176 - 'honeypot' => 1,
177 - 'wp_spam_check' => 0,
178 - 'denylist_check' => 0,
179 - 'disallowed_words' => '',
180 - 'allowed_words' => '',
181 - 'email_style' => 'classic',
126 + 'custom_css' => false,
182 127 );
183 128 }
184 129
185 - /**
186 - * @return void
187 - */
188 130 private function set_default_options() {
189 131 $this->fill_captcha_settings();
190 132
191 133 if ( ! isset( $this->load_style ) ) {
@@ -211,16 +153,8 @@
211 153 if ( ! isset( $this->$frm_role ) ) {
212 154 $this->$frm_role = 'administrator';
213 155 }
214 156 }
215 -
216 - if ( ! isset( $this->default_email ) ) {
217 - $this->default_email = get_option( 'admin_email' );
218 - }
219 -
220 - if ( ! isset( $this->currency ) ) {
221 - $this->currency = 'USD';
222 - }
223 157 }
224 158
225 159 /**
226 160 * @param array $params
@@ -266,12 +200,8 @@
266 200 * @return mixed
267 201 */
268 202 private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) {
269 203 if ( 'custom_css' === $key ) {
270 - if ( false === $value ) {
271 - // Avoid changing the false default value to an empty string.
272 - return $value;
273 - }
274 204 return sanitize_textarea_field( $value );
275 205 }
276 206
277 207 if ( in_array( $key, $filter_keys, true ) ) {
@@ -280,36 +210,29 @@
280 210
281 211 return $value;
282 212 }
283 213
284 - /**
285 - * @return void
286 - */
287 214 private function fill_captcha_settings() {
288 215 if ( ! isset( $this->active_captcha ) ) {
289 216 $this->active_captcha = 'recaptcha';
290 217 }
291 218
292 - $privkey = '';
293 - $re_lang = '';
219 + $privkey = '';
220 + $re_lang = '';
294 221
295 222 if ( ! isset( $this->hcaptcha_privkey ) ) {
296 223 $this->hcaptcha_privkey = '';
297 224 }
298 225
299 - if ( ! isset( $this->turnstile_privkey ) ) {
300 - $this->turnstile_privkey = '';
301 - }
302 -
303 226 if ( ! isset( $this->pubkey ) ) {
304 - // Get the options from the database.
227 + // get the options from the database
305 228 $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
306 - $this->pubkey = $recaptcha_opt['pubkey'] ?? '';
307 - $privkey = $recaptcha_opt['privkey'] ?? $privkey;
308 - $re_lang = $recaptcha_opt['re_lang'] ?? $re_lang;
229 + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
230 + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
231 + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
309 232 }
310 233
311 - if ( empty( $this->re_msg ) ) {
234 + if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
312 235 $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
313 236 }
314 237
315 238 if ( ! isset( $this->privkey ) ) {
@@ -332,10 +255,8 @@
332 255 /**
333 256 * Get values that may be shown on the front-end without an override in the form settings.
334 257 *
335 258 * @since 3.06.01
336 - *
337 - * @return string[]
338 259 */
339 260 public function translatable_strings() {
340 261 return array(
341 262 'invalid_msg',
@@ -348,10 +269,8 @@
348 269 /**
349 270 * Allow strings to be filtered when a specific form may be displaying them.
350 271 *
351 272 * @since 3.06.01
352 - *
353 - * @return void
354 273 */
355 274 public function maybe_filter_for_form( $args ) {
356 275 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
357 276 $this->current_form = $args['current_form'];
@@ -361,21 +280,12 @@
361 280 }
362 281 }
363 282 }
364 283
365 - /**
366 - * @param array $params
367 - * @param array $errors
368 - */
369 284 public function validate( $params, $errors ) {
370 285 return apply_filters( 'frm_validate_settings', $errors, $params );
371 286 }
372 287
373 - /**
374 - * @param array $params
375 - *
376 - * @return void
377 - */
378 288 public function update( $params ) {
379 289 $this->fill_with_defaults( $params );
380 290 $this->update_settings( $params );
381 291
@@ -395,52 +305,26 @@
395 305 $frm_style->update( 'default' );
396 306 }
397 307 }
398 308
399 - /**
400 - * @param array $params
401 - * @return void
402 - */
403 309 private function update_settings( $params ) {
404 - $this->active_captcha = $params['frm_active_captcha'];
405 - $this->pubkey = trim( $params['frm_pubkey'] );
406 - $this->privkey = trim( $params['frm_privkey'] );
407 - $this->re_type = $params['frm_re_type'];
408 - $this->re_lang = $params['frm_re_lang'];
409 - $this->re_threshold = floatval( $params['frm_re_threshold'] );
410 - $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
411 - $this->hcaptcha_privkey = trim( $params['frm_hcaptcha_privkey'] );
412 - $this->turnstile_pubkey = trim( $params['frm_turnstile_pubkey'] );
413 - $this->turnstile_privkey = trim( $params['frm_turnstile_privkey'] );
414 - $this->load_style = $params['frm_load_style'];
415 - $this->custom_css = $params['frm_custom_css'];
416 - $this->default_email = $params['frm_default_email'];
417 - $this->from_email = $params['frm_from_email'];
418 - $this->currency = $params['frm_currency'];
310 + $this->active_captcha = $params['frm_active_captcha'];
311 + $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
312 + $this->hcaptcha_privkey = $params['frm_hcaptcha_privkey'];
313 + $this->pubkey = trim( $params['frm_pubkey'] );
314 + $this->privkey = $params['frm_privkey'];
315 + $this->re_type = $params['frm_re_type'];
316 + $this->re_lang = $params['frm_re_lang'];
317 + $this->re_threshold = floatval( $params['frm_re_threshold'] );
318 + $this->load_style = $params['frm_load_style'];
319 + $this->custom_css = $params['frm_custom_css'];
419 320
420 - $checkboxes = array(
421 - 'mu_menu',
422 - 're_multi',
423 - 'fade_form',
424 - 'no_ips',
425 - 'no_gdpr_cookies',
426 - 'enable_gdpr',
427 - 'custom_header_ip',
428 - 'tracking',
429 - 'admin_bar',
430 - 'summary_emails',
431 - 'honeypot',
432 - 'wp_spam_check',
433 - 'denylist_check',
434 - );
321 + $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'tracking', 'admin_bar' );
435 322 foreach ( $checkboxes as $set ) {
436 - $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
323 + $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
437 324 }
438 325 }
439 326
440 - /**
441 - * @return void
442 - */
443 327 private function update_roles( $params ) {
444 328 global $wp_roles;
445 329
446 330 $frm_roles = FrmAppHelper::frm_capabilities();
@@ -445,12 +329,12 @@
445 329
446 330 $frm_roles = FrmAppHelper::frm_capabilities();
447 331 $roles = get_editable_roles();
448 332 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
449 - $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' );
333 + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
450 334
451 335 // Make sure administrators always have permissions
452 - if ( ! in_array( 'administrator', $this->$frm_role, true ) ) {
336 + if ( ! in_array( 'administrator', $this->$frm_role ) ) {
453 337 array_push( $this->$frm_role, 'administrator' );
454 338 }
455 339
456 340 foreach ( $roles as $role => $details ) {
@@ -462,34 +346,8 @@
462 346 }
463 347 }
464 348 }
465 349
466 - /**
467 - * Updates a single setting with specified sanitization.
468 - *
469 - * @since 6.9
470 - *
471 - * @param string $key The setting key to update.
472 - * @param mixed $value The new value for the setting.
473 - * @param string $sanitize The name of the sanitization function to apply to the new value.
474 - * @return bool True on success, false on failure.
475 - */
476 - public function update_setting( $key, $value, $sanitize ) {
477 - if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) {
478 - // Setting does not exist or sanitization function name is not callable.
479 - return false;
480 - }
481 -
482 - // Update the property value.
483 - FrmAppHelper::sanitize_value( $sanitize, $value );
484 - $this->{$key} = $value;
485 -
486 - return true;
487 - }
488 -
489 - /**
490 - * @return void
491 - */
492 350 public function store() {
493 351 // Save the posted value in the database
494 352
495 353 update_option( 'frm_options', $this );