PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0
Elementor Website Builder – more than just a page builder v4.3.0
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 / ability-definition.php

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

77 lines 1.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 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Ability_Definition {
10 public string $label;
11 public string $description;
12 public string $category;
13 public array $output_schema;
14 public array $meta;
15 /** @var callable */
16 public $permission_callback;
17 public array $input_schema;
18
19 public function __construct(
20 string $label,
21 string $description,
22 string $category,
23 array $output_schema,
24 array $meta,
25 callable $permission_callback,
26 array $input_schema = []
27 ) {
28 $this->label = $label;
29 $this->description = $description;
30 $this->category = $category;
31 $this->output_schema = $output_schema;
32 $this->meta = $meta;
33 $this->permission_callback = $permission_callback;
34 $this->input_schema = $input_schema;
35 }
36
37 public static function empty_object_input_schema(): array {
38 return [
39 'type' => 'object',
40 ];
41 }
42
43 public function to_array(): array {
44 return [
45 'label' => $this->label,
46 'description' => $this->description,
47 'category' => $this->category,
48 'output_schema' => $this->output_schema,
49 'meta' => $this->meta,
50 'permission_callback' => $this->permission_callback,
51 'input_schema' => $this->normalized_input_schema(),
52 ];
53 }
54
55 private function normalized_input_schema(): array {
56 if ( empty( $this->input_schema ) ) {
57 return self::empty_object_input_schema();
58 }
59
60 $schema = $this->input_schema;
61
62 if (
63 array_key_exists( 'properties', $schema )
64 && is_array( $schema['properties'] )
65 && empty( $schema['properties'] )
66 ) {
67 unset( $schema['properties'] );
68 }
69
70 if ( ! isset( $schema['type'] ) ) {
71 $schema['type'] = 'object';
72 }
73
74 return $schema;
75 }
76 }
77