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/helpers/FrmStylesHelper.php +113 -11 6.27 → trunk View file →
@@ -25,11 +25,13 @@
25 25 *
26 26 * @return void
27 27 */
28 28 public static function save_button() {
29 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
29 30 ?>
30 31 <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" />
31 32 <?php
33 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
32 34 }
33 35
34 36 /**
35 37 * @since 2.05
@@ -192,8 +194,9 @@
192 194 $icons = self::$function_name();
193 195 unset( $function_name );
194 196
195 197 $name = 'arrow' === $type ? 'collapse_icon' : 'repeat_icon';
198 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
196 199 ?>
197 200 <div class="btn-group" id="frm_<?php echo esc_attr( $name ); ?>_select">
198 201 <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
199 202 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ); ?>
@@ -218,8 +221,9 @@
218 221 <?php } ?>
219 222 </ul>
220 223 </div>
221 224 <?php
225 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
222 226 }
223 227
224 228 /**
225 229 * Convert a color setting to a RGB CSV (without the rgb()/rgba() wrapper).
@@ -679,16 +683,16 @@
679 683 // Sanitizing is done later.
680 684 //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
681 685 $posted = wp_unslash( $_POST['frm_style_setting'] );
682 686
683 - if ( ! is_array( $posted ) ) {
687 + if ( is_array( $posted ) ) {
688 + $settings = $frm_style->sanitize_post_content( $posted['post_content'] );
689 + $style_name = FrmAppHelper::get_post_param( 'style_name', '', 'sanitize_title' );
690 + } else {
684 691 $posted = json_decode( $posted, true );
685 692 FrmAppHelper::format_form_data( $posted );
686 693 $settings = $frm_style->sanitize_post_content( $posted['frm_style_setting']['post_content'] );
687 694 $style_name = sanitize_title( $posted['style_name'] );
688 - } else {
689 - $settings = $frm_style->sanitize_post_content( $posted['post_content'] );
690 - $style_name = FrmAppHelper::get_post_param( 'style_name', '', 'sanitize_title' );
691 695 }
692 696 } else {
693 697 $settings = $frm_style->sanitize_post_content( wp_unslash( $_GET ) );
694 698 $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' );
@@ -863,11 +867,8 @@
863 867 $color = trim( $color );
864 868
865 869 if ( ! $color ) {
866 870 $color = $default;
867 - } elseif ( str_contains( $color, 'rgb(' ) ) {
868 - $color = str_replace( 'rgb(', 'rgba(', $color );
869 - $color = str_replace( ')', ',1)', $color );
870 871 } elseif ( ! str_contains( $color, '#' ) && self::is_hex( $color ) ) {
871 872 $color = '#' . $color;
872 873 }
873 874 }
@@ -883,8 +884,9 @@
883 884 * @return bool
884 885 */
885 886 private static function is_hex( $color ) {
886 887 $non_hex_substrings = array(
888 + 'rgb(',
887 889 'rgba(',
888 890 'hsl(',
889 891 'hsla(',
890 892 'hwb(',
@@ -924,8 +926,24 @@
924 926 return $change_margin;
925 927 }
926 928
927 929 /**
930 + * Get the raw alignment value stored in the active style for a radio or checkbox field.
931 + *
932 + * @since 6.32
933 + *
934 + * @param array|int $field The 'field' array.
935 + *
936 + * @return string
937 + */
938 + public static function get_align_from_active_style( $field ) {
939 + $field_type = FrmField::is_checkbox( $field ) ? 'checkbox' : 'radio';
940 + $key = FrmStylesController::get_align_key_for_style_settings( $field_type );
941 +
942 + return FrmStylesController::get_active_style( $field )->post_content[ $key ] ?? '';
943 + }
944 +
945 + /**
928 946 * @since 2.3
929 947 *
930 948 * @return bool
931 949 */
@@ -1115,9 +1133,9 @@
1115 1133 return false;
1116 1134 }
1117 1135
1118 1136 // Handle the case where the submit_bg_img is a full URL string. If the
1119 - // settings were saved with the older styler version prior to 6.14, the
1137 + // Settings were saved with the older styler version prior to 6.14, the
1120 1138 // submit_bg_img will be a full URL string.
1121 1139 if ( ! is_numeric( $background_image ) ) {
1122 1140 return $background_image;
1123 1141 }
@@ -1136,11 +1154,9 @@
1136 1154 if ( ! FrmAppHelper::pro_is_installed() ) {
1137 1155 return false;
1138 1156 }
1139 1157
1140 - return is_callable( 'FrmProAppHelper::use_chosen_js' )
1141 - ? FrmProAppHelper::use_chosen_js()
1142 - : true;
1158 + return is_callable( 'FrmProAppHelper::use_chosen_js' ) ? FrmProAppHelper::use_chosen_js() : true;
1143 1159 }
1144 1160
1145 1161 /**
1146 1162 * Returns the bottom part from a margin/padding value.
@@ -1158,6 +1174,92 @@
1158 1174
1159 1175 $parts = explode( ' ', $value );
1160 1176
1161 1177 return count( $parts ) < 3 ? $parts[0] : $parts[2];
1178 + }
1179 +
1180 + /**
1181 + * Scope CSS to .frm_forms on admin pages to prevent style conflicts.
1182 + * On front-end pages, the CSS is returned unchanged.
1183 + *
1184 + * @since 6.30
1185 + *
1186 + * @param string $css The CSS to scope.
1187 + *
1188 + * @return string
1189 + */
1190 + public static function maybe_scope_css_for_admin( $css ) {
1191 + if ( ! self::should_scope_custom_css() ) {
1192 + return $css;
1193 + }
1194 +
1195 + /**
1196 + * Filter the CSS selector used for @scope when scoping custom CSS on admin pages.
1197 + *
1198 + * @since 6.30
1199 + *
1200 + * @param string $selector The CSS selector to scope to. Default '.frm_forms'.
1201 + */
1202 + $selector = apply_filters( 'frm_scope_custom_css_selector', '.frm_forms' );
1203 +
1204 + return '@scope (' . $selector . ') {' . $css . '}';
1205 + }
1206 +
1207 + /**
1208 + * Scope only the custom CSS portion of the full cached stylesheet for admin pages.
1209 + * Extracts the global custom CSS from the cached CSS, outputs the theme CSS unchanged,
1210 + * and returns only the custom CSS portion scoped.
1211 + *
1212 + * @since 6.30
1213 + *
1214 + * @param string $css The full cached CSS containing both theme and custom CSS.
1215 + *
1216 + * @return string The theme CSS with only the custom CSS portion scoped.
1217 + */
1218 + public static function maybe_scope_custom_css_in_cached_output( $css ) {
1219 + if ( ! self::should_scope_custom_css() ) {
1220 + return $css;
1221 + }
1222 +
1223 + $custom_css = strip_tags( FrmStylesController::get_custom_css() );
1224 +
1225 + if ( ! $custom_css ) {
1226 + return $css;
1227 + }
1228 +
1229 + // The cached CSS is minified. Minify the custom CSS the same way to find it.
1230 + $minified_custom_css = self::minify_css( $custom_css );
1231 + $custom_css_pos = strrpos( $css, $minified_custom_css );
1232 +
1233 + if ( false !== $custom_css_pos ) {
1234 + $css = substr( $css, 0, $custom_css_pos );
1235 + }
1236 +
1237 + return $css . self::maybe_scope_css_for_admin( $custom_css );
1238 + }
1239 +
1240 + /**
1241 + * Minify CSS by stripping comments and whitespace.
1242 + * Matches the minification used when saving the cached CSS file.
1243 + *
1244 + * @since 6.30
1245 + *
1246 + * @param string $css The CSS to minify.
1247 + *
1248 + * @return string
1249 + */
1250 + private static function minify_css( $css ) {
1251 + return preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $css ) );
1252 + }
1253 +
1254 + /**
1255 + * Check if custom CSS should be scoped for admin context.
1256 + *
1257 + * @since 6.30
1258 + *
1259 + * @return bool
1260 + */
1261 + private static function should_scope_custom_css() {
1262 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only, used to scope CSS output for admin context.
1263 + return isset( $_GET['frm_scope_custom_css'] );
1162 1264 }
1163 1265 }