| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities\Appliers\V3; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Validates V3 element_config settings against the per-widget non-style allowlist. |
| 11 |
*/ |
| 12 |
class V3_Non_Style_Allowlist { |
| 13 |
|
| 14 |
/** |
| 15 |
* @param string $widget_type |
| 16 |
* @param array<string, mixed> $settings |
| 17 |
* @return array{allowed: array<string, mixed>, rejected: string[], error: \WP_Error|null} |
| 18 |
*/ |
| 19 |
public static function filter( string $widget_type, array $settings ): array { |
| 20 |
$allowed_keys = V3_Widget_Bridge_Registry::get_non_style_keys( $widget_type ); |
| 21 |
$allowed_lookup = array_fill_keys( $allowed_keys, true ); |
| 22 |
|
| 23 |
$allowed = []; |
| 24 |
$rejected = []; |
| 25 |
|
| 26 |
foreach ( $settings as $key => $value ) { |
| 27 |
if ( ! is_string( $key ) || '' === $key ) { |
| 28 |
continue; |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! isset( $allowed_lookup[ $key ] ) ) { |
| 32 |
$rejected[] = $key; |
| 33 |
continue; |
| 34 |
} |
| 35 |
|
| 36 |
$allowed[ $key ] = $value; |
| 37 |
} |
| 38 |
|
| 39 |
if ( empty( $rejected ) ) { |
| 40 |
return [ |
| 41 |
'allowed' => $allowed, |
| 42 |
'rejected' => [], |
| 43 |
'error' => null, |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
$available = empty( $allowed_keys ) |
| 48 |
? '(none — this V3 widget has no settable behavior keys; use style for visuals)' |
| 49 |
: implode( ', ', $allowed_keys ); |
| 50 |
|
| 51 |
return [ |
| 52 |
'allowed' => $allowed, |
| 53 |
'rejected' => $rejected, |
| 54 |
'error' => new \WP_Error( |
| 55 |
'elementor_invalid_settings', |
| 56 |
sprintf( |
| 57 |
'V3 widget "%s" does not allow settings: %s. Allowed non-style keys: %s. Visual styling must go through the style (CSS) input.', |
| 58 |
$widget_type, |
| 59 |
implode( ', ', $rejected ), |
| 60 |
$available |
| 61 |
), |
| 62 |
[ 'status' => \WP_Http::BAD_REQUEST ] |
| 63 |
), |
| 64 |
]; |
| 65 |
} |
| 66 |
} |
| 67 |
|