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