PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12
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 +87 -229 6.356.12 View file →
@@ -3,19 +3,9 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmStyle {
7 -
8 7 /**
9 - * The meta name of default template style.
10 - *
11 - * @since 6.14
12 - *
13 - * @var string
14 - */
15 - private $default_template_style_meta_name = 'frm_style_default';
16 -
17 - /**
18 8 * Unique ID number of the current instance.
19 9 *
20 10 * @var int
21 11 */
@@ -28,9 +18,9 @@
28 18 */
29 19 public $id = 0;
30 20
31 21 /**
32 - * @param int|string $id The id of the stylesheet or 'default'.
22 + * @param int|string $id The id of the stylsheet or 'default'.
33 23 */
34 24 public function __construct( $id = 0 ) {
35 25 $this->id = $id;
36 26 }
@@ -43,9 +33,9 @@
43 33
44 34 $max_slug_value = 2147483647;
45 35 // We want to have at least 2 characters in the slug.
46 36 $min_slug_value = 37;
47 - $key = base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 );
37 + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
48 38
49 39 $style = array(
50 40 'post_type' => FrmStylesController::$post_type,
51 41 'ID' => '',
@@ -60,9 +50,8 @@
60 50 }
61 51
62 52 /**
63 53 * @param array $settings
64 - *
65 54 * @return int|WP_Error
66 55 */
67 56 public function save( $settings ) {
68 57 return FrmDb::save_settings( $settings, 'frm_styles' );
@@ -68,10 +57,8 @@
68 57 return FrmDb::save_settings( $settings, 'frm_styles' );
69 58 }
70 59
71 60 /**
72 - * @param int|string $id The id of the stylesheet or 'default'.
73 - *
74 61 * @return void
75 62 */
76 63 public function duplicate( $id ) {
77 64 // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
@@ -80,17 +67,16 @@
80 67 /**
81 68 * Handle save actions in the visual styler edit page.
82 69 *
83 70 * @param mixed $id
84 - *
85 71 * @return array<int|WP_Error>
86 72 */
87 73 public function update( $id = 'default' ) {
88 - $all_instances = $this->get_all();
89 - $css_scope_helper = new FrmCssScopeHelper();
74 + $all_instances = $this->get_all();
90 75
91 76 if ( ! $id ) {
92 - $all_instances[] = (array) $this->get_new();
77 + $new_style = (array) $this->get_new();
78 + $all_instances[] = $new_style;
93 79 }
94 80
95 81 $action_ids = array();
96 82
@@ -97,10 +83,9 @@
97 83 foreach ( $all_instances as $new_instance ) {
98 84 $new_instance = (array) $new_instance;
99 85 $this->id = $new_instance['ID'];
100 86
101 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
102 - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
87 + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
103 88 // Don't continue if not saving this style.
104 89 continue;
105 90 }
106 91
@@ -105,9 +90,9 @@
105 90 }
106 91
107 92 // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing.
108 93 // 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'] ?? '';
94 + $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : '';
110 95
111 96 // phpcs:ignore WordPress.Security.NonceVerification.Missing
112 97 if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) {
113 98 // The nonce check happens in FrmStylesController::save_style before this is called.
@@ -114,9 +99,9 @@
114 99 // phpcs:ignore WordPress.Security.NonceVerification.Missing
115 100 $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) );
116 101 }
117 102
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
103 + $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 104 $new_instance['post_content']['custom_css'] = $custom_css;
120 105 unset( $custom_css );
121 106
122 107 $new_instance['post_type'] = FrmStylesController::$post_type;
@@ -122,20 +107,11 @@
122 107 $new_instance['post_type'] = FrmStylesController::$post_type;
123 108 $new_instance['post_status'] = 'publish';
124 109
125 110 if ( ! $id ) {
126 - // For a new style (including a duplicate), the post_name is derived from the title.
127 - // Resolve slug uniqueness up front (WordPress appends -2, -3, etc. to duplicate slugs)
128 - // so the CSS scope below matches the slug WordPress will actually store.
129 - $slug = sanitize_title( $new_instance['post_title'] );
130 - $new_instance['post_name'] = wp_unique_post_slug( $slug, 0, $new_instance['post_status'], $new_instance['post_type'], 0 );
111 + $new_instance['post_name'] = $new_instance['post_title'];
131 112 }
132 113
133 - if ( ! empty( $new_instance['post_content']['single_style_custom_css'] ) ) {
134 - $css_scope = 'frm_style_' . $new_instance['post_name'];
135 - $new_instance['post_content']['single_style_custom_css'] = $css_scope_helper->nest( $new_instance['post_content']['single_style_custom_css'], $css_scope );
136 - }
137 -
138 114 $default_settings = $this->get_defaults();
139 115
140 116 foreach ( $default_settings as $setting => $default ) {
141 117 if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
@@ -143,10 +119,9 @@
143 119 }
144 120
145 121 if ( $this->is_color( $setting ) ) {
146 122 $color_val = $new_instance['post_content'][ $setting ];
147 -
148 - if ( $color_val !== '' && str_contains( $color_val, 'rgb' ) ) {
123 + if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) {
149 124 // Maybe sanitize if invalid rgba value is entered.
150 125 $this->maybe_sanitize_rgba_value( $color_val );
151 126 }
152 127 $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val );
@@ -156,10 +131,9 @@
156 131 $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
157 132 }
158 133 }
159 134
160 - $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() );
161 - $action_ids[] = $this->save( $new_instance );
135 + $action_ids[] = $this->save( $new_instance );
162 136 }//end foreach
163 137
164 138 $this->save_settings();
165 139
@@ -171,12 +145,11 @@
171 145 *
172 146 * @since 5.3.2
173 147 *
174 148 * @param string $color_val The color value, by reference.
175 - *
176 149 * @return void
177 150 */
178 - private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
151 + private function maybe_sanitize_rgba_value( &$color_val ) {
179 152 if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) {
180 153 return;
181 154 }
182 155
@@ -183,9 +156,8 @@
183 156 $color_val = trim( $color_val );
184 157 // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
185 158 $color_val = ltrim( $color_val, '(' );
186 159 $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
187 -
188 160 foreach ( $patterns as $pattern ) {
189 161 if ( preg_match( $pattern, $color_val ) === 1 ) {
190 162 return;
191 163 }
@@ -205,9 +177,9 @@
205 177 foreach ( explode( ',', $color_rgba ) as $index => $value ) {
206 178 $new_value = null;
207 179 $value_is_empty_string = '' === trim( $value ) || '' === $value;
208 180
209 - if ( 3 === $length_of_color_codes || $index !== $length_of_color_codes - 1 ) {
181 + if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) {
210 182 // Insert a value for r, g, or b.
211 183 if ( $value < 0 ) {
212 184 $new_value = 0;
213 185 } elseif ( $value > 255 ) {
@@ -216,9 +188,9 @@
216 188 $new_value = 0;
217 189 } else {
218 190 $new_value = absint( $value );
219 191 }
220 - } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
192 + } else {
221 193 // Insert a value for alpha.
222 194 if ( $value_is_empty_string ) {
223 195 $new_value = 4 === $length_of_color_codes ? 1 : 0;
224 196 } elseif ( $value > 1 || $value < 0 ) {
@@ -227,14 +199,13 @@
227 199 $new_value = floatval( $value );
228 200 }
229 201 }//end if
230 202
231 - $new_color_values[] = $new_value;
203 + $new_color_values[] = null === $new_value ? $value : $new_value;
232 204 }//end foreach
233 205
234 206 // add more 0s and 1 (if alpha position) if needed.
235 207 $missing_values = $length_of_color_codes - count( $new_color_values );
236 -
237 208 if ( $missing_values > 1 ) {
238 209 $insert_values = array_fill( 0, $missing_values - 1, 0 );
239 210 $last_value = 4 === $length_of_color_codes ? 1 : 0;
240 211 array_push( $insert_values, $last_value );
@@ -240,9 +211,8 @@
240 211 array_push( $insert_values, $last_value );
241 212 } elseif ( $missing_values === 1 ) {
242 213 $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 );
243 214 }
244 -
245 215 if ( ! empty( $insert_values ) ) {
246 216 $new_color_values = array_merge( $new_color_values, $insert_values );
247 217 }
248 218
@@ -250,8 +220,9 @@
250 220 $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 );
251 221 // Limit the number of opening braces after rgb/rgba. There should only be one.
252 222 $prefix = rtrim( $prefix, '(' ) . '(';
253 223 $new_color = $prefix . $new_color . ')';
224 +
254 225 $color_val = $new_color;
255 226 }
256 227
257 228 /**
@@ -257,9 +228,8 @@
257 228 /**
258 229 * @since 5.0.13
259 230 *
260 231 * @param array $settings
261 - *
262 232 * @return array
263 233 */
264 234 public function sanitize_post_content( $settings ) {
265 235 $defaults = $this->get_defaults();
@@ -264,17 +234,19 @@
264 234 public function sanitize_post_content( $settings ) {
265 235 $defaults = $this->get_defaults();
266 236 $valid_keys = array_keys( $defaults );
267 237 $sanitized_settings = array();
268 -
269 238 foreach ( $valid_keys as $key ) {
270 - $sanitized_settings[ $key ] = isset( $settings[ $key ] ) ? sanitize_textarea_field( $settings[ $key ] ) : $defaults[ $key ];
239 + if ( isset( $settings[ $key ] ) ) {
240 + $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] );
241 + } else {
242 + $sanitized_settings[ $key ] = $defaults[ $key ];
243 + }
271 244
272 - if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) {
245 + if ( 'custom_css' !== $key ) {
273 246 $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
274 247 }
275 248 }
276 -
277 249 return $sanitized_settings;
278 250 }
279 251
280 252 /**
@@ -282,9 +254,8 @@
282 254 *
283 255 * @since 6.2.3
284 256 *
285 257 * @param string $setting
286 - *
287 258 * @return string
288 259 */
289 260 private function strip_invalid_characters( $setting ) {
290 261 $characters_to_remove = array( '{', '}', ';', '[', ']' );
@@ -289,9 +260,9 @@
289 260 private function strip_invalid_characters( $setting ) {
290 261 $characters_to_remove = array( '{', '}', ';', '[', ']' );
291 262
292 263 // RGB is handled instead in self::maybe_sanitize_rgba_value.
293 - if ( ! str_starts_with( $setting, 'rgb' ) ) {
264 + if ( 0 !== strpos( $setting, 'rgb' ) ) {
294 265 $setting = $this->maybe_fix_braces( $setting, $characters_to_remove );
295 266 }
296 267
297 268 return str_replace( $characters_to_remove, '', $setting );
@@ -301,9 +272,8 @@
301 272 * @since 6.2.3
302 273 *
303 274 * @param string $setting
304 275 * @param array $characters_to_remove
305 - *
306 276 * @return string
307 277 */
308 278 private function maybe_fix_braces( $setting, &$characters_to_remove ) {
309 279 $number_of_opening_braces = substr_count( $setting, '(' );
@@ -325,28 +295,23 @@
325 295 /**
326 296 * @since 6.2.3
327 297 *
328 298 * @param string $input
329 - *
330 299 * @return string
331 300 */
332 301 private function trim_braces( $input ) {
333 302 $output = $input;
334 -
335 303 // Remove any ( from the start of the string as no CSS values expect at the first character.
336 304 if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) {
337 305 $output = ltrim( $output, '()' );
338 306 }
339 -
340 307 // Remove extra braces from the end.
341 308 if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) {
342 309 $output = rtrim( $output, '()' );
343 -
344 - if ( str_contains( $output, '(' ) ) {
310 + if ( false !== strpos( $output, '(' ) ) {
345 311 $output .= ')';
346 312 }
347 313 }
348 -
349 314 return $output;
350 315 }
351 316
352 317 /**
@@ -352,13 +317,12 @@
352 317 /**
353 318 * @since 6.2.3
354 319 *
355 320 * @param string $setting
356 - *
357 321 * @return bool
358 322 */
359 323 private function should_remove_every_brace( $setting ) {
360 - if ( str_starts_with( trim( $setting, '()' ), 'calc' ) ) {
324 + if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) {
361 325 // Support calc() sizes. We do not want to remove all braces when calc is used.
362 326 return false;
363 327 }
364 328
@@ -363,9 +327,8 @@
363 327 }
364 328
365 329 // Matches hex values but also checks for unexpected ( and ).
366 330 $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting );
367 -
368 331 if ( $looks_like_a_hex_value ) {
369 332 return true;
370 333 }
371 334
@@ -371,9 +334,13 @@
371 334
372 335 // Matches size values but also checks for unexpected ( and ).
373 336 // This is case insensitive so it will catch PX, PT, etc, as well.
374 337 $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting );
375 - return (bool) $looks_like_a_size;
338 + if ( $looks_like_a_size ) {
339 + return true;
340 + }
341 +
342 + return false;
376 343 }
377 344
378 345 /**
379 346 * @since 3.01.01
@@ -378,17 +345,13 @@
378 345 /**
379 346 * @since 3.01.01
380 347 *
381 348 * @param string $setting
382 - *
383 349 * @return bool
384 350 */
385 351 private function is_color( $setting ) {
386 - if ( str_contains( $setting, 'color' ) ) {
387 - return true;
388 - }
389 -
390 - return in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ), true );
352 + $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
353 + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true );
391 354 }
392 355
393 356 /**
394 357 * @since 3.01.01
@@ -395,9 +358,11 @@
395 358 *
396 359 * @return array
397 360 */
398 361 public function get_color_settings() {
399 - $settings = array_keys( $this->get_defaults() );
362 + $defaults = $this->get_defaults();
363 + $settings = array_keys( $defaults );
364 +
400 365 return array_filter( $settings, array( $this, 'is_color' ) );
401 366 }
402 367
403 368 /**
@@ -415,95 +380,34 @@
415 380
416 381 $this->clear_cache();
417 382
418 383 $css = $this->get_css_content( $filename );
419 - $create_file = new FrmCreateFile( self::get_create_style_file_args() );
384 + $create_file = new FrmCreateFile(
385 + array(
386 + 'file_name' => FrmStylesController::get_file_name(),
387 + 'new_file_path' => FrmAppHelper::plugin_path() . '/css',
388 + )
389 + );
420 390 $create_file->create_file( $css );
421 391
422 - update_option( 'frmpro_css', $css, false );
392 + update_option( 'frmpro_css', $css, 'no' );
423 393 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
424 394 }
425 395
426 396 /**
427 - * @since 6.32
428 - *
429 - * @return array
430 - */
431 - private static function get_create_style_file_args() {
432 - $add_css_to_uploads_dir = self::add_css_to_uploads_dir();
433 - $create_file_args = array(
434 - 'file_name' => FrmStylesController::get_file_name(),
435 - 'new_file_path' => self::get_generated_css_file_path( $add_css_to_uploads_dir ),
436 - );
437 -
438 - if ( $add_css_to_uploads_dir ) {
439 - $create_file_args['folder_name'] = 'formidable/css';
440 - }
441 -
442 - return $create_file_args;
443 - }
444 -
445 - /**
446 - * @since 6.32
447 - *
448 - * @param bool $add_css_to_uploads_dir
449 - *
450 - * @return string
451 - */
452 - public static function get_generated_css_file_path( $add_css_to_uploads_dir ) {
453 - if ( $add_css_to_uploads_dir ) {
454 - return self::target_css_uploads_dir();
455 - }
456 - return self::target_css_plugin_dir();
457 - }
458 -
459 - /**
460 - * Returns true if generated css file should be saved in the uploads directory.
461 - *
462 - * @since 6.32
463 - *
464 - * @return bool
465 - */
466 - public static function add_css_to_uploads_dir() {
467 - /**
468 - * @since 6.32
469 - *
470 - * @param bool $add_css_to_uploads_dir
471 - */
472 - return apply_filters( 'frm_add_css_to_uploads_dir', ! wp_is_file_mod_allowed( 'frm_save_css_to_plugin_folder' ) );
473 - }
474 -
475 - /**
476 - * @since 6.32
477 - *
478 - * @return string
479 - */
480 - private static function target_css_uploads_dir() {
481 - return wp_upload_dir()['basedir'] . '/formidable/css';
482 - }
483 -
484 - /**
485 - * @since 6.32
486 - *
487 - * @return string
488 - */
489 - private static function target_css_plugin_dir() {
490 - return FrmAppHelper::plugin_path() . '/css';
491 - }
492 -
493 - /**
494 397 * @param string $filename
495 - *
496 398 * @return string
497 399 */
498 400 private function get_css_content( $filename ) {
499 - $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
401 + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
402 +
500 403 $saving = true;
501 404 $frm_style = $this;
502 405
503 406 ob_start();
504 407 include $filename;
505 - $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_clean() ) );
408 + $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
409 + ob_end_clean();
506 410
507 411 return FrmStylesController::replace_relative_url( $css );
508 412 }
509 413
@@ -527,9 +431,8 @@
527 431 /**
528 432 * Delete a style by its post ID.
529 433 *
530 434 * @param int $id
531 - *
532 435 * @return false|WP_Post|null
533 436 */
534 437 public function destroy( $id ) {
535 438 if ( $id === $this->get_default_style()->ID ) {
@@ -543,11 +446,14 @@
543 446 */
544 447 public function get_one() {
545 448 if ( 'default' === $this->id ) {
546 449 $style = $this->get_default_style();
450 + if ( $style ) {
451 + $this->id = $style->ID;
452 + } else {
453 + $this->id = 0;
454 + }
547 455
548 - $this->id = $style ? $style->ID : 0;
549 -
550 456 return $style;
551 457 }
552 458
553 459 $style = get_post( $this->id );
@@ -559,9 +465,9 @@
559 465 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
560 466
561 467 $default_values = $this->get_defaults();
562 468
563 - // Fill default values
469 + // fill default values
564 470 $style->post_content = $this->override_defaults( $style->post_content );
565 471 $style->post_content = wp_parse_args( $style->post_content, $default_values );
566 472
567 473 return $style;
@@ -570,9 +476,8 @@
570 476 /**
571 477 * @param string $orderby
572 478 * @param string $order
573 479 * @param int $limit
574 - *
575 480 * @return array
576 481 */
577 482 public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
578 483 $post_atts = array(
@@ -584,16 +489,16 @@
584 489 );
585 490
586 491 $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
587 492
588 - if ( ! $temp_styles ) {
493 + if ( empty( $temp_styles ) ) {
589 494 global $wpdb;
590 - // Make sure there wasn't a conflict with the query
591 - $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
495 + // make sure there wasn't a conflict with the query
496 + $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' );
592 497 $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
593 498
594 - if ( ! $temp_styles ) {
595 - // Create a new style if there are none
499 + if ( empty( $temp_styles ) ) {
500 + // create a new style if there are none
596 501 $new = $this->get_new();
597 502 $new->post_title = __( 'Formidable Style', 'formidable' );
598 503 $new->post_name = $new->post_title;
599 504 $new->menu_order = 1;
@@ -600,25 +505,25 @@
600 505 $new = $this->save( (array) $new );
601 506 $this->update( 'default' );
602 507
603 508 $post_atts['include'] = $new;
604 - $temp_styles = get_posts( $post_atts );
509 +
510 + $temp_styles = get_posts( $post_atts );
605 511 }
606 512 }
607 513
608 514 $default_values = $this->get_defaults();
609 515 $default_style = false;
610 - $styles = array();
611 516
517 + $styles = array();
612 518 foreach ( $temp_styles as $style ) {
613 519 $this->id = $style->ID;
614 -
615 520 if ( $style->menu_order ) {
616 521 if ( $default_style ) {
617 - // Only return one default
522 + // only return one default
618 523 $style->menu_order = 0;
619 524 } else {
620 - // Check for a default style
525 + // check for a default style
621 526 $default_style = $style->ID;
622 527 }
623 528 }
624 529
@@ -623,17 +528,18 @@
623 528 }
624 529
625 530 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
626 531
627 - // Fill default values
532 + // fill default values
628 533 $style->post_content = $this->override_defaults( $style->post_content );
629 534 $style->post_content = wp_parse_args( $style->post_content, $default_values );
630 535
631 536 $styles[ $style->ID ] = $style;
632 - }//end foreach
537 + }
633 538
634 539 if ( ! $default_style ) {
635 - $default_style = reset( $styles );
540 + $default_style = reset( $styles );
541 +
636 542 $styles[ $default_style->ID ]->menu_order = 1;
637 543 }
638 544
639 545 return $styles;
@@ -640,10 +546,8 @@
640 546 }
641 547
642 548 /**
643 549 * @param array|null $styles
644 - *
645 - * @return object|null
646 550 */
647 551 public function get_default_style( $styles = null ) {
648 552 if ( ! isset( $styles ) ) {
649 553 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
@@ -653,15 +557,12 @@
653 557 if ( $style->menu_order ) {
654 558 return $style;
655 559 }
656 560 }
657 -
658 - return null;
659 561 }
660 562
661 563 /**
662 564 * @param mixed $settings
663 - *
664 565 * @return mixed
665 566 */
666 567 public function override_defaults( $settings ) {
667 568 if ( ! is_array( $settings ) ) {
@@ -667,9 +568,9 @@
667 568 if ( ! is_array( $settings ) ) {
668 569 return $settings;
669 570 }
670 571
671 - $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
572 + $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height'];
672 573
673 574 if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
674 575 $settings['form_desc_size'] = $settings['description_font_size'];
675 576 $settings['form_desc_color'] = $settings['description_color'];
@@ -681,28 +582,14 @@
681 582 $settings['section_border_color'] = $settings['border_color'];
682 583 }
683 584
684 585 if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
685 - $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
686 - }
687 -
688 - if ( ! isset( $settings['submit_hover_color'] ) && isset( $settings['submit_text_color'] ) ) {
689 - $settings['submit_hover_color'] = $settings['submit_text_color'];
690 - }
691 -
692 - if ( ! isset( $settings['submit_hover_border_color'] ) && isset( $settings['submit_border_color'] ) ) {
586 + $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
587 + $settings['submit_hover_color'] = $settings['submit_text_color'];
693 588 $settings['submit_hover_border_color'] = $settings['submit_border_color'];
694 - }
695 589
696 - if ( ! isset( $settings['submit_active_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
697 - $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
698 - }
699 -
700 - if ( ! isset( $settings['submit_active_color'] ) && isset( $settings['submit_text_color'] ) ) {
701 - $settings['submit_active_color'] = $settings['submit_text_color'];
702 - }
703 -
704 - if ( ! isset( $settings['submit_active_border_color'] ) && isset( $settings['submit_border_color'] ) ) {
590 + $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
591 + $settings['submit_active_color'] = $settings['submit_text_color'];
705 592 $settings['submit_active_border_color'] = $settings['submit_border_color'];
706 593 }
707 594
708 595 return apply_filters( 'frm_override_default_styles', $settings );
@@ -721,9 +608,9 @@
721 608 'form_align' => 'left',
722 609 'direction' => is_rtl() ? 'rtl' : 'ltr',
723 610 'fieldset' => '0px',
724 611 'fieldset_color' => '000000',
725 - 'fieldset_padding' => '0px 0px 15px 0px',
612 + 'fieldset_padding' => '0 0 15px 0',
726 613 'fieldset_bg_color' => '',
727 614
728 615 'title_size' => '40px',
729 616 'title_color' => '444444',
@@ -732,9 +619,9 @@
732 619 'form_desc_size' => '14px',
733 620 'form_desc_color' => '98A2B3',
734 621 'form_desc_margin_top' => '10px',
735 622 'form_desc_margin_bottom' => '25px',
736 - 'form_desc_padding' => '0px',
623 + 'form_desc_padding' => '0',
737 624
738 625 'font' => '',
739 626 'font_size' => '15px',
740 627 'label_color' => '344054',
@@ -743,9 +630,9 @@
743 630 'align' => 'left',
744 631 'width' => '150px',
745 632 'required_color' => 'F04438',
746 633 'required_weight' => 'bold',
747 - 'label_padding' => '0px 0px 5px 0px',
634 + 'label_padding' => '0 0 5px 0',
748 635
749 636 'description_font_size' => '12px',
750 637 'description_color' => '667085',
751 638 'description_weight' => 'normal',
@@ -750,9 +637,9 @@
750 637 'description_color' => '667085',
751 638 'description_weight' => 'normal',
752 639 'description_style' => 'normal',
753 640 'description_align' => 'left',
754 - 'description_margin' => '0px',
641 + 'description_margin' => '0',
755 642
756 643 'field_font_size' => '14px',
757 644 'field_height' => '36px',
758 645 'line_height' => 'normal',
@@ -790,9 +677,9 @@
790 677
791 678 'section_font_size' => '18px',
792 679 'section_color' => '344054',
793 680 'section_weight' => 'bold',
794 - 'section_pad' => '32px 0px 3px 0px',
681 + 'section_pad' => '32px 0 3px 0',
795 682 'section_mar_top' => '30px',
796 683 'section_mar_bottom' => '30px',
797 684 'section_bg_color' => '',
798 685 'section_border_color' => 'EAECF0',
@@ -845,14 +732,8 @@
845 732 'progress_border_color' => 'EAECF0',
846 733 'progress_border_size' => '1px',
847 734 'progress_size' => '30px',
848 735 'custom_css' => '',
849 - 'use_base_font_size' => false,
850 - 'base_font_size' => '15px',
851 - 'field_shape_type' => 'rounded-corner',
852 -
853 - 'enable_style_custom_css' => false,
854 - 'single_style_custom_css' => '',
855 736 );
856 737
857 738 return apply_filters( 'frm_default_style_settings', $defaults );
858 739 }
@@ -861,13 +742,12 @@
861 742 * Get a name attribute value for a style setting input.
862 743 *
863 744 * @param string $field_name
864 745 * @param string $post_field
865 - *
866 746 * @return string
867 747 */
868 748 public function get_field_name( $field_name, $post_field = 'post_content' ) {
869 - return 'frm_style_setting' . ( $post_field ? '[' . $post_field . ']' : '' ) . '[' . $field_name . ']';
749 + return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
870 750 }
871 751
872 752 /**
873 753 * @return array
@@ -873,17 +753,17 @@
873 753 * @return array
874 754 */
875 755 public static function get_bold_options() {
876 756 return array(
877 - 100 => __( 'Thin', 'formidable' ),
878 - 200 => __( 'Extra Light', 'formidable' ),
879 - 300 => __( 'Light', 'formidable' ),
880 - 'normal' => __( 'Regular', 'formidable' ),
881 - 500 => __( 'Medium', 'formidable' ),
882 - 600 => __( 'Semi Bold', 'formidable' ),
883 - 'bold' => __( 'Bold', 'formidable' ),
884 - 800 => __( 'Extra Bold', 'formidable' ),
885 - 900 => __( 'Black', 'formidable' ),
757 + 100 => 100,
758 + 200 => 200,
759 + 300 => 300,
760 + 'normal' => __( 'normal', 'formidable' ),
761 + 500 => 500,
762 + 600 => 600,
763 + 'bold' => __( 'bold', 'formidable' ),
764 + 800 => 800,
765 + 900 => 900,
886 766 );
887 767 }
888 768
889 769 /**
@@ -889,17 +769,15 @@
889 769 /**
890 770 * Don't let imbalanced font families ruin the whole stylesheet.
891 771 *
892 772 * @param string $value
893 - *
894 773 * @return string
895 774 */
896 775 public function force_balanced_quotation( $value ) {
897 776 $balanced_characters = array( '"', "'" );
898 -
899 777 foreach ( $balanced_characters as $char ) {
900 778 $char_count = substr_count( $value, $char );
901 - $is_balanced = $char_count % 2 === 0;
779 + $is_balanced = $char_count % 2 == 0;
902 780
903 781 if ( $is_balanced ) {
904 782 continue;
905 783 }
@@ -909,27 +787,7 @@
909 787 } else {
910 788 $value .= $char;
911 789 }
912 790 }
913 -
914 791 return $value;
915 - }
916 -
917 - /**
918 - * Get the default template style
919 - *
920 - * @since 6.14
921 - *
922 - * @param int|string $style_id The post type "frm_styles" ID.
923 - *
924 - * @return string The json encoded template data
925 - */
926 - public function get_default_template_style( $style_id ) {
927 - $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true );
928 -
929 - if ( ! $default_template ) {
930 - return FrmAppHelper::prepare_and_encode( $this->get_defaults() );
931 - }
932 -
933 - return $default_template;
934 792 }
935 793 }