PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
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 +125 -235 6.43.06.06 View file →
@@ -1,56 +1,40 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 -#[\AllowDynamicProperties]
7 3 class FrmSettings {
8 - public $option_name = 'frm_options';
9 - public $menu;
10 - public $mu_menu;
11 - public $use_html;
12 - public $jquery_css;
13 - public $accordion_js;
4 + public $option_name = 'frm_options';
5 + public $menu;
6 + public $mu_menu;
7 + public $use_html;
8 + public $jquery_css;
9 + public $accordion_js;
14 10 public $fade_form;
15 11 public $old_css;
16 - public $admin_bar;
17 12
18 - public $success_msg;
19 - public $blank_msg;
20 - public $unique_msg;
21 - public $invalid_msg;
22 - public $failed_msg;
23 - public $submit_value;
24 - public $login_msg;
25 - public $admin_permission;
13 + public $success_msg;
14 + public $blank_msg;
15 + public $unique_msg;
16 + public $invalid_msg;
17 + public $failed_msg;
18 + public $submit_value;
19 + public $login_msg;
20 + public $admin_permission;
26 21
27 - public $email_to;
28 - public $load_style;
29 - public $custom_style;
22 + public $email_to;
23 + public $load_style;
24 + public $custom_style;
30 25
31 - public $active_captcha;
32 - public $hcaptcha_pubkey;
33 - public $hcaptcha_privkey;
34 - public $pubkey;
35 - public $privkey;
36 - public $re_lang;
26 + public $pubkey;
27 + public $privkey;
28 + public $re_lang;
37 29 public $re_type;
38 - public $re_msg;
30 + public $re_msg;
39 31 public $re_multi;
40 32
41 33 public $no_ips;
42 - public $custom_header_ip;
43 34 public $current_form = 0;
44 35 public $tracking;
45 36
46 - /**
47 - * @since 6.0
48 - *
49 - * @var string|false|null
50 - */
51 - public $custom_css;
52 -
53 37 public function __construct( $args = array() ) {
54 38 if ( ! defined( 'ABSPATH' ) ) {
55 39 die( 'You are not allowed to call this page directly.' );
56 40 }
@@ -60,226 +44,156 @@
60 44 if ( ! is_object( $settings ) ) {
61 45 $settings = $this->translate_settings( $settings );
62 46 }
63 47
64 - foreach ( $settings as $setting_name => $setting ) {
65 - $this->{$setting_name} = $setting;
48 + foreach ( $settings as $setting_name => $setting ) {
49 + $this->{$setting_name} = $setting;
66 50 unset( $setting_name, $setting );
67 - }
51 + }
68 52
69 - $this->set_default_options();
53 + $this->set_default_options();
70 54
71 55 $this->maybe_filter_for_form( $args );
72 - }
56 + }
73 57
74 58 private function translate_settings( $settings ) {
75 - if ( $settings ) { //workaround for W3 total cache conflict
59 + if ( $settings ) { //workaround for W3 total cache conflict
76 60 return unserialize( serialize( $settings ) );
77 - }
61 + }
78 62
79 63 $settings = get_option( $this->option_name );
80 64 if ( is_object( $settings ) ) {
81 65 set_transient( $this->option_name, $settings );
82 -
83 66 return $settings;
84 67 }
85 68
86 - // If unserializing didn't work
87 - if ( $settings ) { //workaround for W3 total cache conflict
69 + // If unserializing didn't work
70 + if ( $settings ) { //workaround for W3 total cache conflict
88 71 $settings = unserialize( serialize( $settings ) );
89 - } else {
90 - $settings = $this;
91 - }
72 + } else {
73 + $settings = $this;
74 + }
92 75
93 76 update_option( $this->option_name, $settings );
94 77 set_transient( $this->option_name, $settings );
95 78
96 - return $settings;
97 - }
79 + return $settings;
80 + }
98 81
99 - /**
100 - * @return array
101 - */
82 + /**
83 + * @return array
84 + */
102 85 public function default_options() {
103 - return array(
104 - 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
105 - 'mu_menu' => 0,
106 - 'use_html' => true,
107 - 'jquery_css' => false,
108 - 'accordion_js' => false,
109 - 'fade_form' => false,
110 - 'old_css' => false,
111 - 'admin_bar' => false,
86 + return array(
87 + 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
88 + 'mu_menu' => 0,
89 + 'use_html' => true,
90 + 'jquery_css' => false,
91 + 'accordion_js' => false,
92 + 'fade_form' => false,
93 + 'old_css' => true,
112 94
113 - 're_multi' => 1,
95 + 're_multi' => 1,
114 96
115 - 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
116 - 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
117 - 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
118 - 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
119 - 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
120 - 'submit_value' => __( 'Submit', 'formidable' ),
121 - 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
122 - 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
123 - 'new_tab_msg' => __( 'The page has been opened in a new tab.', 'formidable' ),
97 + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
98 + 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
99 + 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
100 + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
101 + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
102 + 'submit_value' => __( 'Submit', 'formidable' ),
103 + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
104 + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
124 105
125 - 'email_to' => '[admin_email]',
126 - 'no_ips' => 0,
127 - 'custom_header_ip' => false, // Use false by default. We show a warning when this is unset. Once global settings have been saved, this gets saved
128 - 'tracking' => FrmAppHelper::pro_is_installed(),
106 + 'email_to' => '[admin_email]',
107 + 'no_ips' => 0,
108 + 'tracking' => FrmAppHelper::pro_is_installed(),
109 + );
110 + }
129 111
130 - // Normally custom CSS is a string. A false value is used when nothing has been set.
131 - // When it is false, we try to use the old custom_key value from the default style's post_content array.
132 - 'custom_css' => false,
133 - );
134 - }
135 -
136 - /**
137 - * @return void
138 - */
139 112 private function set_default_options() {
140 - $this->fill_captcha_settings();
113 + $this->fill_recaptcha_settings();
141 114
142 115 if ( ! isset( $this->load_style ) ) {
143 116 if ( ! isset( $this->custom_style ) ) {
144 - $this->custom_style = true;
145 - }
117 + $this->custom_style = true;
118 + }
146 119
147 - $this->load_style = 'all';
148 - }
120 + $this->load_style = 'all';
121 + }
149 122
150 - $this->fill_with_defaults();
123 + $this->fill_with_defaults();
151 124
152 - if ( is_multisite() && is_admin() ) {
125 + if ( is_multisite() && is_admin() ) {
153 126 $mu_menu = get_site_option( 'frm_admin_menu_name' );
154 127 if ( $mu_menu && ! empty( $mu_menu ) ) {
155 - $this->menu = $mu_menu;
156 - $this->mu_menu = 1;
157 - }
158 - }
128 + $this->menu = $mu_menu;
129 + $this->mu_menu = 1;
130 + }
131 + }
159 132
160 133 $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
161 134 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
162 135 if ( ! isset( $this->$frm_role ) ) {
163 - $this->$frm_role = 'administrator';
164 - }
165 - }
166 - }
136 + $this->$frm_role = 'administrator';
137 + }
138 + }
139 + }
167 140
168 - /**
169 - * @param array $params
170 - * @return void
171 - */
172 141 public function fill_with_defaults( $params = array() ) {
173 - $settings = $this->default_options();
174 - $filter_html = ! FrmAppHelper::allow_unfiltered_html();
142 + $settings = $this->default_options();
175 143
176 - if ( $filter_html ) {
177 - $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
178 - if ( ! empty( $params['additional_filter_keys'] ) ) {
179 - $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
180 - }
181 - } else {
182 - $filter_keys = array();
183 - }
184 -
185 - foreach ( $settings as $setting => $default ) {
144 + foreach ( $settings as $setting => $default ) {
186 145 if ( isset( $params[ 'frm_' . $setting ] ) ) {
187 146 $this->{$setting} = $params[ 'frm_' . $setting ];
188 147 } elseif ( ! isset( $this->{$setting} ) ) {
189 - $this->{$setting} = $default;
190 - }
148 + $this->{$setting} = $default;
149 + }
191 150
192 - if ( $setting === 'menu' && empty( $this->{$setting} ) ) {
151 + if ( $setting == 'menu' && empty( $this->{$setting} ) ) {
193 152 $this->{$setting} = $default;
194 153 }
195 154
196 - $this->{$setting} = $this->maybe_sanitize_global_setting( $this->{$setting}, $setting, $filter_keys );
197 155 unset( $setting, $default );
198 - }
199 - }
156 + }
157 + }
200 158
201 - /**
202 - * Handle sanitizing for a target global setting key.
203 - *
204 - * @since 6.0
205 - *
206 - * @param mixed $value The unsanitized global setting value.
207 - * @param string $key The key of the global setting being saved.
208 - * @param array $filter_keys These keys that are filtered with kses.
209 - * @return mixed
210 - */
211 - private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) {
212 - if ( 'custom_css' === $key ) {
213 - if ( false === $value ) {
214 - // Avoid changing the false default value to an empty string.
215 - return $value;
216 - }
217 - return sanitize_textarea_field( $value );
218 - }
159 + private function fill_recaptcha_settings() {
160 + $privkey = '';
161 + $re_lang = '';
219 162
220 - if ( in_array( $key, $filter_keys, true ) ) {
221 - return FrmAppHelper::kses( $value, 'all' );
222 - }
223 -
224 - return $value;
225 - }
226 -
227 - /**
228 - * @return void
229 - */
230 - private function fill_captcha_settings() {
231 - if ( ! isset( $this->active_captcha ) ) {
232 - $this->active_captcha = 'recaptcha';
233 - }
234 -
235 - $privkey = '';
236 - $re_lang = '';
237 -
238 - if ( ! isset( $this->hcaptcha_privkey ) ) {
239 - $this->hcaptcha_privkey = '';
240 - }
241 -
242 163 if ( ! isset( $this->pubkey ) ) {
243 164 // get the options from the database
244 165 $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
245 - $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
246 - $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
247 - $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
166 + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
167 + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
168 + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
248 169 }
249 170
250 171 if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
251 - $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
252 - }
172 + $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
173 + }
253 174
254 175 if ( ! isset( $this->privkey ) ) {
255 - $this->privkey = $privkey;
256 - }
176 + $this->privkey = $privkey;
177 + }
257 178
258 179 if ( ! isset( $this->re_lang ) ) {
259 - $this->re_lang = $re_lang;
260 - }
180 + $this->re_lang = $re_lang;
181 + }
261 182
262 183 if ( ! isset( $this->re_type ) ) {
263 184 $this->re_type = '';
264 185 }
186 + }
265 187
266 - if ( ! isset( $this->re_threshold ) ) {
267 - $this->re_threshold = .5;
268 - }
269 - }
270 -
271 188 /**
272 189 * Get values that may be shown on the front-end without an override in the form settings.
273 190 *
274 191 * @since 3.06.01
275 - *
276 - * @return string[]
277 192 */
278 193 public function translatable_strings() {
279 194 return array(
280 195 'invalid_msg',
281 - 'admin_permission',
282 196 'failed_msg',
283 197 'login_msg',
284 198 );
285 199 }
@@ -287,10 +201,8 @@
287 201 /**
288 202 * Allow strings to be filtered when a specific form may be displaying them.
289 203 *
290 204 * @since 3.06.01
291 - *
292 - * @return void
293 205 */
294 206 public function maybe_filter_for_form( $args ) {
295 207 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
296 208 $this->current_form = $args['current_form'];
@@ -300,21 +212,12 @@
300 212 }
301 213 }
302 214 }
303 215
304 - /**
305 - * @param array $params
306 - * @param array $errors
307 - */
308 - public function validate( $params, $errors ) {
309 - return apply_filters( 'frm_validate_settings', $errors, $params );
310 - }
216 + public function validate( $params, $errors ) {
217 + return apply_filters( 'frm_validate_settings', $errors, $params );
218 + }
311 219
312 - /**
313 - * @param array $params
314 - *
315 - * @return void
316 - */
317 220 public function update( $params ) {
318 221 $this->fill_with_defaults( $params );
319 222 $this->update_settings( $params );
320 223
@@ -325,67 +228,54 @@
325 228 }
326 229
327 230 $this->update_roles( $params );
328 231
329 - do_action( 'frm_update_settings', $params );
232 + do_action( 'frm_update_settings', $params );
330 233
331 234 if ( function_exists( 'get_filesystem_method' ) ) {
332 - // Save styling settings in case fallback setting changes.
235 + // save styling settings in case fallback setting changes
333 236 $frm_style = new FrmStyle();
334 237 $frm_style->update( 'default' );
335 238 }
336 - }
239 + }
337 240
338 - /**
339 - * @return void
340 - */
341 241 private function update_settings( $params ) {
342 - $this->active_captcha = $params['frm_active_captcha'];
343 - $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
344 - $this->hcaptcha_privkey = trim( $params['frm_hcaptcha_privkey'] );
345 - $this->pubkey = trim( $params['frm_pubkey'] );
346 - $this->privkey = trim( $params['frm_privkey'] );
347 - $this->re_type = $params['frm_re_type'];
348 - $this->re_lang = $params['frm_re_lang'];
349 - $this->re_threshold = floatval( $params['frm_re_threshold'] );
350 - $this->load_style = $params['frm_load_style'];
351 - $this->custom_css = $params['frm_custom_css'];
242 + $this->pubkey = trim( $params['frm_pubkey'] );
243 + $this->privkey = $params['frm_privkey'];
244 + $this->re_type = $params['frm_re_type'];
245 + $this->re_lang = $params['frm_re_lang'];
352 246
353 - $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'custom_header_ip', 'tracking', 'admin_bar' );
247 + $this->load_style = $params['frm_load_style'];
248 +
249 + $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'old_css', 'no_ips', 'tracking' );
354 250 foreach ( $checkboxes as $set ) {
355 - $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
251 + $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
356 252 }
357 - }
253 + }
358 254
359 - /**
360 - * @return void
361 - */
362 255 private function update_roles( $params ) {
363 - global $wp_roles;
256 + global $wp_roles;
364 257
365 - $frm_roles = FrmAppHelper::frm_capabilities();
366 - $roles = get_editable_roles();
367 - foreach ( $frm_roles as $frm_role => $frm_role_description ) {
368 - $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
258 + $frm_roles = FrmAppHelper::frm_capabilities();
259 + $roles = get_editable_roles();
260 + foreach ( $frm_roles as $frm_role => $frm_role_description ) {
261 + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
369 262
370 - // Make sure administrators always have permissions
371 - if ( ! in_array( 'administrator', $this->$frm_role ) ) {
263 + // Make sure administrators always have permissions
264 + if ( ! in_array( 'administrator', $this->$frm_role ) ) {
372 265 array_push( $this->$frm_role, 'administrator' );
373 - }
266 + }
374 267
375 - foreach ( $roles as $role => $details ) {
268 + foreach ( $roles as $role => $details ) {
376 269 if ( in_array( $role, $this->$frm_role ) ) {
377 - $wp_roles->add_cap( $role, $frm_role );
378 - } else {
379 - $wp_roles->remove_cap( $role, $frm_role );
380 - }
381 - }
270 + $wp_roles->add_cap( $role, $frm_role );
271 + } else {
272 + $wp_roles->remove_cap( $role, $frm_role );
273 + }
274 + }
382 275 }
383 - }
276 + }
384 277
385 - /**
386 - * @return void
387 - */
388 278 public function store() {
389 279 // Save the posted value in the database
390 280
391 281 update_option( 'frm_options', $this );