PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
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 +64 -96 6.306.24 View file →
@@ -8,9 +8,8 @@
8 8 /**
9 9 * The meta name of default template style.
10 10 *
11 11 * @since 6.14
12 - *
13 12 * @var string
14 13 */
15 14 private $default_template_style_meta_name = 'frm_style_default';
16 15
@@ -43,9 +42,9 @@
43 42
44 43 $max_slug_value = 2147483647;
45 44 // We want to have at least 2 characters in the slug.
46 45 $min_slug_value = 37;
47 - $key = base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 );
46 + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
48 47
49 48 $style = array(
50 49 'post_type' => FrmStylesController::$post_type,
51 50 'ID' => '',
@@ -60,9 +59,8 @@
60 59 }
61 60
62 61 /**
63 62 * @param array $settings
64 - *
65 63 * @return int|WP_Error
66 64 */
67 65 public function save( $settings ) {
68 66 return FrmDb::save_settings( $settings, 'frm_styles' );
@@ -68,10 +66,8 @@
68 66 return FrmDb::save_settings( $settings, 'frm_styles' );
69 67 }
70 68
71 69 /**
72 - * @param int|string $id The id of the stylesheet or 'default'.
73 - *
74 70 * @return void
75 71 */
76 72 public function duplicate( $id ) {
77 73 // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
@@ -80,17 +76,16 @@
80 76 /**
81 77 * Handle save actions in the visual styler edit page.
82 78 *
83 79 * @param mixed $id
84 - *
85 80 * @return array<int|WP_Error>
86 81 */
87 82 public function update( $id = 'default' ) {
88 - $all_instances = $this->get_all();
89 - $css_scope_helper = new FrmCssScopeHelper();
83 + $all_instances = $this->get_all();
90 84
91 85 if ( ! $id ) {
92 - $all_instances[] = (array) $this->get_new();
86 + $new_style = (array) $this->get_new();
87 + $all_instances[] = $new_style;
93 88 }
94 89
95 90 $action_ids = array();
96 91
@@ -97,10 +92,9 @@
97 92 foreach ( $all_instances as $new_instance ) {
98 93 $new_instance = (array) $new_instance;
99 94 $this->id = $new_instance['ID'];
100 95
101 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
102 - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
96 + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
103 97 // Don't continue if not saving this style.
104 98 continue;
105 99 }
106 100
@@ -105,9 +99,9 @@
105 99 }
106 100
107 101 // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing.
108 102 // 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'] ?? '';
103 + $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : '';
110 104
111 105 // phpcs:ignore WordPress.Security.NonceVerification.Missing
112 106 if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) {
113 107 // The nonce check happens in FrmStylesController::save_style before this is called.
@@ -114,17 +108,12 @@
114 108 // phpcs:ignore WordPress.Security.NonceVerification.Missing
115 109 $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) );
116 110 }
117 111
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
112 + $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 113 $new_instance['post_content']['custom_css'] = $custom_css;
120 114 unset( $custom_css );
121 115
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 - }
126 -
127 116 $new_instance['post_type'] = FrmStylesController::$post_type;
128 117 $new_instance['post_status'] = 'publish';
129 118
130 119 if ( ! $id ) {
@@ -139,10 +128,9 @@
139 128 }
140 129
141 130 if ( $this->is_color( $setting ) ) {
142 131 $color_val = $new_instance['post_content'][ $setting ];
143 -
144 - if ( $color_val !== '' && str_contains( $color_val, 'rgb' ) ) {
132 + if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) {
145 133 // Maybe sanitize if invalid rgba value is entered.
146 134 $this->maybe_sanitize_rgba_value( $color_val );
147 135 }
148 136 $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val );
@@ -153,9 +141,10 @@
153 141 }
154 142 }
155 143
156 144 $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() );
157 - $action_ids[] = $this->save( $new_instance );
145 +
146 + $action_ids[] = $this->save( $new_instance );
158 147 }//end foreach
159 148
160 149 $this->save_settings();
161 150
@@ -167,12 +156,11 @@
167 156 *
168 157 * @since 5.3.2
169 158 *
170 159 * @param string $color_val The color value, by reference.
171 - *
172 160 * @return void
173 161 */
174 - private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
162 + private function maybe_sanitize_rgba_value( &$color_val ) {
175 163 if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) {
176 164 return;
177 165 }
178 166
@@ -179,9 +167,8 @@
179 167 $color_val = trim( $color_val );
180 168 // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
181 169 $color_val = ltrim( $color_val, '(' );
182 170 $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
183 -
184 171 foreach ( $patterns as $pattern ) {
185 172 if ( preg_match( $pattern, $color_val ) === 1 ) {
186 173 return;
187 174 }
@@ -201,9 +188,9 @@
201 188 foreach ( explode( ',', $color_rgba ) as $index => $value ) {
202 189 $new_value = null;
203 190 $value_is_empty_string = '' === trim( $value ) || '' === $value;
204 191
205 - if ( 3 === $length_of_color_codes || $index !== $length_of_color_codes - 1 ) {
192 + if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) {
206 193 // Insert a value for r, g, or b.
207 194 if ( $value < 0 ) {
208 195 $new_value = 0;
209 196 } elseif ( $value > 255 ) {
@@ -212,9 +199,9 @@
212 199 $new_value = 0;
213 200 } else {
214 201 $new_value = absint( $value );
215 202 }
216 - } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
203 + } else {
217 204 // Insert a value for alpha.
218 205 if ( $value_is_empty_string ) {
219 206 $new_value = 4 === $length_of_color_codes ? 1 : 0;
220 207 } elseif ( $value > 1 || $value < 0 ) {
@@ -223,14 +210,13 @@
223 210 $new_value = floatval( $value );
224 211 }
225 212 }//end if
226 213
227 - $new_color_values[] = $new_value;
214 + $new_color_values[] = null === $new_value ? $value : $new_value;
228 215 }//end foreach
229 216
230 217 // add more 0s and 1 (if alpha position) if needed.
231 218 $missing_values = $length_of_color_codes - count( $new_color_values );
232 -
233 219 if ( $missing_values > 1 ) {
234 220 $insert_values = array_fill( 0, $missing_values - 1, 0 );
235 221 $last_value = 4 === $length_of_color_codes ? 1 : 0;
236 222 array_push( $insert_values, $last_value );
@@ -236,9 +222,8 @@
236 222 array_push( $insert_values, $last_value );
237 223 } elseif ( $missing_values === 1 ) {
238 224 $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 );
239 225 }
240 -
241 226 if ( ! empty( $insert_values ) ) {
242 227 $new_color_values = array_merge( $new_color_values, $insert_values );
243 228 }
244 229
@@ -246,8 +231,9 @@
246 231 $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 );
247 232 // Limit the number of opening braces after rgb/rgba. There should only be one.
248 233 $prefix = rtrim( $prefix, '(' ) . '(';
249 234 $new_color = $prefix . $new_color . ')';
235 +
250 236 $color_val = $new_color;
251 237 }
252 238
253 239 /**
@@ -253,9 +239,8 @@
253 239 /**
254 240 * @since 5.0.13
255 241 *
256 242 * @param array $settings
257 - *
258 243 * @return array
259 244 */
260 245 public function sanitize_post_content( $settings ) {
261 246 $defaults = $this->get_defaults();
@@ -260,17 +245,19 @@
260 245 public function sanitize_post_content( $settings ) {
261 246 $defaults = $this->get_defaults();
262 247 $valid_keys = array_keys( $defaults );
263 248 $sanitized_settings = array();
264 -
265 249 foreach ( $valid_keys as $key ) {
266 - $sanitized_settings[ $key ] = isset( $settings[ $key ] ) ? sanitize_textarea_field( $settings[ $key ] ) : $defaults[ $key ];
250 + if ( isset( $settings[ $key ] ) ) {
251 + $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] );
252 + } else {
253 + $sanitized_settings[ $key ] = $defaults[ $key ];
254 + }
267 255
268 - if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) {
256 + if ( 'custom_css' !== $key ) {
269 257 $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
270 258 }
271 259 }
272 -
273 260 return $sanitized_settings;
274 261 }
275 262
276 263 /**
@@ -278,9 +265,8 @@
278 265 *
279 266 * @since 6.2.3
280 267 *
281 268 * @param string $setting
282 - *
283 269 * @return string
284 270 */
285 271 private function strip_invalid_characters( $setting ) {
286 272 $characters_to_remove = array( '{', '}', ';', '[', ']' );
@@ -285,9 +271,9 @@
285 271 private function strip_invalid_characters( $setting ) {
286 272 $characters_to_remove = array( '{', '}', ';', '[', ']' );
287 273
288 274 // RGB is handled instead in self::maybe_sanitize_rgba_value.
289 - if ( ! str_starts_with( $setting, 'rgb' ) ) {
275 + if ( 0 !== strpos( $setting, 'rgb' ) ) {
290 276 $setting = $this->maybe_fix_braces( $setting, $characters_to_remove );
291 277 }
292 278
293 279 return str_replace( $characters_to_remove, '', $setting );
@@ -297,9 +283,8 @@
297 283 * @since 6.2.3
298 284 *
299 285 * @param string $setting
300 286 * @param array $characters_to_remove
301 - *
302 287 * @return string
303 288 */
304 289 private function maybe_fix_braces( $setting, &$characters_to_remove ) {
305 290 $number_of_opening_braces = substr_count( $setting, '(' );
@@ -321,28 +306,23 @@
321 306 /**
322 307 * @since 6.2.3
323 308 *
324 309 * @param string $input
325 - *
326 310 * @return string
327 311 */
328 312 private function trim_braces( $input ) {
329 313 $output = $input;
330 -
331 314 // Remove any ( from the start of the string as no CSS values expect at the first character.
332 315 if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) {
333 316 $output = ltrim( $output, '()' );
334 317 }
335 -
336 318 // Remove extra braces from the end.
337 319 if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) {
338 320 $output = rtrim( $output, '()' );
339 -
340 - if ( str_contains( $output, '(' ) ) {
321 + if ( false !== strpos( $output, '(' ) ) {
341 322 $output .= ')';
342 323 }
343 324 }
344 -
345 325 return $output;
346 326 }
347 327
348 328 /**
@@ -348,13 +328,12 @@
348 328 /**
349 329 * @since 6.2.3
350 330 *
351 331 * @param string $setting
352 - *
353 332 * @return bool
354 333 */
355 334 private function should_remove_every_brace( $setting ) {
356 - if ( str_starts_with( trim( $setting, '()' ), 'calc' ) ) {
335 + if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) {
357 336 // Support calc() sizes. We do not want to remove all braces when calc is used.
358 337 return false;
359 338 }
360 339
@@ -359,9 +338,8 @@
359 338 }
360 339
361 340 // Matches hex values but also checks for unexpected ( and ).
362 341 $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting );
363 -
364 342 if ( $looks_like_a_hex_value ) {
365 343 return true;
366 344 }
367 345
@@ -367,9 +345,13 @@
367 345
368 346 // Matches size values but also checks for unexpected ( and ).
369 347 // This is case insensitive so it will catch PX, PT, etc, as well.
370 348 $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;
349 + if ( $looks_like_a_size ) {
350 + return true;
351 + }
352 +
353 + return false;
372 354 }
373 355
374 356 /**
375 357 * @since 3.01.01
@@ -374,17 +356,13 @@
374 356 /**
375 357 * @since 3.01.01
376 358 *
377 359 * @param string $setting
378 - *
379 360 * @return bool
380 361 */
381 362 private function is_color( $setting ) {
382 - if ( str_contains( $setting, 'color' ) ) {
383 - return true;
384 - }
385 -
386 - return in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ), true );
363 + $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
364 + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true );
387 365 }
388 366
389 367 /**
390 368 * @since 3.01.01
@@ -391,9 +369,11 @@
391 369 *
392 370 * @return array
393 371 */
394 372 public function get_color_settings() {
395 - $settings = array_keys( $this->get_defaults() );
373 + $defaults = $this->get_defaults();
374 + $settings = array_keys( $defaults );
375 +
396 376 return array_filter( $settings, array( $this, 'is_color' ) );
397 377 }
398 378
399 379 /**
@@ -419,25 +399,26 @@
419 399 )
420 400 );
421 401 $create_file->create_file( $css );
422 402
423 - update_option( 'frmpro_css', $css, false );
403 + update_option( 'frmpro_css', $css, 'no' );
424 404 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
425 405 }
426 406
427 407 /**
428 408 * @param string $filename
429 - *
430 409 * @return string
431 410 */
432 411 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";
412 + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
413 +
434 414 $saving = true;
435 415 $frm_style = $this;
436 416
437 417 ob_start();
438 418 include $filename;
439 - $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_clean() ) );
419 + $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
420 + ob_end_clean();
440 421
441 422 return FrmStylesController::replace_relative_url( $css );
442 423 }
443 424
@@ -461,9 +442,8 @@
461 442 /**
462 443 * Delete a style by its post ID.
463 444 *
464 445 * @param int $id
465 - *
466 446 * @return false|WP_Post|null
467 447 */
468 448 public function destroy( $id ) {
469 449 if ( $id === $this->get_default_style()->ID ) {
@@ -477,11 +457,14 @@
477 457 */
478 458 public function get_one() {
479 459 if ( 'default' === $this->id ) {
480 460 $style = $this->get_default_style();
461 + if ( $style ) {
462 + $this->id = $style->ID;
463 + } else {
464 + $this->id = 0;
465 + }
481 466
482 - $this->id = $style ? $style->ID : 0;
483 -
484 467 return $style;
485 468 }
486 469
487 470 $style = get_post( $this->id );
@@ -493,9 +476,9 @@
493 476 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
494 477
495 478 $default_values = $this->get_defaults();
496 479
497 - // Fill default values
480 + // fill default values
498 481 $style->post_content = $this->override_defaults( $style->post_content );
499 482 $style->post_content = wp_parse_args( $style->post_content, $default_values );
500 483
501 484 return $style;
@@ -504,9 +487,8 @@
504 487 /**
505 488 * @param string $orderby
506 489 * @param string $order
507 490 * @param int $limit
508 - *
509 491 * @return array
510 492 */
511 493 public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
512 494 $post_atts = array(
@@ -518,16 +500,16 @@
518 500 );
519 501
520 502 $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
521 503
522 - if ( ! $temp_styles ) {
504 + if ( empty( $temp_styles ) ) {
523 505 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
506 + // make sure there wasn't a conflict with the query
507 + $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 508 $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
527 509
528 - if ( ! $temp_styles ) {
529 - // Create a new style if there are none
510 + if ( empty( $temp_styles ) ) {
511 + // create a new style if there are none
530 512 $new = $this->get_new();
531 513 $new->post_title = __( 'Formidable Style', 'formidable' );
532 514 $new->post_name = $new->post_title;
533 515 $new->menu_order = 1;
@@ -534,25 +516,25 @@
534 516 $new = $this->save( (array) $new );
535 517 $this->update( 'default' );
536 518
537 519 $post_atts['include'] = $new;
538 - $temp_styles = get_posts( $post_atts );
520 +
521 + $temp_styles = get_posts( $post_atts );
539 522 }
540 523 }
541 524
542 525 $default_values = $this->get_defaults();
543 526 $default_style = false;
544 - $styles = array();
545 527
528 + $styles = array();
546 529 foreach ( $temp_styles as $style ) {
547 530 $this->id = $style->ID;
548 -
549 531 if ( $style->menu_order ) {
550 532 if ( $default_style ) {
551 - // Only return one default
533 + // only return one default
552 534 $style->menu_order = 0;
553 535 } else {
554 - // Check for a default style
536 + // check for a default style
555 537 $default_style = $style->ID;
556 538 }
557 539 }
558 540
@@ -557,17 +539,18 @@
557 539 }
558 540
559 541 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
560 542
561 - // Fill default values
543 + // fill default values
562 544 $style->post_content = $this->override_defaults( $style->post_content );
563 545 $style->post_content = wp_parse_args( $style->post_content, $default_values );
564 546
565 547 $styles[ $style->ID ] = $style;
566 - }//end foreach
548 + }
567 549
568 550 if ( ! $default_style ) {
569 - $default_style = reset( $styles );
551 + $default_style = reset( $styles );
552 +
570 553 $styles[ $default_style->ID ]->menu_order = 1;
571 554 }
572 555
573 556 return $styles;
@@ -574,10 +557,8 @@
574 557 }
575 558
576 559 /**
577 560 * @param array|null $styles
578 - *
579 - * @return object|null
580 561 */
581 562 public function get_default_style( $styles = null ) {
582 563 if ( ! isset( $styles ) ) {
583 564 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
@@ -587,15 +568,12 @@
587 568 if ( $style->menu_order ) {
588 569 return $style;
589 570 }
590 571 }
591 -
592 - return null;
593 572 }
594 573
595 574 /**
596 575 * @param mixed $settings
597 - *
598 576 * @return mixed
599 577 */
600 578 public function override_defaults( $settings ) {
601 579 if ( ! is_array( $settings ) ) {
@@ -601,9 +579,9 @@
601 579 if ( ! is_array( $settings ) ) {
602 580 return $settings;
603 581 }
604 582
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
583 + $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height'];
606 584
607 585 if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
608 586 $settings['form_desc_size'] = $settings['description_font_size'];
609 587 $settings['form_desc_color'] = $settings['description_color'];
@@ -768,11 +746,8 @@
768 746 'custom_css' => '',
769 747 'use_base_font_size' => false,
770 748 'base_font_size' => '15px',
771 749 'field_shape_type' => 'rounded-corner',
772 -
773 - 'enable_style_custom_css' => false,
774 - 'single_style_custom_css' => '',
775 750 );
776 751
777 752 return apply_filters( 'frm_default_style_settings', $defaults );
778 753 }
@@ -781,13 +756,12 @@
781 756 * Get a name attribute value for a style setting input.
782 757 *
783 758 * @param string $field_name
784 759 * @param string $post_field
785 - *
786 760 * @return string
787 761 */
788 762 public function get_field_name( $field_name, $post_field = 'post_content' ) {
789 - return 'frm_style_setting' . ( $post_field ? '[' . $post_field . ']' : '' ) . '[' . $field_name . ']';
763 + return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
790 764 }
791 765
792 766 /**
793 767 * @return array
@@ -809,17 +783,15 @@
809 783 /**
810 784 * Don't let imbalanced font families ruin the whole stylesheet.
811 785 *
812 786 * @param string $value
813 - *
814 787 * @return string
815 788 */
816 789 public function force_balanced_quotation( $value ) {
817 790 $balanced_characters = array( '"', "'" );
818 -
819 791 foreach ( $balanced_characters as $char ) {
820 792 $char_count = substr_count( $value, $char );
821 - $is_balanced = $char_count % 2 === 0;
793 + $is_balanced = $char_count % 2 == 0;
822 794
823 795 if ( $is_balanced ) {
824 796 continue;
825 797 }
@@ -829,9 +801,8 @@
829 801 } else {
830 802 $value .= $char;
831 803 }
832 804 }
833 -
834 805 return $value;
835 806 }
836 807
837 808 /**
@@ -837,19 +808,16 @@
837 808 /**
838 809 * Get the default template style
839 810 *
840 811 * @since 6.14
812 + * @param int $style_id The post type "frm_styles" ID.
841 813 *
842 - * @param int|string $style_id The post type "frm_styles" ID.
843 - *
844 814 * @return string The json encoded template data
845 815 */
846 816 public function get_default_template_style( $style_id ) {
847 817 $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true );
848 -
849 - if ( ! $default_template ) {
818 + if ( empty( $default_template ) ) {
850 819 return FrmAppHelper::prepare_and_encode( $this->get_defaults() );
851 820 }
852 -
853 821 return $default_template;
854 822 }
855 823 }