PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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 -249 6.255.4 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,91 +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 - public $disallowed_words;
101 -
102 - public $allowed_words;
103 -
104 41 public function __construct( $args = array() ) {
105 42 if ( ! defined( 'ABSPATH' ) ) {
106 43 die( 'You are not allowed to call this page directly.' );
107 44 }
108 45
109 - $settings = get_option( $this->option_name );
46 + $settings = get_transient( $this->option_name );
110 47
111 48 if ( ! is_object( $settings ) ) {
112 49 $settings = $this->translate_settings( $settings );
113 50 }
@@ -122,18 +59,29 @@
122 59 $this->maybe_filter_for_form( $args );
123 60 }
124 61
125 62 private function translate_settings( $settings ) {
126 - if ( $settings ) {
127 - // Workaround for W3 total cache conflict.
63 + if ( $settings ) { //workaround for W3 total cache conflict
128 64 return unserialize( serialize( $settings ) );
129 65 }
130 66
131 - // If unserializing didn't work.
132 - $settings = $this;
67 + $settings = get_option( $this->option_name );
68 + if ( is_object( $settings ) ) {
69 + set_transient( $this->option_name, $settings );
133 70
134 - update_option( $this->option_name, $settings, 'yes' );
71 + return $settings;
72 + }
135 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 +
136 84 return $settings;
137 85 }
138 86
139 87 /**
@@ -140,54 +88,36 @@
140 88 * @return array
141 89 */
142 90 public function default_options() {
143 91 return array(
144 - 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
145 - 'mu_menu' => 0,
146 - 'fade_form' => false,
147 - '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,
148 100
149 - 're_multi' => 1,
101 + 're_multi' => 1,
150 102
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' ),
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' ),
162 111
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]',
172 -
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',
112 + 'email_to' => '[admin_email]',
113 + 'no_ips' => 0,
114 + 'tracking' => FrmAppHelper::pro_is_installed(),
182 115 );
183 116 }
184 117
185 - /**
186 - * @return void
187 - */
188 118 private function set_default_options() {
189 - $this->fill_captcha_settings();
119 + $this->fill_recaptcha_settings();
190 120
191 121 if ( ! isset( $this->load_style ) ) {
192 122 if ( ! isset( $this->custom_style ) ) {
193 123 $this->custom_style = true;
@@ -211,21 +141,12 @@
211 141 if ( ! isset( $this->$frm_role ) ) {
212 142 $this->$frm_role = 'administrator';
213 143 }
214 144 }
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 145 }
224 146
225 147 /**
226 148 * @param array $params
227 - * @return void
228 149 */
229 150 public function fill_with_defaults( $params = array() ) {
230 151 $settings = $this->default_options();
231 152 $filter_html = ! FrmAppHelper::allow_unfiltered_html();
@@ -249,68 +170,30 @@
249 170 if ( $setting === 'menu' && empty( $this->{$setting} ) ) {
250 171 $this->{$setting} = $default;
251 172 }
252 173
253 - $this->{$setting} = $this->maybe_sanitize_global_setting( $this->{$setting}, $setting, $filter_keys );
254 - unset( $setting, $default );
255 - }
256 - }
257 -
258 - /**
259 - * Handle sanitizing for a target global setting key.
260 - *
261 - * @since 6.0
262 - *
263 - * @param mixed $value The unsanitized global setting value.
264 - * @param string $key The key of the global setting being saved.
265 - * @param array $filter_keys These keys that are filtered with kses.
266 - * @return mixed
267 - */
268 - private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) {
269 - if ( 'custom_css' === $key ) {
270 - if ( false === $value ) {
271 - // Avoid changing the false default value to an empty string.
272 - return $value;
174 + if ( $filter_html && in_array( $setting, $filter_keys, true ) ) {
175 + $this->{$setting} = FrmAppHelper::kses( $this->{$setting}, 'all' );
273 176 }
274 - return sanitize_textarea_field( $value );
275 - }
276 177
277 - if ( in_array( $key, $filter_keys, true ) ) {
278 - return FrmAppHelper::kses( $value, 'all' );
178 + unset( $setting, $default );
279 179 }
280 -
281 - return $value;
282 180 }
283 181
284 - /**
285 - * @return void
286 - */
287 - private function fill_captcha_settings() {
288 - if ( ! isset( $this->active_captcha ) ) {
289 - $this->active_captcha = 'recaptcha';
290 - }
291 -
182 + private function fill_recaptcha_settings() {
292 183 $privkey = '';
293 184 $re_lang = '';
294 185
295 - if ( ! isset( $this->hcaptcha_privkey ) ) {
296 - $this->hcaptcha_privkey = '';
297 - }
298 -
299 - if ( ! isset( $this->turnstile_privkey ) ) {
300 - $this->turnstile_privkey = '';
301 - }
302 -
303 186 if ( ! isset( $this->pubkey ) ) {
304 - // Get the options from the database.
187 + // get the options from the database
305 188 $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;
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;
309 192 }
310 193
311 - if ( empty( $this->re_msg ) ) {
312 - $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' );
313 196 }
314 197
315 198 if ( ! isset( $this->privkey ) ) {
316 199 $this->privkey = $privkey;
@@ -332,10 +215,8 @@
332 215 /**
333 216 * Get values that may be shown on the front-end without an override in the form settings.
334 217 *
335 218 * @since 3.06.01
336 - *
337 - * @return string[]
338 219 */
339 220 public function translatable_strings() {
340 221 return array(
341 222 'invalid_msg',
@@ -348,10 +229,8 @@
348 229 /**
349 230 * Allow strings to be filtered when a specific form may be displaying them.
350 231 *
351 232 * @since 3.06.01
352 - *
353 - * @return void
354 233 */
355 234 public function maybe_filter_for_form( $args ) {
356 235 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
357 236 $this->current_form = $args['current_form'];
@@ -361,21 +240,12 @@
361 240 }
362 241 }
363 242 }
364 243
365 - /**
366 - * @param array $params
367 - * @param array $errors
368 - */
369 244 public function validate( $params, $errors ) {
370 245 return apply_filters( 'frm_validate_settings', $errors, $params );
371 246 }
372 247
373 - /**
374 - * @param array $params
375 - *
376 - * @return void
377 - */
378 248 public function update( $params ) {
379 249 $this->fill_with_defaults( $params );
380 250 $this->update_settings( $params );
381 251
@@ -389,58 +259,28 @@
389 259
390 260 do_action( 'frm_update_settings', $params );
391 261
392 262 if ( function_exists( 'get_filesystem_method' ) ) {
393 - // Save styling settings in case fallback setting changes.
263 + // save styling settings in case fallback setting changes
394 264 $frm_style = new FrmStyle();
395 265 $frm_style->update( 'default' );
396 266 }
397 267 }
398 268
399 - /**
400 - * @param array $params
401 - * @return void
402 - */
403 269 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'];
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'];
419 276
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 - );
277 + $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'tracking', 'admin_bar' );
435 278 foreach ( $checkboxes as $set ) {
436 - $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
279 + $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
437 280 }
438 281 }
439 282
440 - /**
441 - * @return void
442 - */
443 283 private function update_roles( $params ) {
444 284 global $wp_roles;
445 285
446 286 $frm_roles = FrmAppHelper::frm_capabilities();
@@ -445,12 +285,12 @@
445 285
446 286 $frm_roles = FrmAppHelper::frm_capabilities();
447 287 $roles = get_editable_roles();
448 288 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
449 - $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' );
289 + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
450 290
451 291 // Make sure administrators always have permissions
452 - if ( ! in_array( 'administrator', $this->$frm_role, true ) ) {
292 + if ( ! in_array( 'administrator', $this->$frm_role ) ) {
453 293 array_push( $this->$frm_role, 'administrator' );
454 294 }
455 295
456 296 foreach ( $roles as $role => $details ) {
@@ -462,34 +302,8 @@
462 302 }
463 303 }
464 304 }
465 305
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 306 public function store() {
493 307 // Save the posted value in the database
494 308
495 309 update_option( 'frm_options', $this );