PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-dev3
Elementor Website Builder – more than just a page builder v4.1.0-dev3
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
← All changes | modules/mcp/abilities/abstract-ability.php +3 -105 4.3.0-beta2 → 4.1.0-dev3 View file →
@@ -1,10 +1,8 @@
1 1 <?php
2 2
3 3 namespace Elementor\Modules\Mcp\Abilities;
4 4
5 -use Elementor\Modules\Mcp\Utils\Editor_Sync_State;
6 -
7 5 if ( ! defined( 'ABSPATH' ) ) {
8 6 exit;
9 7 }
10 8
@@ -9,14 +7,8 @@
9 7 }
10 8
11 9 abstract class Abstract_Ability {
12 10
13 - const KIND_TOOL = 'tool';
14 - const KIND_RESOURCE = 'resource';
15 - const ABILITY_ID_PREFIX = 'elementor/';
16 -
17 - private ?Ability_Definition $cached_definition = null;
18 -
19 11 abstract protected function get_ability_id(): string;
20 12
21 13 abstract protected function get_definition(): Ability_Definition;
22 14
@@ -21,104 +13,10 @@
21 13 abstract protected function get_definition(): Ability_Definition;
22 14
23 15 abstract public function execute( $input = [] );
24 16
25 - final public function execute_guarded( $input = [] ) {
26 - $is_mutating = self::KIND_TOOL === $this->get_kind() && $this->is_destructive();
27 -
28 - if ( $is_mutating ) {
29 - $guard = apply_filters( 'elementor/mcp/pre_execute_guard', null, $input );
30 - if ( is_wp_error( $guard ) ) {
31 - return $guard;
32 - }
33 - }
34 -
35 - $result = $this->execute( $input );
36 - $post_id = isset( $input['post_id'] ) ? (int) $input['post_id'] : 0;
37 -
38 - $is_failed = is_wp_error( $result ) || ( is_array( $result ) && 'error' === ( $result['status'] ?? '' ) );
39 -
40 - if ( $is_mutating && $post_id > 0 && ! $is_failed ) {
41 - Editor_Sync_State::set_mcp_mutation( $post_id );
42 - }
43 -
44 - return $result;
45 - }
46 -
47 - public function check_permission(): bool {
48 - return (bool) call_user_func( $this->definition()->permission_callback );
49 - }
50 -
51 17 public function register(): void {
52 - $definition = $this->definition()->to_array();
53 - $definition['execute_callback'] = [ $this, 'execute_guarded' ];
54 - $meta = is_array( $definition['meta'] ?? null ) ? $definition['meta'] : [];
55 - $mcp = is_array( $meta['mcp'] ?? null ) ? $meta['mcp'] : [];
56 - $mcp['public'] = true;
57 - $meta['mcp'] = $mcp;
58 - $meta['show_in_rest'] = true;
59 - $definition['meta'] = $meta;
60 - wp_register_ability( $this->get_id(), $definition );
61 - }
62 -
63 - public function get_id(): string {
64 - return $this->get_ability_id();
65 - }
66 -
67 - public function get_kind(): string {
68 - return $this->is_resource() ? self::KIND_RESOURCE : self::KIND_TOOL;
69 - }
70 -
71 - public function get_uri(): ?string {
72 - return $this->mcp_meta()['uri'] ?? null;
73 - }
74 -
75 - public function get_mime_type(): ?string {
76 - return $this->mcp_meta()['mimeType'] ?? null;
77 - }
78 -
79 - public function get_resource_description(): ?string {
80 - return $this->mcp_meta()['description'] ?? $this->definition()->description;
81 - }
82 -
83 - public function get_display_name(): string {
84 - return (string) ( $this->mcp_meta()['name'] ?? $this->definition()->label );
85 - }
86 -
87 - public function get_proxy_slug(): string {
88 - if ( self::KIND_RESOURCE === $this->get_kind() ) {
89 - return (string) $this->get_uri();
90 - }
91 -
92 - return substr( $this->get_id(), strlen( self::ABILITY_ID_PREFIX ) );
93 - }
94 -
95 - public function is_exposed_via_proxy(): bool {
96 - return true;
97 - }
98 -
99 - public function is_exposed_on_server(): bool {
100 - return true;
101 - }
102 -
103 - private function is_resource(): bool {
104 - return self::KIND_RESOURCE === ( $this->mcp_meta()['type'] ?? null );
105 - }
106 -
107 - private function is_destructive(): bool {
108 - return false !== ( $this->definition()->meta['annotations']['destructive'] ?? true );
109 - }
110 -
111 - protected function definition(): Ability_Definition {
112 - if ( null === $this->cached_definition ) {
113 - $this->cached_definition = $this->get_definition();
114 - }
115 -
116 - return $this->cached_definition;
117 - }
118 -
119 - private function mcp_meta(): array {
120 - $meta = $this->definition()->meta;
121 -
122 - return is_array( $meta['mcp'] ?? null ) ? $meta['mcp'] : [];
18 + $definition = $this->get_definition()->to_array();
19 + $definition['execute_callback'] = [ $this, 'execute' ];
20 + wp_register_ability( $this->get_ability_id(), $definition );
123 21 }
124 22 }