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/FrmStylesCardHelper.php +32 -7 6.25 → trunk View file →
@@ -67,8 +67,9 @@
67 67 * @since 6.0
68 68 *
69 69 * @param stdClass|WP_Post $style
70 70 * @param bool $hidden Used for pagination.
71 + *
71 72 * @return void
72 73 */
73 74 private function echo_style_card( $style, $hidden = false ) {
74 75 $params = $this->get_params_for_style_card( $style, $hidden );
@@ -85,8 +86,9 @@
85 86 * @since 6.0
86 87 *
87 88 * @param stdClass|WP_Post $style
88 89 * @param bool $hidden
90 + *
89 91 * @return array
90 92 */
91 93 private function get_params_for_style_card( $style, $hidden = false ) {
92 94 if ( ! empty( $style->post_content['position'] ) ) {
@@ -92,10 +94,9 @@
92 94 if ( ! empty( $style->post_content['position'] ) ) {
93 95 $label_position = $style->post_content['position'];
94 96 } else {
95 97 $frm_style = new FrmStyle();
96 - $defaults = $frm_style->get_defaults();
97 - $label_position = $defaults['position'];
98 + $label_position = $frm_style->get_defaults()['position'];
98 99 }
99 100
100 101 $class_name = 'frm_style_' . $style->post_name;
101 102 $params = array(
@@ -107,14 +108,17 @@
107 108 'data-label-position' => $label_position,
108 109 );
109 110
110 111 $is_active_style = $style->ID === $this->active_style->ID;
112 +
111 113 if ( $is_active_style ) {
112 114 $params['class'] .= ' frm-active-style-card frm-currently-set-style-card';
113 115 }
116 +
114 117 if ( $hidden ) {
115 118 $params['class'] .= ' frm_hidden';
116 119 }
120 +
117 121 if ( self::has_dark_background( $style ) ) {
118 122 $params['class'] .= ' frm-dark-style';
119 123 }
120 124
@@ -124,8 +128,9 @@
124 128 * @since 6.0
125 129 *
126 130 * @param array $params
127 131 * @param array $args {
132 + *
128 133 * @type WP_Post $style
129 134 * }
130 135 */
131 136 return apply_filters( 'frm_style_card_params', $params, compact( 'style' ) );
@@ -132,8 +137,9 @@
132 137 }
133 138
134 139 /**
135 140 * @param stdClass|WP_Post $style
141 + *
136 142 * @return bool
137 143 */
138 144 private static function has_dark_background( $style ) {
139 145 $key = 'fieldset_bg_color';
@@ -143,14 +149,15 @@
143 149 }
144 150
145 151 $color = $style->post_content[ $key ];
146 152
147 - if ( 0 === strpos( $color, 'rgba' ) ) {
153 + if ( str_starts_with( $color, 'rgba' ) ) {
148 154 preg_match_all( '/([\\d.]+)/', $color, $matches );
149 155
150 156 if ( isset( $matches[1][3] ) && is_numeric( $matches[1][3] ) ) {
151 157 // Consider a faded out rgba value as light even when the color is dark.
152 158 $color_opacity = floatval( $matches[1][3] );
159 +
153 160 if ( $color_opacity < 0.5 ) {
154 161 return false;
155 162 }
156 163 }
@@ -169,9 +176,11 @@
169 176 * @type array $settings
170 177 * @type string $name
171 178 * @type string $slug
172 179 * }
180 + *
173 181 * @param bool $hidden
182 + *
174 183 * @return bool True if the template was valid and echoed.
175 184 */
176 185 private function echo_card_template( $style, $hidden = false ) {
177 186 if ( empty( $style['settings'] ) || ! is_array( $style['settings'] ) ) {
@@ -195,10 +204,12 @@
195 204 * Set up a locked style card for the upgrade modal.
196 205 *
197 206 * @param array $params
198 207 * @param array $args {
208 + *
199 209 * @type stdClass|WP_Post $style
200 210 * }
211 + *
201 212 * @param stdClass $style_object
202 213 * @param array $style
203 214 */
204 215 $param_filter = function ( $params, $args ) use ( $style_object, $style ) {
@@ -222,8 +233,9 @@
222 233 * Include the template key for the preview in Pro.
223 234 *
224 235 * @param array $params
225 236 * @param array $style
237 + *
226 238 * @return array
227 239 */
228 240 $param_filter = function ( $params ) use ( $style ) {
229 241 $params['data-template-key'] = $style['slug'];
@@ -247,8 +259,9 @@
247 259 * @since 6.0
248 260 *
249 261 * @param stdClass|WP_Post $style A new style (including duplicated styles) is not a WP_Post object.
250 262 * Template cards also use an stdClss instead of a WP_Post object.
263 + *
251 264 * @return string
252 265 */
253 266 public static function get_style_param_for_card( $style ) {
254 267 $styles = array();
@@ -256,10 +269,11 @@
256 269 // Add the background color setting for fieldsets to the card.
257 270 if ( empty( $style->post_content['fieldset_bg_color'] ) ) {
258 271 $background_color = '#fff';
259 272 } else {
260 - $background_color = ( 0 === strpos( $style->post_content['fieldset_bg_color'], 'rgb' ) ? $style->post_content['fieldset_bg_color'] : '#' . $style->post_content['fieldset_bg_color'] );
273 + $background_color = str_starts_with( $style->post_content['fieldset_bg_color'], 'rgb' ) ? $style->post_content['fieldset_bg_color'] : '#' . $style->post_content['fieldset_bg_color']; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
261 274 }
275 +
262 276 $styles[] = '--preview-background-color: ' . $background_color;
263 277
264 278 if ( empty( $style->post_content['submit_border_color'] ) ) {
265 279 $style->post_content['submit_border_color'] = 'transparent';
@@ -266,9 +280,8 @@
266 280 }
267 281
268 282 // Apply additional styles from the style.
269 283 $rules_to_apply = self::get_style_keys_for_card();
270 -
271 284 $frm_style = new FrmStyle();
272 285 $color_settings = $frm_style->get_color_settings();
273 286
274 287 foreach ( $rules_to_apply as $key ) {
@@ -276,11 +289,11 @@
276 289 // A template from the API may not include every style key. If something is missing, skip it.
277 290 continue;
278 291 }
279 292
280 - $value = $style->post_content[ $key ];
293 + $value = $style->post_content[ $key ];
294 + $is_hex = in_array( $key, $color_settings, true ) && $value && '#' !== $value[0] && ! str_contains( $value, 'rgb' ) && $value !== 'transparent';
281 295
282 - $is_hex = in_array( $key, $color_settings, true ) && $value && '#' !== $value[0] && false === strpos( $value, 'rgb' ) && $value !== 'transparent';
283 296 if ( $is_hex ) {
284 297 $value = '#' . $value;
285 298 }
286 299
@@ -334,8 +347,9 @@
334 347 'id' => $id,
335 348 'class' => 'frm-style-card-wrapper with_frm_style',
336 349 'style' => $wrapper_style,
337 350 );
351 +
338 352 if ( $this->enabled ) {
339 353 $card_wrapper_params['class'] .= ' frm-styles-enabled';
340 354 }
341 355
@@ -340,8 +354,9 @@
340 354 }
341 355
342 356 $first_style = reset( $styles );
343 357 $is_template_wrapper = is_array( $first_style );
358 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
344 359 ?>
345 360 <div <?php FrmAppHelper::array_to_html_params( $card_wrapper_params, true ); ?>>
346 361 <?php
347 362 if ( $is_template_wrapper ) {
@@ -351,8 +366,9 @@
351 366 }
352 367 ?>
353 368 </div>
354 369 <?php
370 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
355 371 }
356 372
357 373 /**
358 374 * Overwrite some styles. We want to make sure the sizes are normalized for the cards.
@@ -382,8 +398,9 @@
382 398 /**
383 399 * @since 6.0
384 400 *
385 401 * @param array<array> $styles
402 + *
386 403 * @return void
387 404 */
388 405 private function echo_template_cards( $styles ) {
389 406 array_walk(
@@ -393,8 +410,9 @@
393 410 *
394 411 * @param array|string $style
395 412 * @param string $key The key for the API data. It may be a numeric ID, or a key like "active_sub" or "expires".
396 413 * @param int $count Used for pagination.
414 + *
397 415 * @return void
398 416 */
399 417 function ( $style, $key ) {
400 418 if ( ! is_numeric( $key ) ) {
@@ -408,8 +426,9 @@
408 426 }
409 427
410 428 /**
411 429 * @param array<WP_Post> $styles
430 + *
412 431 * @return void
413 432 */
414 433 private function echo_custom_cards( $styles ) {
415 434 $count = 0;
@@ -420,8 +439,9 @@
420 439 * Echo a style card for a single style in the $styles array.
421 440 *
422 441 * @param WP_Post $style
423 442 * @param int $count Used for pagination.
443 + *
424 444 * @return void
425 445 */
426 446 function ( $style ) use ( &$count ) {
427 447 $hidden = $count > self::PAGE_SIZE - 1;
@@ -436,8 +456,9 @@
436 456 /**
437 457 * @since 6.0
438 458 *
439 459 * @param int $count
460 + *
440 461 * @return void
441 462 */
442 463 private function maybe_echo_card_pagination( $count ) {
443 464 if ( $count <= self::PAGE_SIZE ) {
@@ -443,8 +464,9 @@
443 464 if ( $count <= self::PAGE_SIZE ) {
444 465 // Not enough cards to require pagination.
445 466 return;
446 467 }
468 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
447 469 ?>
448 470 <div class="frm-style-card-pagination frm_wrap">
449 471 <a href="#" class="frm-show-all-styles">
450 472 <?php
@@ -456,8 +478,9 @@
456 478 ?>
457 479 </a>
458 480 </div>
459 481 <?php
482 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
460 483 }
461 484
462 485 /**
463 486 * @since 6.0
@@ -474,8 +497,9 @@
474 497 /**
475 498 * Remove the default style from an array of styles.
476 499 *
477 500 * @param array $styles
501 + *
478 502 * @return array
479 503 */
480 504 public function filter_custom_styles( $styles ) {
481 505 return array_filter(
@@ -481,8 +505,9 @@
481 505 return array_filter(
482 506 $styles,
483 507 /**
484 508 * @param WP_Post $style
509 + *
485 510 * @return bool
486 511 */
487 512 function ( $style ) {
488 513 return $this->default_style->ID !== $style->ID;