PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.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/FrmStyle.php +204 -376 6.306.0 View file →
@@ -3,35 +3,14 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmStyle {
7 + public $number = false; // Unique ID number of the current instance.
8 + public $id = 0; // the id of the post
7 9
8 10 /**
9 - * The meta name of default template style.
10 - *
11 - * @since 6.14
12 - *
13 - * @var string
11 + * @param int|string $id The id of the stylsheet or 'default'
14 12 */
15 - private $default_template_style_meta_name = 'frm_style_default';
16 -
17 - /**
18 - * Unique ID number of the current instance.
19 - *
20 - * @var int
21 - */
22 - public $number = false;
23 -
24 - /**
25 - * The id of the post.
26 - *
27 - * @var int|string
28 - */
29 - public $id = 0;
30 -
31 - /**
32 - * @param int|string $id The id of the stylesheet or 'default'.
33 - */
34 13 public function __construct( $id = 0 ) {
35 14 $this->id = $id;
36 15 }
37 16
@@ -41,11 +20,10 @@
41 20 public function get_new() {
42 21 $this->id = 0;
43 22
44 23 $max_slug_value = 2147483647;
45 - // We want to have at least 2 characters in the slug.
46 - $min_slug_value = 37;
47 - $key = base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 );
24 + $min_slug_value = 37; // we want to have at least 2 characters in the slug
25 + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
48 26
49 27 $style = array(
50 28 'post_type' => FrmStylesController::$post_type,
51 29 'ID' => '',
@@ -60,9 +38,8 @@
60 38 }
61 39
62 40 /**
63 41 * @param array $settings
64 - *
65 42 * @return int|WP_Error
66 43 */
67 44 public function save( $settings ) {
68 45 return FrmDb::save_settings( $settings, 'frm_styles' );
@@ -67,13 +44,8 @@
67 44 public function save( $settings ) {
68 45 return FrmDb::save_settings( $settings, 'frm_styles' );
69 46 }
70 47
71 - /**
72 - * @param int|string $id The id of the stylesheet or 'default'.
73 - *
74 - * @return void
75 - */
76 48 public function duplicate( $id ) {
77 49 // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
78 50 }
79 51
@@ -80,27 +52,25 @@
80 52 /**
81 53 * Handle save actions in the visual styler edit page.
82 54 *
83 55 * @param mixed $id
84 - *
85 56 * @return array<int|WP_Error>
86 57 */
87 58 public function update( $id = 'default' ) {
88 - $all_instances = $this->get_all();
89 - $css_scope_helper = new FrmCssScopeHelper();
59 + $all_instances = $this->get_all();
90 60
91 61 if ( ! $id ) {
92 - $all_instances[] = (array) $this->get_new();
62 + $new_style = (array) $this->get_new();
63 + $all_instances[] = $new_style;
93 64 }
94 65
95 66 $action_ids = array();
96 67
97 - foreach ( $all_instances as $new_instance ) {
68 + foreach ( $all_instances as $number => $new_instance ) {
98 69 $new_instance = (array) $new_instance;
99 70 $this->id = $new_instance['ID'];
100 71
101 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
102 - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
72 + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
103 73 // Don't continue if not saving this style.
104 74 continue;
105 75 }
106 76
@@ -105,9 +75,9 @@
105 75 }
106 76
107 77 // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing.
108 78 // Preserve the previous value in case Custom CSS has not been saved as a Global Setting yet.
109 - $custom_css = $new_instance['post_content']['custom_css'] ?? '';
79 + $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : '';
110 80
111 81 // phpcs:ignore WordPress.Security.NonceVerification.Missing
112 82 if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) {
113 83 // The nonce check happens in FrmStylesController::save_style before this is called.
@@ -114,20 +84,15 @@
114 84 // phpcs:ignore WordPress.Security.NonceVerification.Missing
115 85 $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) );
116 86 }
117 87
118 - $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $this->sanitize_post_content( wp_unslash( $_POST['frm_style_setting']['post_content'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
88 + $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $this->sanitize_post_content( wp_unslash( $_POST['frm_style_setting']['post_content'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
119 89 $new_instance['post_content']['custom_css'] = $custom_css;
120 90 unset( $custom_css );
121 91
122 - if ( ! empty( $new_instance['post_content']['single_style_custom_css'] ) ) {
123 - $css_scope = 'frm_style_' . $new_instance['post_name'];
124 - $new_instance['post_content']['single_style_custom_css'] = $css_scope_helper->nest( $new_instance['post_content']['single_style_custom_css'], $css_scope );
125 - }
92 + $new_instance['post_type'] = FrmStylesController::$post_type;
93 + $new_instance['post_status'] = 'publish';
126 94
127 - $new_instance['post_type'] = FrmStylesController::$post_type;
128 - $new_instance['post_status'] = 'publish';
129 -
130 95 if ( ! $id ) {
131 96 $new_instance['post_name'] = $new_instance['post_title'];
132 97 }
133 98
@@ -139,10 +104,9 @@
139 104 }
140 105
141 106 if ( $this->is_color( $setting ) ) {
142 107 $color_val = $new_instance['post_content'][ $setting ];
143 -
144 - if ( $color_val !== '' && str_contains( $color_val, 'rgb' ) ) {
108 + if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) {
145 109 // Maybe sanitize if invalid rgba value is entered.
146 110 $this->maybe_sanitize_rgba_value( $color_val );
147 111 }
148 112 $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val );
@@ -152,11 +116,10 @@
152 116 $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
153 117 }
154 118 }
155 119
156 - $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() );
157 - $action_ids[] = $this->save( $new_instance );
158 - }//end foreach
120 + $action_ids[] = $this->save( $new_instance );
121 + }
159 122
160 123 $this->save_settings();
161 124
162 125 return $action_ids;
@@ -166,22 +129,19 @@
166 129 * Sanitize custom color values and convert it to valid one filling missing values.
167 130 *
168 131 * @since 5.3.2
169 132 *
170 - * @param string $color_val The color value, by reference.
171 - *
133 + * @param string $color_val, The color value, by reference.
172 134 * @return void
173 135 */
174 - private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
136 + private function maybe_sanitize_rgba_value( &$color_val ) {
175 137 if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) {
176 138 return;
177 139 }
178 140
179 141 $color_val = trim( $color_val );
180 - // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
181 - $color_val = ltrim( $color_val, '(' );
142 + $color_val = ltrim( $color_val, '(' ); // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
182 143 $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
183 -
184 144 foreach ( $patterns as $pattern ) {
185 145 if ( preg_match( $pattern, $color_val ) === 1 ) {
186 146 return;
187 147 }
@@ -190,11 +150,10 @@
190 150 // Remove all leading ')' braces, then add one back. This way there's always a single brace.
191 151 $color_val = rtrim( $color_val, ')' );
192 152 $color_val .= ')';
193 153
194 - $color_rgba = substr( $color_val, strpos( $color_val, '(' ) + 1, strlen( $color_val ) - strpos( $color_val, '(' ) - 2 );
195 - // Remove any excessive braces from the rgba like rgba((.
196 - $color_rgba = trim( $color_rgba, '()' );
154 + $color_rgba = substr( $color_val, strpos( $color_val, '(' ) + 1, strlen( $color_val ) - strpos( $color_val, '(' ) - 2 );
155 + $color_rgba = trim( $color_rgba, '()' ); // Remove any excessive braces from the rgba like rgba((.
197 156 $length_of_color_codes = strpos( $color_val, '(' );
198 157 $new_color_values = array();
199 158
200 159 // replace empty values by 0 or 1 (if alpha position).
@@ -201,9 +160,9 @@
201 160 foreach ( explode( ',', $color_rgba ) as $index => $value ) {
202 161 $new_value = null;
203 162 $value_is_empty_string = '' === trim( $value ) || '' === $value;
204 163
205 - if ( 3 === $length_of_color_codes || $index !== $length_of_color_codes - 1 ) {
164 + if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) {
206 165 // Insert a value for r, g, or b.
207 166 if ( $value < 0 ) {
208 167 $new_value = 0;
209 168 } elseif ( $value > 255 ) {
@@ -212,9 +171,9 @@
212 171 $new_value = 0;
213 172 } else {
214 173 $new_value = absint( $value );
215 174 }
216 - } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
175 + } else {
217 176 // Insert a value for alpha.
218 177 if ( $value_is_empty_string ) {
219 178 $new_value = 4 === $length_of_color_codes ? 1 : 0;
220 179 } elseif ( $value > 1 || $value < 0 ) {
@@ -221,16 +180,15 @@
221 180 $new_value = 1;
222 181 } else {
223 182 $new_value = floatval( $value );
224 183 }
225 - }//end if
184 + }
226 185
227 - $new_color_values[] = $new_value;
228 - }//end foreach
186 + $new_color_values[] = null === $new_value ? $value : $new_value;
187 + }
229 188
230 189 // add more 0s and 1 (if alpha position) if needed.
231 190 $missing_values = $length_of_color_codes - count( $new_color_values );
232 -
233 191 if ( $missing_values > 1 ) {
234 192 $insert_values = array_fill( 0, $missing_values - 1, 0 );
235 193 $last_value = 4 === $length_of_color_codes ? 1 : 0;
236 194 array_push( $insert_values, $last_value );
@@ -236,9 +194,8 @@
236 194 array_push( $insert_values, $last_value );
237 195 } elseif ( $missing_values === 1 ) {
238 196 $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 );
239 197 }
240 -
241 198 if ( ! empty( $insert_values ) ) {
242 199 $new_color_values = array_merge( $new_color_values, $insert_values );
243 200 }
244 201
@@ -243,19 +200,33 @@
243 200 }
244 201
245 202 $new_color = implode( ',', $new_color_values );
246 203 $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 );
247 - // Limit the number of opening braces after rgb/rgba. There should only be one.
248 - $prefix = rtrim( $prefix, '(' ) . '(';
204 + $prefix = rtrim( $prefix, '(' ) . '('; // Limit the number of opening braces after rgb/rgba. There should only be one.
249 205 $new_color = $prefix . $new_color . ')';
206 +
250 207 $color_val = $new_color;
251 208 }
252 209
253 210 /**
211 + * Unslash everything in post_content but custom_css
212 + *
254 213 * @since 5.0.13
255 214 *
256 215 * @param array $settings
216 + * @return array
217 + */
218 + private function unslash_post_content( $settings ) {
219 + $custom_css = isset( $settings['custom_css'] ) ? $settings['custom_css'] : '';
220 + $settings = wp_unslash( $settings );
221 + $settings['custom_css'] = $custom_css;
222 + return $settings;
223 + }
224 +
225 + /**
226 + * @since 5.0.13
257 227 *
228 + * @param array $settings
258 229 * @return array
259 230 */
260 231 public function sanitize_post_content( $settings ) {
261 232 $defaults = $this->get_defaults();
@@ -260,131 +231,25 @@
260 231 public function sanitize_post_content( $settings ) {
261 232 $defaults = $this->get_defaults();
262 233 $valid_keys = array_keys( $defaults );
263 234 $sanitized_settings = array();
264 -
265 235 foreach ( $valid_keys as $key ) {
266 - $sanitized_settings[ $key ] = isset( $settings[ $key ] ) ? sanitize_textarea_field( $settings[ $key ] ) : $defaults[ $key ];
267 -
268 - if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) {
269 - $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
236 + if ( isset( $settings[ $key ] ) ) {
237 + $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] );
238 + } else {
239 + $sanitized_settings[ $key ] = $defaults[ $key ];
270 240 }
271 241 }
272 -
273 242 return $sanitized_settings;
274 243 }
275 244
276 245 /**
277 - * Remove any characters that should not be used in CSS.
278 - *
279 - * @since 6.2.3
280 - *
281 - * @param string $setting
282 - *
283 - * @return string
284 - */
285 - private function strip_invalid_characters( $setting ) {
286 - $characters_to_remove = array( '{', '}', ';', '[', ']' );
287 -
288 - // RGB is handled instead in self::maybe_sanitize_rgba_value.
289 - if ( ! str_starts_with( $setting, 'rgb' ) ) {
290 - $setting = $this->maybe_fix_braces( $setting, $characters_to_remove );
291 - }
292 -
293 - return str_replace( $characters_to_remove, '', $setting );
294 - }
295 -
296 - /**
297 - * @since 6.2.3
298 - *
299 - * @param string $setting
300 - * @param array $characters_to_remove
301 - *
302 - * @return string
303 - */
304 - private function maybe_fix_braces( $setting, &$characters_to_remove ) {
305 - $number_of_opening_braces = substr_count( $setting, '(' );
306 - $number_of_closing_braces = substr_count( $setting, ')' );
307 -
308 - if ( $number_of_opening_braces === $number_of_closing_braces ) {
309 - return $this->trim_braces( $setting );
310 - }
311 -
312 - if ( $this->should_remove_every_brace( $setting ) ) {
313 - // Add to $characters_to_remove to remove when str_replace is called.
314 - array_push( $characters_to_remove, '(', ')' );
315 - return $setting;
316 - }
317 -
318 - return $this->trim_braces( $setting );
319 - }
320 -
321 - /**
322 - * @since 6.2.3
323 - *
324 - * @param string $input
325 - *
326 - * @return string
327 - */
328 - private function trim_braces( $input ) {
329 - $output = $input;
330 -
331 - // Remove any ( from the start of the string as no CSS values expect at the first character.
332 - if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) {
333 - $output = ltrim( $output, '()' );
334 - }
335 -
336 - // Remove extra braces from the end.
337 - if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) {
338 - $output = rtrim( $output, '()' );
339 -
340 - if ( str_contains( $output, '(' ) ) {
341 - $output .= ')';
342 - }
343 - }
344 -
345 - return $output;
346 - }
347 -
348 - /**
349 - * @since 6.2.3
350 - *
351 - * @param string $setting
352 - *
353 - * @return bool
354 - */
355 - private function should_remove_every_brace( $setting ) {
356 - if ( str_starts_with( trim( $setting, '()' ), 'calc' ) ) {
357 - // Support calc() sizes. We do not want to remove all braces when calc is used.
358 - return false;
359 - }
360 -
361 - // Matches hex values but also checks for unexpected ( and ).
362 - $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting );
363 -
364 - if ( $looks_like_a_hex_value ) {
365 - return true;
366 - }
367 -
368 - // Matches size values but also checks for unexpected ( and ).
369 - // This is case insensitive so it will catch PX, PT, etc, as well.
370 - $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting );
371 - return (bool) $looks_like_a_size;
372 - }
373 -
374 - /**
375 246 * @since 3.01.01
376 - *
377 - * @param string $setting
378 - *
379 - * @return bool
380 247 */
381 248 private function is_color( $setting ) {
382 - if ( str_contains( $setting, 'color' ) ) {
383 - return true;
384 - }
249 + $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
385 250
386 - return in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ), true );
251 + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors );
387 252 }
388 253
389 254 /**
390 255 * @since 3.01.01
@@ -391,9 +256,11 @@
391 256 *
392 257 * @return array
393 258 */
394 259 public function get_color_settings() {
395 - $settings = array_keys( $this->get_defaults() );
260 + $defaults = $this->get_defaults();
261 + $settings = array_keys( $defaults );
262 +
396 263 return array_filter( $settings, array( $this, 'is_color' ) );
397 264 }
398 265
399 266 /**
@@ -419,25 +286,26 @@
419 286 )
420 287 );
421 288 $create_file->create_file( $css );
422 289
423 - update_option( 'frmpro_css', $css, false );
290 + update_option( 'frmpro_css', $css, 'no' );
424 291 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
425 292 }
426 293
427 294 /**
428 295 * @param string $filename
429 - *
430 296 * @return string
431 297 */
432 298 private function get_css_content( $filename ) {
433 - $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
299 + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
300 +
434 301 $saving = true;
435 302 $frm_style = $this;
436 303
437 304 ob_start();
438 305 include $filename;
439 - $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_clean() ) );
306 + $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
307 + ob_end_clean();
440 308
441 309 return FrmStylesController::replace_relative_url( $css );
442 310 }
443 311
@@ -461,10 +329,9 @@
461 329 /**
462 330 * Delete a style by its post ID.
463 331 *
464 332 * @param int $id
465 - *
466 - * @return false|WP_Post|null
333 + * @return WP_Post|false|null
467 334 */
468 335 public function destroy( $id ) {
469 336 if ( $id === $this->get_default_style()->ID ) {
470 337 return false;
@@ -472,16 +339,19 @@
472 339 return wp_delete_post( $id );
473 340 }
474 341
475 342 /**
476 - * @return stdClass|WP_Post
343 + * @return WP_Post|stdClass
477 344 */
478 345 public function get_one() {
479 346 if ( 'default' === $this->id ) {
480 347 $style = $this->get_default_style();
348 + if ( $style ) {
349 + $this->id = $style->ID;
350 + } else {
351 + $this->id = 0;
352 + }
481 353
482 - $this->id = $style ? $style->ID : 0;
483 -
484 354 return $style;
485 355 }
486 356
487 357 $style = get_post( $this->id );
@@ -493,9 +363,9 @@
493 363 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
494 364
495 365 $default_values = $this->get_defaults();
496 366
497 - // Fill default values
367 + // fill default values
498 368 $style->post_content = $this->override_defaults( $style->post_content );
499 369 $style->post_content = wp_parse_args( $style->post_content, $default_values );
500 370
501 371 return $style;
@@ -504,9 +374,8 @@
504 374 /**
505 375 * @param string $orderby
506 376 * @param string $order
507 377 * @param int $limit
508 - *
509 378 * @return array
510 379 */
511 380 public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
512 381 $post_atts = array(
@@ -518,16 +387,16 @@
518 387 );
519 388
520 389 $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
521 390
522 - if ( ! $temp_styles ) {
391 + if ( empty( $temp_styles ) ) {
523 392 global $wpdb;
524 - // Make sure there wasn't a conflict with the query
525 - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
393 + // make sure there wasn't a conflict with the query
394 + $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
526 395 $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
527 396
528 - if ( ! $temp_styles ) {
529 - // Create a new style if there are none
397 + if ( empty( $temp_styles ) ) {
398 + // create a new style if there are none
530 399 $new = $this->get_new();
531 400 $new->post_title = __( 'Formidable Style', 'formidable' );
532 401 $new->post_name = $new->post_title;
533 402 $new->menu_order = 1;
@@ -534,25 +403,25 @@
534 403 $new = $this->save( (array) $new );
535 404 $this->update( 'default' );
536 405
537 406 $post_atts['include'] = $new;
538 - $temp_styles = get_posts( $post_atts );
407 +
408 + $temp_styles = get_posts( $post_atts );
539 409 }
540 410 }
541 411
542 412 $default_values = $this->get_defaults();
543 413 $default_style = false;
544 - $styles = array();
545 414
415 + $styles = array();
546 416 foreach ( $temp_styles as $style ) {
547 417 $this->id = $style->ID;
548 -
549 418 if ( $style->menu_order ) {
550 419 if ( $default_style ) {
551 - // Only return one default
420 + // only return one default
552 421 $style->menu_order = 0;
553 422 } else {
554 - // Check for a default style
423 + // check for a default style
555 424 $default_style = $style->ID;
556 425 }
557 426 }
558 427
@@ -557,17 +426,18 @@
557 426 }
558 427
559 428 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
560 429
561 - // Fill default values
430 + // fill default values
562 431 $style->post_content = $this->override_defaults( $style->post_content );
563 432 $style->post_content = wp_parse_args( $style->post_content, $default_values );
564 433
565 434 $styles[ $style->ID ] = $style;
566 - }//end foreach
435 + }
567 436
568 437 if ( ! $default_style ) {
569 - $default_style = reset( $styles );
438 + $default_style = reset( $styles );
439 +
570 440 $styles[ $default_style->ID ]->menu_order = 1;
571 441 }
572 442
573 443 return $styles;
@@ -572,13 +442,8 @@
572 442
573 443 return $styles;
574 444 }
575 445
576 - /**
577 - * @param array|null $styles
578 - *
579 - * @return object|null
580 - */
581 446 public function get_default_style( $styles = null ) {
582 447 if ( ! isset( $styles ) ) {
583 448 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
584 449 }
@@ -587,15 +452,12 @@
587 452 if ( $style->menu_order ) {
588 453 return $style;
589 454 }
590 455 }
591 -
592 - return null;
593 456 }
594 457
595 458 /**
596 459 * @param mixed $settings
597 - *
598 460 * @return mixed
599 461 */
600 462 public function override_defaults( $settings ) {
601 463 if ( ! is_array( $settings ) ) {
@@ -601,9 +463,9 @@
601 463 if ( ! is_array( $settings ) ) {
602 464 return $settings;
603 465 }
604 466
605 - $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height']; // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong
467 + $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
606 468
607 469 if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
608 470 $settings['form_desc_size'] = $settings['description_font_size'];
609 471 $settings['form_desc_color'] = $settings['description_color'];
@@ -632,147 +494,142 @@
632 494 * @return array
633 495 */
634 496 public function get_defaults() {
635 497 $defaults = array(
636 - 'theme_css' => 'ui-lightness',
637 - 'theme_name' => 'UI Lightness',
498 + 'theme_css' => 'ui-lightness',
499 + 'theme_name' => 'UI Lightness',
638 500
639 - 'center_form' => '',
640 - 'form_width' => '100%',
641 - 'form_align' => 'left',
642 - 'direction' => is_rtl() ? 'rtl' : 'ltr',
643 - 'fieldset' => '0px',
644 - 'fieldset_color' => '000000',
645 - 'fieldset_padding' => '0px 0px 15px 0px',
646 - 'fieldset_bg_color' => '',
501 + 'center_form' => '',
502 + 'form_width' => '100%',
503 + 'form_align' => 'left',
504 + 'direction' => is_rtl() ? 'rtl' : 'ltr',
505 + 'fieldset' => '0px',
506 + 'fieldset_color' => '000000',
507 + 'fieldset_padding' => '0 0 15px 0',
508 + 'fieldset_bg_color' => '',
647 509
648 - 'title_size' => '40px',
649 - 'title_color' => '444444',
650 - 'title_margin_top' => '10px',
651 - 'title_margin_bottom' => '60px',
652 - 'form_desc_size' => '14px',
653 - 'form_desc_color' => '98A2B3',
654 - 'form_desc_margin_top' => '10px',
655 - 'form_desc_margin_bottom' => '25px',
656 - 'form_desc_padding' => '0px',
510 + 'title_size' => '40px',
511 + 'title_color' => '444444',
512 + 'title_margin_top' => '10px',
513 + 'title_margin_bottom' => '60px',
514 + 'form_desc_size' => '14px',
515 + 'form_desc_color' => '666666',
516 + 'form_desc_margin_top' => '10px',
517 + 'form_desc_margin_bottom' => '25px',
518 + 'form_desc_padding' => '0',
657 519
658 - 'font' => '',
659 - 'font_size' => '15px',
660 - 'label_color' => '344054',
661 - 'weight' => 'normal',
662 - 'position' => 'none',
663 - 'align' => 'left',
664 - 'width' => '150px',
665 - 'required_color' => 'F04438',
666 - 'required_weight' => 'bold',
667 - 'label_padding' => '0px 0px 5px 0px',
520 + 'font' => '',
521 + 'font_size' => '15px',
522 + 'label_color' => '3f4b5b',
523 + 'weight' => 'normal',
524 + 'position' => 'none',
525 + 'align' => 'left',
526 + 'width' => '150px',
527 + 'required_color' => 'B94A48',
528 + 'required_weight' => 'bold',
529 + 'label_padding' => '0 0 3px 0',
668 530
669 - 'description_font_size' => '12px',
670 - 'description_color' => '667085',
671 - 'description_weight' => 'normal',
672 - 'description_style' => 'normal',
673 - 'description_align' => 'left',
674 - 'description_margin' => '0px',
531 + 'description_font_size' => '12px',
532 + 'description_color' => '666666',
533 + 'description_weight' => 'normal',
534 + 'description_style' => 'normal',
535 + 'description_align' => 'left',
536 + 'description_margin' => '0',
675 537
676 - 'field_font_size' => '14px',
677 - 'field_height' => '36px',
678 - 'line_height' => 'normal',
679 - 'field_width' => '100%',
680 - 'auto_width' => false,
681 - 'field_pad' => '8px 12px',
682 - 'field_margin' => '20px',
683 - 'field_weight' => 'normal',
684 - 'text_color' => '1D2939',
685 - // 'border_color_hv' => 'cccccc',
686 - 'border_color' => 'D0D5DD',
687 - 'field_border_width' => '1px',
688 - 'field_border_style' => 'solid',
538 + 'field_font_size' => '14px',
539 + 'field_height' => '32px',
540 + 'line_height' => 'normal',
541 + 'field_width' => '100%',
542 + 'auto_width' => false,
543 + 'field_pad' => '6px 10px',
544 + 'field_margin' => '20px',
545 + 'field_weight' => 'normal',
546 + 'text_color' => '555555',
547 + //'border_color_hv' => 'cccccc',
548 + 'border_color' => 'BFC3C8',
549 + 'field_border_width' => '1px',
550 + 'field_border_style' => 'solid',
689 551
690 - 'bg_color' => 'ffffff',
691 - // 'bg_color_hv' => 'ffffff',
692 - 'remove_box_shadow' => '',
693 - 'bg_color_active' => 'ffffff',
694 - 'border_color_active' => '4199FD',
695 - 'remove_box_shadow_active' => '',
696 - 'text_color_error' => '444444',
697 - 'bg_color_error' => 'ffffff',
698 - 'border_color_error' => 'F04438',
699 - 'border_width_error' => '1px',
700 - 'border_style_error' => 'solid',
701 - 'bg_color_disabled' => 'F9FAFB',
702 - 'border_color_disabled' => 'D0D5DD',
703 - 'text_color_disabled' => '667085',
552 + 'bg_color' => 'ffffff',
553 + //'bg_color_hv' => 'ffffff',
554 + 'remove_box_shadow' => '',
555 + 'bg_color_active' => 'ffffff',
556 + 'border_color_active' => '66afe9',
557 + 'remove_box_shadow_active' => '',
558 + 'text_color_error' => '444444',
559 + 'bg_color_error' => 'ffffff',
560 + 'border_color_error' => 'B94A48',
561 + 'border_width_error' => '1px',
562 + 'border_style_error' => 'solid',
563 + 'bg_color_disabled' => 'ffffff',
564 + 'border_color_disabled' => 'E5E5E5',
565 + 'text_color_disabled' => 'A1A1A1',
704 566
705 - 'radio_align' => 'block',
706 - 'check_align' => 'block',
707 - 'check_font_size' => '14px',
708 - 'check_label_color' => '1D2939',
709 - 'check_weight' => 'normal',
567 + 'radio_align' => 'block',
568 + 'check_align' => 'block',
569 + 'check_font_size' => '13px',
570 + 'check_label_color' => '444444',
571 + 'check_weight' => 'normal',
710 572
711 - 'section_font_size' => '18px',
712 - 'section_color' => '344054',
713 - 'section_weight' => 'bold',
714 - 'section_pad' => '32px 0px 3px 0px',
715 - 'section_mar_top' => '30px',
716 - 'section_mar_bottom' => '30px',
717 - 'section_bg_color' => '',
718 - 'section_border_color' => 'EAECF0',
719 - 'section_border_width' => '1px',
720 - 'section_border_style' => 'solid',
721 - 'section_border_loc' => '-top',
722 - 'collapse_icon' => '6',
723 - 'collapse_pos' => 'after',
724 - 'repeat_icon' => '1',
725 - 'repeat_icon_color' => 'ffffff',
573 + 'section_font_size' => '18px',
574 + 'section_color' => '444444',
575 + 'section_weight' => 'bold',
576 + 'section_pad' => '15px 0 3px 0',
577 + 'section_mar_top' => '15px',
578 + 'section_mar_bottom' => '30px',
579 + 'section_bg_color' => '',
580 + 'section_border_color' => 'e8e8e8',
581 + 'section_border_width' => '2px',
582 + 'section_border_style' => 'solid',
583 + 'section_border_loc' => '-top',
584 + 'collapse_icon' => '6',
585 + 'collapse_pos' => 'after',
586 + 'repeat_icon' => '1',
587 + 'repeat_icon_color' => 'ffffff',
726 588
727 589 'submit_style' => false,
728 - 'submit_font_size' => '14px',
590 + 'submit_font_size' => '15px',
729 591 'submit_width' => 'auto',
730 592 'submit_height' => 'auto',
731 - 'submit_bg_color' => '4199FD',
732 - 'submit_border_color' => '4199FD',
593 + 'submit_bg_color' => '579AF6',
594 + 'submit_border_color' => '579AF6',
733 595 'submit_border_width' => '1px',
734 596 'submit_text_color' => 'ffffff',
735 597 'submit_weight' => 'normal',
736 - 'submit_border_radius' => '8px',
598 + 'submit_border_radius' => '4px',
737 599 'submit_bg_img' => '',
738 600 'submit_margin' => '10px',
739 - 'submit_padding' => '8px 16px',
601 + 'submit_padding' => '10px 20px',
740 602 'submit_shadow_color' => 'eeeeee',
741 - 'submit_hover_bg_color' => '3680D3',
742 - 'submit_hover_color' => 'ffffff',
743 - 'submit_hover_border_color' => '3680D3',
744 - 'submit_active_bg_color' => '3680D3',
745 - 'submit_active_color' => 'ffffff',
746 - 'submit_active_border_color' => '3680D3',
603 + 'submit_hover_bg_color' => 'efefef',
604 + 'submit_hover_color' => '444444',
605 + 'submit_hover_border_color' => 'cccccc',
606 + 'submit_active_bg_color' => 'efefef',
607 + 'submit_active_color' => '444444',
608 + 'submit_active_border_color' => 'cccccc',
747 609
748 - 'border_radius' => '8px',
749 - 'error_bg' => 'FEE4E2',
750 - 'error_border' => 'F5B8AA',
751 - 'error_text' => 'F04438',
752 - 'error_font_size' => '14px',
610 + 'border_radius' => '4px',
611 + 'error_bg' => 'F2DEDE',
612 + 'error_border' => 'EBCCD1',
613 + 'error_text' => 'B94A48',
614 + 'error_font_size' => '14px',
753 615
754 - 'success_bg_color' => 'DFF0D8',
755 - 'success_border_color' => 'D6E9C6',
756 - 'success_text_color' => '468847',
757 - 'success_font_size' => '14px',
616 + 'success_bg_color' => 'DFF0D8',
617 + 'success_border_color' => 'D6E9C6',
618 + 'success_text_color' => '468847',
619 + 'success_font_size' => '14px',
758 620
759 - 'important_style' => false,
621 + 'important_style' => false,
760 622
761 - 'progress_bg_color' => 'EAECF0',
762 - 'progress_color' => '1D2939',
763 - 'progress_active_bg_color' => '4199FD',
764 - 'progress_active_color' => 'ffffff',
765 - 'progress_border_color' => 'EAECF0',
766 - 'progress_border_size' => '1px',
767 - 'progress_size' => '30px',
768 - 'custom_css' => '',
769 - 'use_base_font_size' => false,
770 - 'base_font_size' => '15px',
771 - 'field_shape_type' => 'rounded-corner',
623 + 'progress_bg_color' => 'eaeaea',
624 + 'progress_active_color' => 'ffffff',
625 + 'progress_active_bg_color' => '579AF6',
626 + 'progress_color' => '3f4b5b',
627 + 'progress_border_color' => 'E5E5E5',
628 + 'progress_border_size' => '2px',
629 + 'progress_size' => '24px',
772 630
773 - 'enable_style_custom_css' => false,
774 - 'single_style_custom_css' => '',
631 + 'custom_css' => '',
775 632 );
776 633
777 634 return apply_filters( 'frm_default_style_settings', $defaults );
778 635 }
@@ -781,13 +638,12 @@
781 638 * Get a name attribute value for a style setting input.
782 639 *
783 640 * @param string $field_name
784 641 * @param string $post_field
785 - *
786 642 * @return string
787 643 */
788 644 public function get_field_name( $field_name, $post_field = 'post_content' ) {
789 - return 'frm_style_setting' . ( $post_field ? '[' . $post_field . ']' : '' ) . '[' . $field_name . ']';
645 + return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
790 646 }
791 647
792 648 /**
793 649 * @return array
@@ -793,63 +649,35 @@
793 649 * @return array
794 650 */
795 651 public static function get_bold_options() {
796 652 return array(
797 - 100 => __( 'Thin', 'formidable' ),
798 - 200 => __( 'Extra Light', 'formidable' ),
799 - 300 => __( 'Light', 'formidable' ),
800 - 'normal' => __( 'Regular', 'formidable' ),
801 - 500 => __( 'Medium', 'formidable' ),
802 - 600 => __( 'Semi Bold', 'formidable' ),
803 - 'bold' => __( 'Bold', 'formidable' ),
804 - 800 => __( 'Extra Bold', 'formidable' ),
805 - 900 => __( 'Black', 'formidable' ),
653 + 100 => 100,
654 + 200 => 200,
655 + 300 => 300,
656 + 'normal' => __( 'normal', 'formidable' ),
657 + 500 => 500,
658 + 600 => 600,
659 + 'bold' => __( 'bold', 'formidable' ),
660 + 800 => 800,
661 + 900 => 900,
806 662 );
807 663 }
808 664
809 665 /**
810 - * Don't let imbalanced font families ruin the whole stylesheet.
666 + * Don't let imbalanced font families ruin the whole stylesheet
811 667 *
812 668 * @param string $value
813 - *
814 669 * @return string
815 670 */
816 671 public function force_balanced_quotation( $value ) {
817 672 $balanced_characters = array( '"', "'" );
818 -
819 673 foreach ( $balanced_characters as $char ) {
820 674 $char_count = substr_count( $value, $char );
821 - $is_balanced = $char_count % 2 === 0;
822 -
823 - if ( $is_balanced ) {
824 - continue;
825 - }
826 -
827 - if ( $value && $char === $value[ strlen( $value ) - 1 ] ) {
828 - $value = $char . $value;
829 - } else {
675 + $is_balanced = $char_count % 2 == 0;
676 + if ( ! $is_balanced ) {
830 677 $value .= $char;
831 678 }
832 679 }
833 680
834 681 return $value;
835 - }
836 -
837 - /**
838 - * Get the default template style
839 - *
840 - * @since 6.14
841 - *
842 - * @param int|string $style_id The post type "frm_styles" ID.
843 - *
844 - * @return string The json encoded template data
845 - */
846 - public function get_default_template_style( $style_id ) {
847 - $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true );
848 -
849 - if ( ! $default_template ) {
850 - return FrmAppHelper::prepare_and_encode( $this->get_defaults() );
851 - }
852 -
853 - return $default_template;
854 682 }
855 683 }