| @@ -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,32 +38,12 @@ | ||
| 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 | - | |
| 128 | - /** | |
| 129 | - * @var float|string|null | |
| 130 | - */ | |
| 131 | 46 | public $re_threshold; |
| 132 | 47 | |
| 133 | 48 | /** |
| 134 | 49 | * Settings for hCaptcha. |
| @@ -157,51 +72,17 @@ | ||
| 157 | 72 | * @var string|null |
| 158 | 73 | */ |
| 159 | 74 | public $turnstile_privkey; |
| 160 | 75 | |
| 161 | - /** | |
| 162 | - * @var bool | |
| 163 | - */ | |
| 164 | 76 | public $no_ips; |
| 165 | - | |
| 166 | - /** | |
| 167 | - * @var string | |
| 168 | - */ | |
| 169 | 77 | public $custom_header_ip; |
| 170 | - | |
| 171 | - /** | |
| 172 | - * @var int | |
| 173 | - */ | |
| 174 | 78 | public $current_form = 0; |
| 175 | - | |
| 176 | - /** | |
| 177 | - * @var bool|int | |
| 178 | - */ | |
| 179 | 79 | public $tracking; |
| 180 | - | |
| 181 | - /** | |
| 182 | - * @var bool | |
| 183 | - */ | |
| 184 | 80 | public $summary_emails; |
| 185 | - | |
| 186 | - /** | |
| 187 | - * @var string | |
| 188 | - */ | |
| 189 | 81 | public $summary_emails_recipients; |
| 190 | 82 | |
| 191 | - /** | |
| 192 | - * @var string|null | |
| 193 | - */ | |
| 194 | 83 | public $default_email; |
| 195 | - | |
| 196 | - /** | |
| 197 | - * @var string | |
| 198 | - */ | |
| 199 | 84 | public $from_email; |
| 200 | - | |
| 201 | - /** | |
| 202 | - * @var string|null | |
| 203 | - */ | |
| 204 | 85 | public $currency; |
| 205 | 86 | |
| 206 | 87 | /** |
| 207 | 88 | * @since 6.0 |
| @@ -209,43 +90,16 @@ | ||
| 209 | 90 | * @var false|string|null |
| 210 | 91 | */ |
| 211 | 92 | public $custom_css; |
| 212 | 93 | |
| 213 | - /** | |
| 214 | - * @var int | |
| 215 | - */ | |
| 216 | 94 | public $honeypot; |
| 217 | 95 | |
| 218 | - /** | |
| 219 | - * @var bool | |
| 220 | - */ | |
| 221 | 96 | public $wp_spam_check; |
| 222 | 97 | |
| 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 | 98 | public $disallowed_words; |
| 239 | 99 | |
| 240 | - /** | |
| 241 | - * @var string | |
| 242 | - */ | |
| 243 | 100 | public $allowed_words; |
| 244 | 101 | |
| 245 | - /** | |
| 246 | - * @param array $args | |
| 247 | - */ | |
| 248 | 102 | public function __construct( $args = array() ) { |
| 249 | 103 | if ( ! defined( 'ABSPATH' ) ) { |
| 250 | 104 | die( 'You are not allowed to call this page directly.' ); |
| 251 | 105 | } |
| @@ -265,13 +119,8 @@ | ||
| 265 | 119 | |
| 266 | 120 | $this->maybe_filter_for_form( $args ); |
| 267 | 121 | } |
| 268 | 122 | |
| 269 | - /** | |
| 270 | - * @param false|object $settings | |
| 271 | - * | |
| 272 | - * @return object | |
| 273 | - */ | |
| 274 | 123 | private function translate_settings( $settings ) { |
| 275 | 124 | if ( $settings ) { |
| 276 | 125 | // Workaround for W3 total cache conflict. |
| 277 | 126 | return unserialize( serialize( $settings ) ); |
| @@ -279,9 +128,9 @@ | ||
| 279 | 128 | |
| 280 | 129 | // If unserializing didn't work. |
| 281 | 130 | $settings = $this; |
| 282 | 131 | |
| 283 | - update_option( $this->option_name, $settings, true ); | |
| 132 | + update_option( $this->option_name, $settings, 'yes' ); | |
| 284 | 133 | |
| 285 | 134 | return $settings; |
| 286 | 135 | } |
| 287 | 136 | |
| @@ -323,12 +172,10 @@ | ||
| 323 | 172 | // When it is false, we try to use the old custom_key value from the default style's post_content array. |
| 324 | 173 | 'custom_css' => false, |
| 325 | 174 | 'honeypot' => 1, |
| 326 | 175 | 'wp_spam_check' => 0, |
| 327 | - 'denylist_check' => 0, | |
| 328 | 176 | 'disallowed_words' => '', |
| 329 | 177 | 'allowed_words' => '', |
| 330 | - 'email_style' => 'classic', | |
| 331 | 178 | ); |
| 332 | 179 | } |
| 333 | 180 | |
| 334 | 181 | /** |
| @@ -348,10 +195,9 @@ | ||
| 348 | 195 | $this->fill_with_defaults(); |
| 349 | 196 | |
| 350 | 197 | if ( is_multisite() && is_admin() ) { |
| 351 | 198 | $mu_menu = get_site_option( 'frm_admin_menu_name' ); |
| 352 | - | |
| 353 | - if ( $mu_menu && $mu_menu ) { | |
| 199 | + if ( $mu_menu && ! empty( $mu_menu ) ) { | |
| 354 | 200 | $this->menu = $mu_menu; |
| 355 | 201 | $this->mu_menu = 1; |
| 356 | 202 | } |
| 357 | 203 | } |
| @@ -356,9 +202,8 @@ | ||
| 356 | 202 | } |
| 357 | 203 | } |
| 358 | 204 | |
| 359 | 205 | $frm_roles = FrmAppHelper::frm_capabilities( 'pro' ); |
| 360 | - | |
| 361 | 206 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 362 | 207 | if ( ! isset( $this->$frm_role ) ) { |
| 363 | 208 | $this->$frm_role = 'administrator'; |
| 364 | 209 | } |
| @@ -374,9 +219,8 @@ | ||
| 374 | 219 | } |
| 375 | 220 | |
| 376 | 221 | /** |
| 377 | 222 | * @param array $params |
| 378 | - * | |
| 379 | 223 | * @return void |
| 380 | 224 | */ |
| 381 | 225 | public function fill_with_defaults( $params = array() ) { |
| 382 | 226 | $settings = $this->default_options(); |
| @@ -383,9 +227,8 @@ | ||
| 383 | 227 | $filter_html = ! FrmAppHelper::allow_unfiltered_html(); |
| 384 | 228 | |
| 385 | 229 | if ( $filter_html ) { |
| 386 | 230 | $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' ); |
| 387 | - | |
| 388 | 231 | if ( ! empty( $params['additional_filter_keys'] ) ) { |
| 389 | 232 | $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] ); |
| 390 | 233 | } |
| 391 | 234 | } else { |
| @@ -415,9 +258,8 @@ | ||
| 415 | 258 | * |
| 416 | 259 | * @param mixed $value The unsanitized global setting value. |
| 417 | 260 | * @param string $key The key of the global setting being saved. |
| 418 | 261 | * @param array $filter_keys These keys that are filtered with kses. |
| 419 | - * | |
| 420 | 262 | * @return mixed |
| 421 | 263 | */ |
| 422 | 264 | private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) { |
| 423 | 265 | if ( 'custom_css' === $key ) { |
| @@ -424,9 +266,8 @@ | ||
| 424 | 266 | if ( false === $value ) { |
| 425 | 267 | // Avoid changing the false default value to an empty string. |
| 426 | 268 | return $value; |
| 427 | 269 | } |
| 428 | - | |
| 429 | 270 | return sanitize_textarea_field( $value ); |
| 430 | 271 | } |
| 431 | 272 | |
| 432 | 273 | if ( in_array( $key, $filter_keys, true ) ) { |
| @@ -457,14 +298,14 @@ | ||
| 457 | 298 | |
| 458 | 299 | if ( ! isset( $this->pubkey ) ) { |
| 459 | 300 | // Get the options from the database. |
| 460 | 301 | $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; | |
| 302 | + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : ''; | |
| 303 | + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey; | |
| 304 | + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang; | |
| 464 | 305 | } |
| 465 | 306 | |
| 466 | - if ( ! $this->re_msg ) { | |
| 307 | + if ( empty( $this->re_msg ) ) { | |
| 467 | 308 | $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' ); |
| 468 | 309 | } |
| 469 | 310 | |
| 470 | 311 | if ( ! isset( $this->privkey ) ) { |
| @@ -504,30 +345,23 @@ | ||
| 504 | 345 | * Allow strings to be filtered when a specific form may be displaying them. |
| 505 | 346 | * |
| 506 | 347 | * @since 3.06.01 |
| 507 | 348 | * |
| 508 | - * @param array $args | |
| 509 | - * | |
| 510 | 349 | * @return void |
| 511 | 350 | */ |
| 512 | 351 | public function maybe_filter_for_form( $args ) { |
| 513 | - if ( ! isset( $args['current_form'] ) || ! is_numeric( $args['current_form'] ) ) { | |
| 514 | - return; | |
| 352 | + if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) { | |
| 353 | + $this->current_form = $args['current_form']; | |
| 354 | + foreach ( $this->translatable_strings() as $string ) { | |
| 355 | + $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this ); | |
| 356 | + $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this ); | |
| 357 | + } | |
| 515 | 358 | } |
| 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 | 359 | } |
| 524 | 360 | |
| 525 | 361 | /** |
| 526 | 362 | * @param array $params |
| 527 | 363 | * @param array $errors |
| 528 | - * | |
| 529 | - * @return array | |
| 530 | 364 | */ |
| 531 | 365 | public function validate( $params, $errors ) { |
| 532 | 366 | return apply_filters( 'frm_validate_settings', $errors, $params ); |
| 533 | 367 | } |
| @@ -550,20 +384,17 @@ | ||
| 550 | 384 | $this->update_roles( $params ); |
| 551 | 385 | |
| 552 | 386 | do_action( 'frm_update_settings', $params ); |
| 553 | 387 | |
| 554 | - if ( ! function_exists( 'get_filesystem_method' ) ) { | |
| 555 | - return; | |
| 388 | + if ( function_exists( 'get_filesystem_method' ) ) { | |
| 389 | + // Save styling settings in case fallback setting changes. | |
| 390 | + $frm_style = new FrmStyle(); | |
| 391 | + $frm_style->update( 'default' ); | |
| 556 | 392 | } |
| 557 | - | |
| 558 | - // Save styling settings in case fallback setting changes. | |
| 559 | - $frm_style = new FrmStyle(); | |
| 560 | - $frm_style->update( 'default' ); | |
| 561 | 393 | } |
| 562 | 394 | |
| 563 | 395 | /** |
| 564 | 396 | * @param array $params |
| 565 | - * | |
| 566 | 397 | * @return void |
| 567 | 398 | */ |
| 568 | 399 | private function update_settings( $params ) { |
| 569 | 400 | $this->active_captcha = $params['frm_active_captcha']; |
| @@ -594,11 +425,9 @@ | ||
| 594 | 425 | 'admin_bar', |
| 595 | 426 | 'summary_emails', |
| 596 | 427 | 'honeypot', |
| 597 | 428 | 'wp_spam_check', |
| 598 | - 'denylist_check', | |
| 599 | 429 | ); |
| 600 | - | |
| 601 | 430 | foreach ( $checkboxes as $set ) { |
| 602 | 431 | $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0; |
| 603 | 432 | } |
| 604 | 433 | } |
| @@ -603,10 +432,8 @@ | ||
| 603 | 432 | } |
| 604 | 433 | } |
| 605 | 434 | |
| 606 | 435 | /** |
| 607 | - * @param array $params | |
| 608 | - * | |
| 609 | 436 | * @return void |
| 610 | 437 | */ |
| 611 | 438 | private function update_roles( $params ) { |
| 612 | 439 | global $wp_roles; |
| @@ -612,11 +439,10 @@ | ||
| 612 | 439 | global $wp_roles; |
| 613 | 440 | |
| 614 | 441 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 615 | 442 | $roles = get_editable_roles(); |
| 616 | - | |
| 617 | 443 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 618 | - $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' ); | |
| 444 | + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); | |
| 619 | 445 | |
| 620 | 446 | // Make sure administrators always have permissions |
| 621 | 447 | if ( ! in_array( 'administrator', $this->$frm_role, true ) ) { |
| 622 | 448 | array_push( $this->$frm_role, 'administrator' ); |
| @@ -622,9 +448,9 @@ | ||
| 622 | 448 | array_push( $this->$frm_role, 'administrator' ); |
| 623 | 449 | } |
| 624 | 450 | |
| 625 | 451 | foreach ( $roles as $role => $details ) { |
| 626 | - if ( in_array( $role, $this->$frm_role, true ) ) { | |
| 452 | + if ( in_array( $role, $this->$frm_role ) ) { | |
| 627 | 453 | $wp_roles->add_cap( $role, $frm_role ); |
| 628 | 454 | } else { |
| 629 | 455 | $wp_roles->remove_cap( $role, $frm_role ); |
| 630 | 456 | } |
| @@ -639,9 +465,8 @@ | ||
| 639 | 465 | * |
| 640 | 466 | * @param string $key The setting key to update. |
| 641 | 467 | * @param mixed $value The new value for the setting. |
| 642 | 468 | * @param string $sanitize The name of the sanitization function to apply to the new value. |
| 643 | - * | |
| 644 | 469 | * @return bool True on success, false on failure. |
| 645 | 470 | */ |
| 646 | 471 | public function update_setting( $key, $value, $sanitize ) { |
| 647 | 472 | if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) { |