PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.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 +73 -270 6.255.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;
@@ -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,35 +141,13 @@
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 - /**
226 - * @param array $params
227 - * @return void
228 - */
229 147 public function fill_with_defaults( $params = array() ) {
230 - $settings = $this->default_options();
231 - $filter_html = ! FrmAppHelper::allow_unfiltered_html();
148 + $settings = $this->default_options();
232 149
233 - if ( $filter_html ) {
234 - $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
235 - if ( ! empty( $params['additional_filter_keys'] ) ) {
236 - $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
237 - }
238 - } else {
239 - $filter_keys = array();
240 - }
241 -
242 150 foreach ( $settings as $setting => $default ) {
243 151 if ( isset( $params[ 'frm_' . $setting ] ) ) {
244 152 $this->{$setting} = $params[ 'frm_' . $setting ];
245 153 } elseif ( ! isset( $this->{$setting} ) ) {
@@ -245,72 +153,30 @@
245 153 } elseif ( ! isset( $this->{$setting} ) ) {
246 154 $this->{$setting} = $default;
247 155 }
248 156
249 - if ( $setting === 'menu' && empty( $this->{$setting} ) ) {
157 + if ( $setting == 'menu' && empty( $this->{$setting} ) ) {
250 158 $this->{$setting} = $default;
251 159 }
252 160
253 - $this->{$setting} = $this->maybe_sanitize_global_setting( $this->{$setting}, $setting, $filter_keys );
254 161 unset( $setting, $default );
255 162 }
256 163 }
257 164
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;
273 - }
274 - return sanitize_textarea_field( $value );
275 - }
276 -
277 - if ( in_array( $key, $filter_keys, true ) ) {
278 - return FrmAppHelper::kses( $value, 'all' );
279 - }
280 -
281 - return $value;
282 - }
283 -
284 - /**
285 - * @return void
286 - */
287 - private function fill_captcha_settings() {
288 - if ( ! isset( $this->active_captcha ) ) {
289 - $this->active_captcha = 'recaptcha';
290 - }
291 -
165 + private function fill_recaptcha_settings() {
292 166 $privkey = '';
293 167 $re_lang = '';
294 168
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 169 if ( ! isset( $this->pubkey ) ) {
304 - // Get the options from the database.
170 + // get the options from the database
305 171 $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;
172 + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
173 + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
174 + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
309 175 }
310 176
311 - if ( empty( $this->re_msg ) ) {
312 - $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
177 + if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
178 + $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
313 179 }
314 180
315 181 if ( ! isset( $this->privkey ) ) {
316 182 $this->privkey = $privkey;
@@ -322,12 +188,8 @@
322 188
323 189 if ( ! isset( $this->re_type ) ) {
324 190 $this->re_type = '';
325 191 }
326 -
327 - if ( ! isset( $this->re_threshold ) ) {
328 - $this->re_threshold = .5;
329 - }
330 192 }
331 193
332 194 /**
333 195 * Get values that may be shown on the front-end without an override in the form settings.
@@ -332,15 +194,12 @@
332 194 /**
333 195 * Get values that may be shown on the front-end without an override in the form settings.
334 196 *
335 197 * @since 3.06.01
336 - *
337 - * @return string[]
338 198 */
339 199 public function translatable_strings() {
340 200 return array(
341 201 'invalid_msg',
342 - 'admin_permission',
343 202 'failed_msg',
344 203 'login_msg',
345 204 );
346 205 }
@@ -348,10 +207,8 @@
348 207 /**
349 208 * Allow strings to be filtered when a specific form may be displaying them.
350 209 *
351 210 * @since 3.06.01
352 - *
353 - * @return void
354 211 */
355 212 public function maybe_filter_for_form( $args ) {
356 213 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
357 214 $this->current_form = $args['current_form'];
@@ -361,21 +218,12 @@
361 218 }
362 219 }
363 220 }
364 221
365 - /**
366 - * @param array $params
367 - * @param array $errors
368 - */
369 222 public function validate( $params, $errors ) {
370 223 return apply_filters( 'frm_validate_settings', $errors, $params );
371 224 }
372 225
373 - /**
374 - * @param array $params
375 - *
376 - * @return void
377 - */
378 226 public function update( $params ) {
379 227 $this->fill_with_defaults( $params );
380 228 $this->update_settings( $params );
381 229
@@ -389,58 +237,39 @@
389 237
390 238 do_action( 'frm_update_settings', $params );
391 239
392 240 if ( function_exists( 'get_filesystem_method' ) ) {
393 - // Save styling settings in case fallback setting changes.
241 + // save styling settings in case fallback setting changes
394 242 $frm_style = new FrmStyle();
395 243 $frm_style->update( 'default' );
396 244 }
397 245 }
398 246
399 - /**
400 - * @param array $params
401 - * @return void
402 - */
403 247 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'];
248 + $this->pubkey = trim( $params['frm_pubkey'] );
249 + $this->privkey = $params['frm_privkey'];
250 + $this->re_type = $params['frm_re_type'];
251 + $this->re_lang = $params['frm_re_lang'];
252 + $this->load_style = $params['frm_load_style'];
419 253
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 - );
254 + $previous_old_css_setting = $this->old_css;
255 +
256 + $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'old_css', 'no_ips', 'tracking', 'admin_bar' );
435 257 foreach ( $checkboxes as $set ) {
436 - $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
258 + $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
437 259 }
260 +
261 + $this->maybe_remove_old_css_inbox_message( $previous_old_css_setting, $this->old_css );
438 262 }
439 263
440 - /**
441 - * @return void
442 - */
264 + private function maybe_remove_old_css_inbox_message( $previous_setting, $new_setting ) {
265 + $enabled_css_grid = $previous_setting && ! $new_setting;
266 + if ( $enabled_css_grid ) {
267 + $inbox = new FrmInbox();
268 + $inbox->remove( 'old_css' );
269 + }
270 + }
271 +
443 272 private function update_roles( $params ) {
444 273 global $wp_roles;
445 274
446 275 $frm_roles = FrmAppHelper::frm_capabilities();
@@ -445,12 +274,12 @@
445 274
446 275 $frm_roles = FrmAppHelper::frm_capabilities();
447 276 $roles = get_editable_roles();
448 277 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
449 - $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' );
278 + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
450 279
451 280 // Make sure administrators always have permissions
452 - if ( ! in_array( 'administrator', $this->$frm_role, true ) ) {
281 + if ( ! in_array( 'administrator', $this->$frm_role ) ) {
453 282 array_push( $this->$frm_role, 'administrator' );
454 283 }
455 284
456 285 foreach ( $roles as $role => $details ) {
@@ -462,34 +291,8 @@
462 291 }
463 292 }
464 293 }
465 294
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 295 public function store() {
493 296 // Save the posted value in the database
494 297
495 298 update_option( 'frm_options', $this );