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