| @@ -324,14 +324,42 @@ | ||
| 324 | 324 | $vars['--sd-btn-align-items'] = $align_map[ $settings['buttonAlignment'] ]; |
| 325 | 325 | $vars['--sd-btn-width'] = 'auto'; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - if ( empty( $vars ) ) { | |
| 328 | + /** | |
| 329 | + * Filter the form style CSS custom properties before they are serialized | |
| 330 | + * onto the `.sd-form-container` wrapper. | |
| 331 | + * | |
| 332 | + * Add-ons (e.g. SureDonation Pro) use this to contribute additional | |
| 333 | + * `--sd-*` variables. Runs before the empty-check so an add-on can style a | |
| 334 | + * form even when the free panel set nothing. Values must be pre-sanitized | |
| 335 | + * CSS tokens — they are emitted verbatim inside the inline style attribute. | |
| 336 | + * | |
| 337 | + * @param array<string, string> $vars Map of `--sd-*` variable => value. | |
| 338 | + * @param int $form_id Form post ID. | |
| 339 | + * @param array<string, mixed> $settings Merged free style settings. | |
| 340 | + * @since 1.5.0 | |
| 341 | + */ | |
| 342 | + $vars = apply_filters( 'suredonation_form_style_vars', $vars, (int) $form_id, $settings ); | |
| 343 | + | |
| 344 | + if ( ! is_array( $vars ) || empty( $vars ) ) { | |
| 329 | 345 | return ''; |
| 330 | 346 | } |
| 331 | 347 | |
| 332 | 348 | $declarations = []; |
| 333 | 349 | foreach ( $vars as $name => $value ) { |
| 350 | + // Defense-in-depth for the public filter above: only emit custom | |
| 351 | + // properties with scalar, declaration-safe values, so a | |
| 352 | + // non-sanitizing add-on callback cannot append arbitrary | |
| 353 | + // declarations or trigger array-to-string notices. Values are | |
| 354 | + // additionally escaped by the caller via esc_attr(). | |
| 355 | + if ( | |
| 356 | + ! is_scalar( $value ) | |
| 357 | + || ! preg_match( '/^--[A-Za-z0-9_-]+$/', (string) $name ) | |
| 358 | + || preg_match( '/[;{}]/', (string) $value ) | |
| 359 | + ) { | |
| 360 | + continue; | |
| 361 | + } | |
| 334 | 362 | $declarations[] = $name . ':' . $value; |
| 335 | 363 | } |
| 336 | 364 | |
| 337 | 365 | return implode( ';', $declarations ) . ';'; |
| @@ -407,9 +435,9 @@ | ||
| 407 | 435 | * @param array<string, mixed> $fallback Default box. |
| 408 | 436 | * @return array<string, mixed> |
| 409 | 437 | * @since 1.0.0 |
| 410 | 438 | */ |
| 411 | - private static function sanitize_box( $box, $fallback ) { | |
| 439 | + public static function sanitize_box( $box, $fallback ) { | |
| 412 | 440 | if ( ! is_array( $box ) ) { |
| 413 | 441 | return $fallback; |
| 414 | 442 | } |
| 415 | 443 | |
| @@ -423,21 +451,25 @@ | ||
| 423 | 451 | |
| 424 | 452 | /** |
| 425 | 453 | * Validate a CSS length (e.g. "10px", "1.5rem"); bare numbers become px. |
| 426 | 454 | * |
| 455 | + * Negative values are rejected: every consumer here (padding, border | |
| 456 | + * radius) is invalid with a negative length, which the browser would | |
| 457 | + * silently drop. | |
| 458 | + * | |
| 427 | 459 | * @param mixed $value Incoming value. |
| 428 | - * @return string Valid length, or '' when invalid/empty. | |
| 460 | + * @return string Valid length, or '' when invalid/empty/negative. | |
| 429 | 461 | * @since 1.0.0 |
| 430 | 462 | */ |
| 431 | - private static function sanitize_length( $value ) { | |
| 463 | + public static function sanitize_length( $value ) { | |
| 432 | 464 | if ( is_numeric( $value ) ) { |
| 433 | - return ( 0 + $value ) . 'px'; | |
| 465 | + return $value < 0 ? '' : ( 0 + $value ) . 'px'; | |
| 434 | 466 | } |
| 435 | 467 | $value = is_string( $value ) ? trim( $value ) : ''; |
| 436 | 468 | if ( '' === $value ) { |
| 437 | 469 | return ''; |
| 438 | 470 | } |
| 439 | - return preg_match( '/^-?\d*\.?\d+(px|em|rem|%|vw|vh)$/', $value ) ? $value : ''; | |
| 471 | + return preg_match( '/^\d*\.?\d+(px|em|rem|%|vw|vh)$/', $value ) ? $value : ''; | |
| 440 | 472 | } |
| 441 | 473 | |
| 442 | 474 | /** |
| 443 | 475 | * Sanitize a color value via a strict allowlist. |
| @@ -449,9 +481,9 @@ | ||
| 449 | 481 | * @param mixed $value Incoming color. |
| 450 | 482 | * @return string Valid color, or '' when invalid/empty. |
| 451 | 483 | * @since 1.0.0 |
| 452 | 484 | */ |
| 453 | - private static function sanitize_color( $value ) { | |
| 485 | + public static function sanitize_color( $value ) { | |
| 454 | 486 | $value = is_string( $value ) ? trim( $value ) : ''; |
| 455 | 487 | if ( '' === $value ) { |
| 456 | 488 | return ''; |
| 457 | 489 | } |
| @@ -489,9 +521,9 @@ | ||
| 489 | 521 | * @param mixed $value Incoming gradient. |
| 490 | 522 | * @return string Valid gradient, or '' when invalid/empty. |
| 491 | 523 | * @since 1.0.0 |
| 492 | 524 | */ |
| 493 | - private static function sanitize_gradient( $value ) { | |
| 525 | + public static function sanitize_gradient( $value ) { | |
| 494 | 526 | $value = is_string( $value ) ? trim( $value ) : ''; |
| 495 | 527 | if ( '' === $value ) { |
| 496 | 528 | return ''; |
| 497 | 529 | } |