PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
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 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / mcp / abilities / get-widget-schema-ability.php

get-widget-schema-ability.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/mcp/abilities/get-widget-schema-ability.php

94 lines 2.6 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;
4
5 use Elementor\Modules\Mcp\Abilities\Utils\Prompt_Loader;
6 use Elementor\Modules\Mcp\Abilities\Utils\Widget_Context_Helper;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class Get_Widget_Schema_Ability extends Abstract_Ability {
13
14 protected function get_ability_id(): string {
15 return 'elementor/get-widget-schema';
16 }
17
18 protected function get_definition(): Ability_Definition {
19 return new Ability_Definition(
20 __( 'Get Elementor Widget Schema', 'elementor' ),
21 Prompt_Loader::load( 'get-widget-schema' ),
22 'elementor',
23 [ 'type' => 'object' ],
24 [
25 'annotations' => [
26 'readonly' => true,
27 'idempotent' => true,
28 'destructive' => false,
29 ],
30 ],
31 function () {
32 return current_user_can( 'edit_posts' );
33 },
34 [
35 'type' => 'object',
36 'required' => [ 'widget_type' ],
37 'properties' => [
38 'widget_type' => [
39 'type' => 'string',
40 'description' => 'Registry identifier of the widget, e.g. "e-heading".',
41 ],
42 ],
43 ]
44 );
45 }
46
47 public function execute( $input = [] ) {
48 $input = is_array( $input ) ? $input : [];
49 $widget_type = isset( $input['widget_type'] ) ? sanitize_key( $input['widget_type'] ) : '';
50
51 if ( ! $widget_type ) {
52 return new \WP_Error(
53 'invalid_input',
54 __( 'widget_type is required.', 'elementor' ),
55 [ 'status' => \WP_Http::BAD_REQUEST ]
56 );
57 }
58
59 $config = Widget_Context_Helper::get_widget_config( $widget_type );
60
61 if ( ! $config || ! Widget_Context_Helper::is_widget_eligible_for_llm( $config ) ) {
62 return new \WP_Error(
63 'elementor_not_found',
64 /* translators: %s: widget type */
65 sprintf( __( 'Unknown widget type: %s.', 'elementor' ), $widget_type ),
66 [ 'status' => \WP_Http::NOT_FOUND ]
67 );
68 }
69
70 $is_v3 = Widget_Context_Helper::VERSION_V3 === Widget_Context_Helper::get_widget_version( $config );
71
72 if ( $is_v3 && ! Widget_Context_Helper::is_v3_allowlisted( $widget_type ) ) {
73 return new \WP_Error(
74 'elementor_v3_not_supported',
75 __( 'This is a legacy V3 widget and cannot be modified through this MCP. Edit V3 widgets directly in the Elementor editor.', 'elementor' ),
76 [
77 'status' => \WP_Http::BAD_REQUEST,
78 'widget_type' => $widget_type,
79 'version' => 'v3',
80 ]
81 );
82 }
83
84 if ( $is_v3 ) {
85 return Widget_Context_Helper::build_widget_schema( $widget_type, $config );
86 }
87
88 $all_widget_configs = Widget_Context_Helper::get_llm_eligible_widgets();
89 $parents_index = Widget_Context_Helper::build_parents_index( $all_widget_configs );
90
91 return Widget_Context_Helper::build_widget_schema( $widget_type, $config, $parents_index );
92 }
93 }
94