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 +98 -20 6.28 → trunk View file →
@@ -118,20 +118,24 @@
118 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
119 119 $new_instance['post_content']['custom_css'] = $custom_css;
120 120 unset( $custom_css );
121 121
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 122 $new_instance['post_type'] = FrmStylesController::$post_type;
128 123 $new_instance['post_status'] = 'publish';
129 124
130 125 if ( ! $id ) {
131 - $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 );
132 131 }
133 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 +
134 138 $default_settings = $this->get_defaults();
135 139
136 140 foreach ( $default_settings as $setting => $default ) {
137 141 if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
@@ -212,9 +216,9 @@
212 216 $new_value = 0;
213 217 } else {
214 218 $new_value = absint( $value );
215 219 }
216 - } else {
220 + } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
217 221 // Insert a value for alpha.
218 222 if ( $value_is_empty_string ) {
219 223 $new_value = 4 === $length_of_color_codes ? 1 : 0;
220 224 } elseif ( $value > 1 || $value < 0 ) {
@@ -391,11 +395,9 @@
391 395 *
392 396 * @return array
393 397 */
394 398 public function get_color_settings() {
395 - $defaults = $this->get_defaults();
396 - $settings = array_keys( $defaults );
397 -
399 + $settings = array_keys( $this->get_defaults() );
398 400 return array_filter( $settings, array( $this, 'is_color' ) );
399 401 }
400 402
401 403 /**
@@ -413,14 +415,9 @@
413 415
414 416 $this->clear_cache();
415 417
416 418 $css = $this->get_css_content( $filename );
417 - $create_file = new FrmCreateFile(
418 - array(
419 - 'file_name' => FrmStylesController::get_file_name(),
420 - 'new_file_path' => FrmAppHelper::plugin_path() . '/css',
421 - )
422 - );
419 + $create_file = new FrmCreateFile( self::get_create_style_file_args() );
423 420 $create_file->create_file( $css );
424 421
425 422 update_option( 'frmpro_css', $css, false );
426 423 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
@@ -426,8 +423,75 @@
426 423 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
427 424 }
428 425
429 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 + /**
430 494 * @param string $filename
431 495 *
432 496 * @return string
433 497 */
@@ -617,14 +681,28 @@
617 681 $settings['section_border_color'] = $settings['border_color'];
618 682 }
619 683
620 684 if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
621 - $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
622 - $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'] ) ) {
623 693 $settings['submit_hover_border_color'] = $settings['submit_border_color'];
694 + }
624 695
625 - $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
626 - $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'] ) ) {
627 705 $settings['submit_active_border_color'] = $settings['submit_border_color'];
628 706 }
629 707
630 708 return apply_filters( 'frm_override_default_styles', $settings );