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

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

98 lines 2.2 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 );
57 }
58
59 public function execute( $input = [] ) {
60 return [
61 'resources' => $this->build_catalog(),
62 ];
63 }
64
65 private function build_catalog(): array {
66 $catalog = [];
67
68 foreach ( $this->resolve_registry()->resources() as $ability ) {
69 if ( ! $ability->is_exposed_via_proxy() ) {
70 continue;
71 }
72
73 $catalog[] = [
74 'uri' => (string) $ability->get_uri(),
75 'name' => $ability->get_display_name(),
76 'description' => (string) ( $ability->get_resource_description() ?? '' ),
77 'mimeType' => (string) ( $ability->get_mime_type() ?? '' ),
78 ];
79 }
80
81 return $catalog;
82 }
83
84 private function resolve_registry(): Ability_Registry {
85 if ( $this->registry instanceof Ability_Registry ) {
86 return $this->registry;
87 }
88
89 $module = Plugin::$instance->modules_manager->get_modules( 'mcp' );
90
91 $this->registry = $module instanceof Mcp_Module
92 ? $module->registry()
93 : Mcp_Module::build_core_registry();
94
95 return $this->registry;
96 }
97 }
98