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 / list-resources-ability.php

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

99 lines 2.3 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\Module as Mcp_Module;
7 use Elementor\Modules\Mcp\Registry\Ability_Registry;
8 use Elementor\Plugin;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 class List_Resources_Ability extends Abstract_Ability {
15
16 private ?Ability_Registry $registry;
17
18 public function __construct( ?Ability_Registry $registry = null ) {
19 $this->registry = $registry;
20 }
21
22 protected function get_ability_id(): string {
23 return 'elementor/list-resources';
24 }
25
26 protected function get_definition(): Ability_Definition {
27 return new Ability_Definition(
28 __( 'List Elementor Resources', 'elementor' ),
29 Prompt_Loader::load( 'list-resources' ),
30 'elementor',
31 [
32 'type' => 'object',
33 'properties' => [
34 'resources' => [
35 'type' => 'array',
36 'items' => [
37 'type' => 'object',
38 'properties' => [
39 'uri' => [ 'type' => 'string' ],
40 'name' => [ 'type' => 'string' ],
41 'description' => [ 'type' => 'string' ],
42 'mimeType' => [ 'type' => 'string' ],
43 ],
44 ],
45 ],
46 ],
47 ],
48 [
49 'annotations' => [
50 'readonly' => true,
51 'idempotent' => true,
52 'destructive' => false,
53 ],
54 ],
55 fn() => current_user_can( 'edit_posts' ),
56 Ability_Definition::empty_object_input_schema()
57 );
58 }
59
60 public function execute( $input = [] ) {
61 return [
62 'resources' => $this->build_catalog(),
63 ];
64 }
65
66 private function build_catalog(): array {
67 $catalog = [];
68
69 foreach ( $this->resolve_registry()->resources() as $ability ) {
70 if ( ! $ability->is_exposed_via_proxy() ) {
71 continue;
72 }
73
74 $catalog[] = [
75 'uri' => (string) $ability->get_uri(),
76 'name' => $ability->get_display_name(),
77 'description' => (string) ( $ability->get_resource_description() ?? '' ),
78 'mimeType' => (string) ( $ability->get_mime_type() ?? '' ),
79 ];
80 }
81
82 return $catalog;
83 }
84
85 private function resolve_registry(): Ability_Registry {
86 if ( $this->registry instanceof Ability_Registry ) {
87 return $this->registry;
88 }
89
90 $module = Plugin::$instance->modules_manager->get_modules( 'mcp' );
91
92 $this->registry = $module instanceof Mcp_Module
93 ? $module->registry()
94 : Mcp_Module::build_core_registry();
95
96 return $this->registry;
97 }
98 }
99