PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +184 -72 6.25.1 → trunk View file →
@@ -8,8 +8,9 @@
8 8 /**
9 9 * The meta name of default template style.
10 10 *
11 11 * @since 6.14
12 + *
12 13 * @var string
13 14 */
14 15 private $default_template_style_meta_name = 'frm_style_default';
15 16
@@ -59,8 +60,9 @@
59 60 }
60 61
61 62 /**
62 63 * @param array $settings
64 + *
63 65 * @return int|WP_Error
64 66 */
65 67 public function save( $settings ) {
66 68 return FrmDb::save_settings( $settings, 'frm_styles' );
@@ -66,8 +68,10 @@
66 68 return FrmDb::save_settings( $settings, 'frm_styles' );
67 69 }
68 70
69 71 /**
72 + * @param int|string $id The id of the stylesheet or 'default'.
73 + *
70 74 * @return void
71 75 */
72 76 public function duplicate( $id ) {
73 77 // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
@@ -76,16 +80,17 @@
76 80 /**
77 81 * Handle save actions in the visual styler edit page.
78 82 *
79 83 * @param mixed $id
84 + *
80 85 * @return array<int|WP_Error>
81 86 */
82 87 public function update( $id = 'default' ) {
83 - $all_instances = $this->get_all();
88 + $all_instances = $this->get_all();
89 + $css_scope_helper = new FrmCssScopeHelper();
84 90
85 91 if ( ! $id ) {
86 - $new_style = (array) $this->get_new();
87 - $all_instances[] = $new_style;
92 + $all_instances[] = (array) $this->get_new();
88 93 }
89 94
90 95 $action_ids = array();
91 96
@@ -92,9 +97,10 @@
92 97 foreach ( $all_instances as $new_instance ) {
93 98 $new_instance = (array) $new_instance;
94 99 $this->id = $new_instance['ID'];
95 100
96 - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
101 + // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
102 + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
97 103 // Don't continue if not saving this style.
98 104 continue;
99 105 }
100 106
@@ -108,9 +114,9 @@
108 114 // phpcs:ignore WordPress.Security.NonceVerification.Missing
109 115 $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) );
110 116 }
111 117
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
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
113 119 $new_instance['post_content']['custom_css'] = $custom_css;
114 120 unset( $custom_css );
115 121
116 122 $new_instance['post_type'] = FrmStylesController::$post_type;
@@ -116,11 +122,20 @@
116 122 $new_instance['post_type'] = FrmStylesController::$post_type;
117 123 $new_instance['post_status'] = 'publish';
118 124
119 125 if ( ! $id ) {
120 - $new_instance['post_name'] = $new_instance['post_title'];
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 );
121 131 }
122 132
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 +
123 138 $default_settings = $this->get_defaults();
124 139
125 140 foreach ( $default_settings as $setting => $default ) {
126 141 if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
@@ -128,9 +143,10 @@
128 143 }
129 144
130 145 if ( $this->is_color( $setting ) ) {
131 146 $color_val = $new_instance['post_content'][ $setting ];
132 - if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) {
147 +
148 + if ( $color_val !== '' && str_contains( $color_val, 'rgb' ) ) {
133 149 // Maybe sanitize if invalid rgba value is entered.
134 150 $this->maybe_sanitize_rgba_value( $color_val );
135 151 }
136 152 $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val );
@@ -141,10 +157,9 @@
141 157 }
142 158 }
143 159
144 160 $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() );
145 -
146 - $action_ids[] = $this->save( $new_instance );
161 + $action_ids[] = $this->save( $new_instance );
147 162 }//end foreach
148 163
149 164 $this->save_settings();
150 165
@@ -156,11 +171,12 @@
156 171 *
157 172 * @since 5.3.2
158 173 *
159 174 * @param string $color_val The color value, by reference.
175 + *
160 176 * @return void
161 177 */
162 - private function maybe_sanitize_rgba_value( &$color_val ) {
178 + private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
163 179 if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) {
164 180 return;
165 181 }
166 182
@@ -167,8 +183,9 @@
167 183 $color_val = trim( $color_val );
168 184 // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
169 185 $color_val = ltrim( $color_val, '(' );
170 186 $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
187 +
171 188 foreach ( $patterns as $pattern ) {
172 189 if ( preg_match( $pattern, $color_val ) === 1 ) {
173 190 return;
174 191 }
@@ -188,9 +205,9 @@
188 205 foreach ( explode( ',', $color_rgba ) as $index => $value ) {
189 206 $new_value = null;
190 207 $value_is_empty_string = '' === trim( $value ) || '' === $value;
191 208
192 - if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) {
209 + if ( 3 === $length_of_color_codes || $index !== $length_of_color_codes - 1 ) {
193 210 // Insert a value for r, g, or b.
194 211 if ( $value < 0 ) {
195 212 $new_value = 0;
196 213 } elseif ( $value > 255 ) {
@@ -199,9 +216,9 @@
199 216 $new_value = 0;
200 217 } else {
201 218 $new_value = absint( $value );
202 219 }
203 - } else {
220 + } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
204 221 // Insert a value for alpha.
205 222 if ( $value_is_empty_string ) {
206 223 $new_value = 4 === $length_of_color_codes ? 1 : 0;
207 224 } elseif ( $value > 1 || $value < 0 ) {
@@ -215,8 +232,9 @@
215 232 }//end foreach
216 233
217 234 // add more 0s and 1 (if alpha position) if needed.
218 235 $missing_values = $length_of_color_codes - count( $new_color_values );
236 +
219 237 if ( $missing_values > 1 ) {
220 238 $insert_values = array_fill( 0, $missing_values - 1, 0 );
221 239 $last_value = 4 === $length_of_color_codes ? 1 : 0;
222 240 array_push( $insert_values, $last_value );
@@ -222,8 +240,9 @@
222 240 array_push( $insert_values, $last_value );
223 241 } elseif ( $missing_values === 1 ) {
224 242 $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 );
225 243 }
244 +
226 245 if ( ! empty( $insert_values ) ) {
227 246 $new_color_values = array_merge( $new_color_values, $insert_values );
228 247 }
229 248
@@ -231,9 +250,8 @@
231 250 $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 );
232 251 // Limit the number of opening braces after rgb/rgba. There should only be one.
233 252 $prefix = rtrim( $prefix, '(' ) . '(';
234 253 $new_color = $prefix . $new_color . ')';
235 -
236 254 $color_val = $new_color;
237 255 }
238 256
239 257 /**
@@ -239,8 +257,9 @@
239 257 /**
240 258 * @since 5.0.13
241 259 *
242 260 * @param array $settings
261 + *
243 262 * @return array
244 263 */
245 264 public function sanitize_post_content( $settings ) {
246 265 $defaults = $this->get_defaults();
@@ -245,19 +264,17 @@
245 264 public function sanitize_post_content( $settings ) {
246 265 $defaults = $this->get_defaults();
247 266 $valid_keys = array_keys( $defaults );
248 267 $sanitized_settings = array();
268 +
249 269 foreach ( $valid_keys as $key ) {
250 - if ( isset( $settings[ $key ] ) ) {
251 - $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] );
252 - } else {
253 - $sanitized_settings[ $key ] = $defaults[ $key ];
254 - }
270 + $sanitized_settings[ $key ] = isset( $settings[ $key ] ) ? sanitize_textarea_field( $settings[ $key ] ) : $defaults[ $key ];
255 271
256 - if ( 'custom_css' !== $key ) {
272 + if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) {
257 273 $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
258 274 }
259 275 }
276 +
260 277 return $sanitized_settings;
261 278 }
262 279
263 280 /**
@@ -265,8 +282,9 @@
265 282 *
266 283 * @since 6.2.3
267 284 *
268 285 * @param string $setting
286 + *
269 287 * @return string
270 288 */
271 289 private function strip_invalid_characters( $setting ) {
272 290 $characters_to_remove = array( '{', '}', ';', '[', ']' );
@@ -271,9 +289,9 @@
271 289 private function strip_invalid_characters( $setting ) {
272 290 $characters_to_remove = array( '{', '}', ';', '[', ']' );
273 291
274 292 // RGB is handled instead in self::maybe_sanitize_rgba_value.
275 - if ( 0 !== strpos( $setting, 'rgb' ) ) {
293 + if ( ! str_starts_with( $setting, 'rgb' ) ) {
276 294 $setting = $this->maybe_fix_braces( $setting, $characters_to_remove );
277 295 }
278 296
279 297 return str_replace( $characters_to_remove, '', $setting );
@@ -283,8 +301,9 @@
283 301 * @since 6.2.3
284 302 *
285 303 * @param string $setting
286 304 * @param array $characters_to_remove
305 + *
287 306 * @return string
288 307 */
289 308 private function maybe_fix_braces( $setting, &$characters_to_remove ) {
290 309 $number_of_opening_braces = substr_count( $setting, '(' );
@@ -306,23 +325,28 @@
306 325 /**
307 326 * @since 6.2.3
308 327 *
309 328 * @param string $input
329 + *
310 330 * @return string
311 331 */
312 332 private function trim_braces( $input ) {
313 333 $output = $input;
334 +
314 335 // Remove any ( from the start of the string as no CSS values expect at the first character.
315 336 if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) {
316 337 $output = ltrim( $output, '()' );
317 338 }
339 +
318 340 // Remove extra braces from the end.
319 341 if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) {
320 342 $output = rtrim( $output, '()' );
321 - if ( false !== strpos( $output, '(' ) ) {
343 +
344 + if ( str_contains( $output, '(' ) ) {
322 345 $output .= ')';
323 346 }
324 347 }
348 +
325 349 return $output;
326 350 }
327 351
328 352 /**
@@ -328,12 +352,13 @@
328 352 /**
329 353 * @since 6.2.3
330 354 *
331 355 * @param string $setting
356 + *
332 357 * @return bool
333 358 */
334 359 private function should_remove_every_brace( $setting ) {
335 - if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) {
360 + if ( str_starts_with( trim( $setting, '()' ), 'calc' ) ) {
336 361 // Support calc() sizes. We do not want to remove all braces when calc is used.
337 362 return false;
338 363 }
339 364
@@ -338,8 +363,9 @@
338 363 }
339 364
340 365 // Matches hex values but also checks for unexpected ( and ).
341 366 $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting );
367 +
342 368 if ( $looks_like_a_hex_value ) {
343 369 return true;
344 370 }
345 371
@@ -345,13 +371,9 @@
345 371
346 372 // Matches size values but also checks for unexpected ( and ).
347 373 // This is case insensitive so it will catch PX, PT, etc, as well.
348 374 $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting );
349 - if ( $looks_like_a_size ) {
350 - return true;
351 - }
352 -
353 - return false;
375 + return (bool) $looks_like_a_size;
354 376 }
355 377
356 378 /**
357 379 * @since 3.01.01
@@ -356,13 +378,17 @@
356 378 /**
357 379 * @since 3.01.01
358 380 *
359 381 * @param string $setting
382 + *
360 383 * @return bool
361 384 */
362 385 private function is_color( $setting ) {
363 - $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
364 - return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true );
386 + if ( str_contains( $setting, 'color' ) ) {
387 + return true;
388 + }
389 +
390 + return in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ), true );
365 391 }
366 392
367 393 /**
368 394 * @since 3.01.01
@@ -369,11 +395,9 @@
369 395 *
370 396 * @return array
371 397 */
372 398 public function get_color_settings() {
373 - $defaults = $this->get_defaults();
374 - $settings = array_keys( $defaults );
375 -
399 + $settings = array_keys( $this->get_defaults() );
376 400 return array_filter( $settings, array( $this, 'is_color' ) );
377 401 }
378 402
379 403 /**
@@ -391,34 +415,95 @@
391 415
392 416 $this->clear_cache();
393 417
394 418 $css = $this->get_css_content( $filename );
395 - $create_file = new FrmCreateFile(
396 - array(
397 - 'file_name' => FrmStylesController::get_file_name(),
398 - 'new_file_path' => FrmAppHelper::plugin_path() . '/css',
399 - )
400 - );
419 + $create_file = new FrmCreateFile( self::get_create_style_file_args() );
401 420 $create_file->create_file( $css );
402 421
403 - update_option( 'frmpro_css', $css, 'no' );
422 + update_option( 'frmpro_css', $css, false );
404 423 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
405 424 }
406 425
407 426 /**
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 + /**
408 494 * @param string $filename
495 + *
409 496 * @return string
410 497 */
411 498 private function get_css_content( $filename ) {
412 - $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
413 -
499 + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
414 500 $saving = true;
415 501 $frm_style = $this;
416 502
417 503 ob_start();
418 504 include $filename;
419 - $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
420 - ob_end_clean();
505 + $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_clean() ) );
421 506
422 507 return FrmStylesController::replace_relative_url( $css );
423 508 }
424 509
@@ -442,8 +527,9 @@
442 527 /**
443 528 * Delete a style by its post ID.
444 529 *
445 530 * @param int $id
531 + *
446 532 * @return false|WP_Post|null
447 533 */
448 534 public function destroy( $id ) {
449 535 if ( $id === $this->get_default_style()->ID ) {
@@ -457,14 +543,11 @@
457 543 */
458 544 public function get_one() {
459 545 if ( 'default' === $this->id ) {
460 546 $style = $this->get_default_style();
461 - if ( $style ) {
462 - $this->id = $style->ID;
463 - } else {
464 - $this->id = 0;
465 - }
466 547
548 + $this->id = $style ? $style->ID : 0;
549 +
467 550 return $style;
468 551 }
469 552
470 553 $style = get_post( $this->id );
@@ -476,9 +559,9 @@
476 559 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
477 560
478 561 $default_values = $this->get_defaults();
479 562
480 - // fill default values
563 + // Fill default values
481 564 $style->post_content = $this->override_defaults( $style->post_content );
482 565 $style->post_content = wp_parse_args( $style->post_content, $default_values );
483 566
484 567 return $style;
@@ -487,8 +570,9 @@
487 570 /**
488 571 * @param string $orderby
489 572 * @param string $order
490 573 * @param int $limit
574 + *
491 575 * @return array
492 576 */
493 577 public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
494 578 $post_atts = array(
@@ -500,16 +584,16 @@
500 584 );
501 585
502 586 $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
503 587
504 - if ( empty( $temp_styles ) ) {
588 + if ( ! $temp_styles ) {
505 589 global $wpdb;
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' );
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
508 592 $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
509 593
510 - if ( empty( $temp_styles ) ) {
511 - // create a new style if there are none
594 + if ( ! $temp_styles ) {
595 + // Create a new style if there are none
512 596 $new = $this->get_new();
513 597 $new->post_title = __( 'Formidable Style', 'formidable' );
514 598 $new->post_name = $new->post_title;
515 599 $new->menu_order = 1;
@@ -516,25 +600,25 @@
516 600 $new = $this->save( (array) $new );
517 601 $this->update( 'default' );
518 602
519 603 $post_atts['include'] = $new;
520 -
521 - $temp_styles = get_posts( $post_atts );
604 + $temp_styles = get_posts( $post_atts );
522 605 }
523 606 }
524 607
525 608 $default_values = $this->get_defaults();
526 609 $default_style = false;
610 + $styles = array();
527 611
528 - $styles = array();
529 612 foreach ( $temp_styles as $style ) {
530 613 $this->id = $style->ID;
614 +
531 615 if ( $style->menu_order ) {
532 616 if ( $default_style ) {
533 - // only return one default
617 + // Only return one default
534 618 $style->menu_order = 0;
535 619 } else {
536 - // check for a default style
620 + // Check for a default style
537 621 $default_style = $style->ID;
538 622 }
539 623 }
540 624
@@ -539,18 +623,17 @@
539 623 }
540 624
541 625 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
542 626
543 - // fill default values
627 + // Fill default values
544 628 $style->post_content = $this->override_defaults( $style->post_content );
545 629 $style->post_content = wp_parse_args( $style->post_content, $default_values );
546 630
547 631 $styles[ $style->ID ] = $style;
548 - }
632 + }//end foreach
549 633
550 634 if ( ! $default_style ) {
551 - $default_style = reset( $styles );
552 -
635 + $default_style = reset( $styles );
553 636 $styles[ $default_style->ID ]->menu_order = 1;
554 637 }
555 638
556 639 return $styles;
@@ -557,8 +640,10 @@
557 640 }
558 641
559 642 /**
560 643 * @param array|null $styles
644 + *
645 + * @return object|null
561 646 */
562 647 public function get_default_style( $styles = null ) {
563 648 if ( ! isset( $styles ) ) {
564 649 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
@@ -568,12 +653,15 @@
568 653 if ( $style->menu_order ) {
569 654 return $style;
570 655 }
571 656 }
657 +
658 + return null;
572 659 }
573 660
574 661 /**
575 662 * @param mixed $settings
663 + *
576 664 * @return mixed
577 665 */
578 666 public function override_defaults( $settings ) {
579 667 if ( ! is_array( $settings ) ) {
@@ -579,9 +667,9 @@
579 667 if ( ! is_array( $settings ) ) {
580 668 return $settings;
581 669 }
582 670
583 - $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height'];
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
584 672
585 673 if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
586 674 $settings['form_desc_size'] = $settings['description_font_size'];
587 675 $settings['form_desc_color'] = $settings['description_color'];
@@ -593,14 +681,28 @@
593 681 $settings['section_border_color'] = $settings['border_color'];
594 682 }
595 683
596 684 if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
597 - $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
598 - $settings['submit_hover_color'] = $settings['submit_text_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'] ) ) {
599 693 $settings['submit_hover_border_color'] = $settings['submit_border_color'];
694 + }
600 695
601 - $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
602 - $settings['submit_active_color'] = $settings['submit_text_color'];
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'] ) ) {
603 705 $settings['submit_active_border_color'] = $settings['submit_border_color'];
604 706 }
605 707
606 708 return apply_filters( 'frm_override_default_styles', $settings );
@@ -746,8 +848,11 @@
746 848 'custom_css' => '',
747 849 'use_base_font_size' => false,
748 850 'base_font_size' => '15px',
749 851 'field_shape_type' => 'rounded-corner',
852 +
853 + 'enable_style_custom_css' => false,
854 + 'single_style_custom_css' => '',
750 855 );
751 856
752 857 return apply_filters( 'frm_default_style_settings', $defaults );
753 858 }
@@ -756,12 +861,13 @@
756 861 * Get a name attribute value for a style setting input.
757 862 *
758 863 * @param string $field_name
759 864 * @param string $post_field
865 + *
760 866 * @return string
761 867 */
762 868 public function get_field_name( $field_name, $post_field = 'post_content' ) {
763 - return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
869 + return 'frm_style_setting' . ( $post_field ? '[' . $post_field . ']' : '' ) . '[' . $field_name . ']';
764 870 }
765 871
766 872 /**
767 873 * @return array
@@ -783,15 +889,17 @@
783 889 /**
784 890 * Don't let imbalanced font families ruin the whole stylesheet.
785 891 *
786 892 * @param string $value
893 + *
787 894 * @return string
788 895 */
789 896 public function force_balanced_quotation( $value ) {
790 897 $balanced_characters = array( '"', "'" );
898 +
791 899 foreach ( $balanced_characters as $char ) {
792 900 $char_count = substr_count( $value, $char );
793 - $is_balanced = $char_count % 2 == 0;
901 + $is_balanced = $char_count % 2 === 0;
794 902
795 903 if ( $is_balanced ) {
796 904 continue;
797 905 }
@@ -801,8 +909,9 @@
801 909 } else {
802 910 $value .= $char;
803 911 }
804 912 }
913 +
805 914 return $value;
806 915 }
807 916
808 917 /**
@@ -808,16 +917,19 @@
808 917 /**
809 918 * Get the default template style
810 919 *
811 920 * @since 6.14
812 - * @param int $style_id The post type "frm_styles" ID.
813 921 *
922 + * @param int|string $style_id The post type "frm_styles" ID.
923 + *
814 924 * @return string The json encoded template data
815 925 */
816 926 public function get_default_template_style( $style_id ) {
817 927 $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true );
818 - if ( empty( $default_template ) ) {
928 +
929 + if ( ! $default_template ) {
819 930 return FrmAppHelper::prepare_and_encode( $this->get_defaults() );
820 931 }
932 +
821 933 return $default_template;
822 934 }
823 935 }