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.2 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 All 455 releases
elementor / modules / mcp / abilities / appliers / v3 / v3-dynamic-resolver.php

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

85 lines 1.9 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 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Detects LLM-facing dynamic-tag input shapes on V3 widget controls.
11 */
12 class V3_Dynamic_Resolver {
13
14 public static function is_dynamic_capable( array $control ): bool {
15 $control_dynamic = is_array( $control['dynamic'] ?? null ) ? $control['dynamic'] : [];
16
17 if ( true === ( $control_dynamic['active'] ?? false ) ) {
18 return true;
19 }
20
21 return is_string( $control_dynamic['default'] ?? null ) && '' !== $control_dynamic['default'];
22 }
23
24 /**
25 * @return array{name: string, settings: array<string, mixed>}|null
26 */
27 public static function extract_input( $value, ?string $property ): ?array {
28 if ( ! is_array( $value ) ) {
29 return null;
30 }
31
32 $top_level = self::normalize_dynamic_input( $value );
33 if ( null !== $top_level ) {
34 return $top_level;
35 }
36
37 if ( ! is_string( $property ) || '' === $property ) {
38 return null;
39 }
40
41 $nested = $value[ $property ] ?? null;
42 if ( ! is_array( $nested ) ) {
43 return null;
44 }
45
46 return self::normalize_dynamic_input( $nested );
47 }
48
49 /**
50 * @param array<string, mixed> $value
51 *
52 * @return array<string, mixed>
53 */
54 public static function extract_primitive_remainder( array $value, ?string $property ): array {
55 if ( ! is_string( $property ) || '' === $property || ! array_key_exists( $property, $value ) ) {
56 return [];
57 }
58
59 $remainder = $value;
60 unset( $remainder[ $property ] );
61
62 return $remainder;
63 }
64
65 /**
66 * @return array{name: string, settings: array<string, mixed>}|null
67 */
68 private static function normalize_dynamic_input( array $candidate ): ?array {
69 $name = $candidate['name'] ?? null;
70 if ( ! is_string( $name ) || '' === $name ) {
71 return null;
72 }
73
74 $settings = $candidate['settings'] ?? [];
75 if ( ! is_array( $settings ) ) {
76 $settings = [];
77 }
78
79 return [
80 'name' => $name,
81 'settings' => $settings,
82 ];
83 }
84 }
85