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