PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.1
Elementor Website Builder – more than just a page builder v4.3.1
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
elementor / modules / mcp / abilities / appliers / v3 / v3-settings-validator.php

v3-settings-validator.php in Elementor Website Builder – more than just a page builder 4.3.1, at modules/mcp/abilities/appliers/v3/v3-settings-validator.php

59 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Mcp\Abilities\Appliers\V3;
4
5 use Elementor\Modules\Mcp\Abilities\Utils\V3_Json_Schema_Builder;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 /**
12 * Shallow shape guard for the primitive remainder of a V3 element_config entry.
13 *
14 * Called after `V3_Non_Style_Allowlist` (key gate) and `V3_Dynamic_Hoister`
15 * (splits dynamic shortcodes from primitives). Delegates to
16 * `V3_Json_Schema_Builder::check_settings_shape()` — enforces only `type`,
17 * `enum`, and one-level nested `properties.type` so the applier never merges
18 * an array into a scalar field.
19 */
20 class V3_Settings_Validator {
21
22 /**
23 * @param string $widget_type V3 widget type (e.g. `theme-post-title`).
24 * @param array<string, mixed> $primitives Primitive settings (after hoisting removed __dynamic__ entries).
25 * @param array<string, mixed> $widget_config Widget config from `Widget_Type_Resolver::resolve_type_config()`.
26 *
27 * @return array{
28 * valid: array<string, mixed>,
29 * error: \WP_Error|null,
30 * }
31 */
32 public static function validate_shape( string $widget_type, array $primitives, array $widget_config ): array {
33 $controls = is_array( $widget_config['controls'] ?? null ) ? $widget_config['controls'] : [];
34 $schema = V3_Json_Schema_Builder::build( $controls, array_keys( $primitives ) );
35 $shape = V3_Json_Schema_Builder::check_settings_shape( $primitives, $schema );
36
37 if ( empty( $shape['errors'] ) ) {
38 return [
39 'valid' => $shape['valid'],
40 'error' => null,
41 ];
42 }
43
44 $messages = [];
45 foreach ( $shape['errors'] as $key => $reason ) {
46 $messages[] = sprintf( 'V3 widget "%s" property "%s": %s', $widget_type, $key, $reason );
47 }
48
49 return [
50 'valid' => $shape['valid'],
51 'error' => new \WP_Error(
52 'elementor_invalid_settings',
53 implode( '; ', $messages ),
54 [ 'status' => \WP_Http::BAD_REQUEST ]
55 ),
56 ];
57 }
58 }
59