| @@ -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'; |
| @@ -156,9 +149,8 @@ | ||
| 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 | } |
| @@ -170,18 +162,14 @@ | ||
| 170 | 162 | |
| 171 | 163 | /** |
| 172 | 164 | * @since 6.0 |
| 173 | 165 | * |
| 174 | - * @param array $style { | |
| 175 | - * API style data. | |
| 176 | - * | |
| 166 | + * @param array $style API style data { | |
| 177 | 167 | * @type array $settings |
| 178 | 168 | * @type string $name |
| 179 | 169 | * @type string $slug |
| 180 | 170 | * } |
| 181 | - * | |
| 182 | 171 | * @param bool $hidden |
| 183 | - * | |
| 184 | 172 | * @return bool True if the template was valid and echoed. |
| 185 | 173 | */ |
| 186 | 174 | private function echo_card_template( $style, $hidden = false ) { |
| 187 | 175 | if ( empty( $style['settings'] ) || ! is_array( $style['settings'] ) ) { |
| @@ -205,16 +193,14 @@ | ||
| 205 | 193 | * Set up a locked style card for the upgrade modal. |
| 206 | 194 | * |
| 207 | 195 | * @param array $params |
| 208 | 196 | * @param array $args { |
| 209 | - * | |
| 210 | - * @type stdClass|WP_Post $style | |
| 197 | + * @type WP_Post|stdClass $style | |
| 211 | 198 | * } |
| 212 | - * | |
| 213 | 199 | * @param stdClass $style_object |
| 214 | 200 | * @param array $style |
| 215 | 201 | */ |
| 216 | - $param_filter = function ( $params, $args ) use ( $style_object, $style ) { | |
| 202 | + $param_filter = function( $params, $args ) use ( $style_object, $style ) { | |
| 217 | 203 | if ( $args['style'] !== $style_object ) { |
| 218 | 204 | return $params; |
| 219 | 205 | } |
| 220 | 206 | |
| @@ -234,16 +220,15 @@ | ||
| 234 | 220 | * Include the template key for the preview in Pro. |
| 235 | 221 | * |
| 236 | 222 | * @param array $params |
| 237 | 223 | * @param array $style |
| 238 | - * | |
| 239 | 224 | * @return array |
| 240 | 225 | */ |
| 241 | - $param_filter = function ( $params ) use ( $style ) { | |
| 226 | + $param_filter = function( $params ) use ( $style ) { | |
| 242 | 227 | $params['data-template-key'] = $style['slug']; |
| 243 | 228 | return $params; |
| 244 | 229 | }; |
| 245 | - }//end if | |
| 230 | + } | |
| 246 | 231 | |
| 247 | 232 | $this->is_new_template = ! empty( $style['is_new'] ); |
| 248 | 233 | |
| 249 | 234 | add_filter( 'frm_style_card_params', $param_filter, 10, $this->locked ? 2 : 1 ); |
| @@ -258,11 +243,10 @@ | ||
| 258 | 243 | * It's kept static as it only requires a $style as input and also gets called when resetting a style. |
| 259 | 244 | * |
| 260 | 245 | * @since 6.0 |
| 261 | 246 | * |
| 262 | - * @param stdClass|WP_Post $style A new style (including duplicated styles) is not a WP_Post object. | |
| 247 | + * @param WP_Post|stdClass $style A new style (including duplicated styles) is not a WP_Post object. | |
| 263 | 248 | * Template cards also use an stdClss instead of a WP_Post object. |
| 264 | - * | |
| 265 | 249 | * @return string |
| 266 | 250 | */ |
| 267 | 251 | public static function get_style_param_for_card( $style ) { |
| 268 | 252 | $styles = array(); |
| @@ -293,9 +277,8 @@ | ||
| 293 | 277 | |
| 294 | 278 | $value = $style->post_content[ $key ]; |
| 295 | 279 | |
| 296 | 280 | $is_hex = in_array( $key, $color_settings, true ) && $value && '#' !== $value[0] && false === strpos( $value, 'rgb' ) && $value !== 'transparent'; |
| 297 | - | |
| 298 | 281 | if ( $is_hex ) { |
| 299 | 282 | $value = '#' . $value; |
| 300 | 283 | } |
| 301 | 284 | |
| @@ -349,9 +332,8 @@ | ||
| 349 | 332 | 'id' => $id, |
| 350 | 333 | 'class' => 'frm-style-card-wrapper with_frm_style', |
| 351 | 334 | 'style' => $wrapper_style, |
| 352 | 335 | ); |
| 353 | - | |
| 354 | 336 | if ( $this->enabled ) { |
| 355 | 337 | $card_wrapper_params['class'] .= ' frm-styles-enabled'; |
| 356 | 338 | } |
| 357 | 339 | |
| @@ -398,9 +380,8 @@ | ||
| 398 | 380 | /** |
| 399 | 381 | * @since 6.0 |
| 400 | 382 | * |
| 401 | 383 | * @param array<array> $styles |
| 402 | - * | |
| 403 | 384 | * @return void |
| 404 | 385 | */ |
| 405 | 386 | private function echo_template_cards( $styles ) { |
| 406 | 387 | array_walk( |
| @@ -410,12 +391,11 @@ | ||
| 410 | 391 | * |
| 411 | 392 | * @param array|string $style |
| 412 | 393 | * @param string $key The key for the API data. It may be a numeric ID, or a key like "active_sub" or "expires". |
| 413 | 394 | * @param int $count Used for pagination. |
| 414 | - * | |
| 415 | 395 | * @return void |
| 416 | 396 | */ |
| 417 | - function ( $style, $key ) { | |
| 397 | + function( $style, $key ) use ( &$count ) { | |
| 418 | 398 | if ( ! is_numeric( $key ) ) { |
| 419 | 399 | // Skip active_sub/expires keys. |
| 420 | 400 | return; |
| 421 | 401 | } |
| @@ -426,9 +406,8 @@ | ||
| 426 | 406 | } |
| 427 | 407 | |
| 428 | 408 | /** |
| 429 | 409 | * @param array<WP_Post> $styles |
| 430 | - * | |
| 431 | 410 | * @return void |
| 432 | 411 | */ |
| 433 | 412 | private function echo_custom_cards( $styles ) { |
| 434 | 413 | $count = 0; |
| @@ -435,17 +414,16 @@ | ||
| 435 | 414 | $this->locked = false; |
| 436 | 415 | array_walk( |
| 437 | 416 | $styles, |
| 438 | 417 | /** |
| 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; | |
| 418 | + * Echo a style card for a single style in the $styles array. | |
| 419 | + * | |
| 420 | + * @param WP_Post $style | |
| 421 | + * @param int $count Used for pagination. | |
| 422 | + * @return void | |
| 423 | + */ | |
| 424 | + function( $style ) use ( &$count ) { | |
| 425 | + $hidden = $count > ( self::PAGE_SIZE - 1 ); | |
| 448 | 426 | $this->echo_style_card( $style, $hidden ); |
| 449 | 427 | ++$count; |
| 450 | 428 | } |
| 451 | 429 | ); |
| @@ -456,9 +434,8 @@ | ||
| 456 | 434 | /** |
| 457 | 435 | * @since 6.0 |
| 458 | 436 | * |
| 459 | 437 | * @param int $count |
| 460 | - * | |
| 461 | 438 | * @return void |
| 462 | 439 | */ |
| 463 | 440 | private function maybe_echo_card_pagination( $count ) { |
| 464 | 441 | if ( $count <= self::PAGE_SIZE ) { |
| @@ -495,9 +472,8 @@ | ||
| 495 | 472 | /** |
| 496 | 473 | * Remove the default style from an array of styles. |
| 497 | 474 | * |
| 498 | 475 | * @param array $styles |
| 499 | - * | |
| 500 | 476 | * @return array |
| 501 | 477 | */ |
| 502 | 478 | public function filter_custom_styles( $styles ) { |
| 503 | 479 | return array_filter( |
| @@ -503,12 +479,11 @@ | ||
| 503 | 479 | return array_filter( |
| 504 | 480 | $styles, |
| 505 | 481 | /** |
| 506 | 482 | * @param WP_Post $style |
| 507 | - * | |
| 508 | 483 | * @return bool |
| 509 | 484 | */ |
| 510 | - function ( $style ) { | |
| 485 | + function( $style ) { | |
| 511 | 486 | return $this->default_style->ID !== $style->ID; |
| 512 | 487 | } |
| 513 | 488 | ); |
| 514 | 489 | } |