PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.0
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.0
4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / mcp / manager.php
elementskit-lite / mcp Last commit date
assets 3 weeks ago abilities.php 3 weeks ago manager.php 3 weeks ago rest-proxy.php 3 weeks ago server.php 3 weeks ago service.php 3 weeks ago
manager.php
112 lines
1 <?php
2 namespace ElementsKit_Lite\Mcp;
3
4 use ElementsKit_Lite\Traits\Singleton;
5
6 defined( 'ABSPATH' ) || exit;
7
8 /**
9 * Entry point for ElementsKit's MCP support.
10 *
11 * Wires together the layers described in the architecture:
12 * - shared PHP service ({@see Service}),
13 * - the public backend contract: WP Abilities ({@see Abilities}) and the
14 * optional MCP server ({@see Server}),
15 * - the editor convenience layer: the REST proxy ({@see Rest_Proxy}) and the
16 * Angie integration JS.
17 *
18 * The Angie integration is a browser bundle built with @elementor/angie-sdk that
19 * registers an ElementsKit MCP server with Angie over postMessage. Angie loads
20 * globally in wp-admin, so this is enqueued globally (not only in the Elementor
21 * editor) and gated on the Angie plugin being active — the same mechanism the
22 * Amelia plugin uses. Each tool forwards to the REST proxy.
23 *
24 * Instantiated directly from the plugin bootstrap; not a toggleable module.
25 *
26 * @since 3.10.x
27 */
28 class Manager {
29
30 use Singleton;
31
32 const ANGIE_HANDLE = 'elementskit-angie-mcp';
33 const ANGIE_PLUGIN = 'angie/angie.php';
34
35 public function __construct() {
36 ( new Abilities() )->hooks();
37 ( new Server() )->hooks();
38 ( new Rest_Proxy() )->hooks();
39
40 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_angie_integration' ] );
41 }
42
43 /**
44 * Register the ElementsKit MCP server with Angie, wherever Angie is available
45 * in wp-admin (dashboard and the Elementor editor alike).
46 */
47 public function enqueue_angie_integration() {
48 if ( ! $this->angie_active() ) {
49 return;
50 }
51
52 // The Script Modules API (wp_enqueue_script_module) landed in WordPress 6.5.
53 if ( ! function_exists( 'wp_enqueue_script_module' ) ) {
54 return;
55 }
56
57 $path = \ElementsKit_Lite::plugin_dir() . 'mcp/assets/elementskit-angie.js';
58
59 if ( ! file_exists( $path ) ) {
60 return;
61 }
62
63 // Script modules cannot receive wp_localize_script, so hand the bundle its
64 // REST endpoint + nonce through a global printed before the module runs.
65 add_action( 'admin_print_scripts', [ $this, 'print_angie_config' ] );
66
67 // Version by file mtime so every rebuild busts the browser's module cache.
68 $version = \ElementsKit_Lite::version() . '.' . (string) filemtime( $path );
69
70 wp_enqueue_script_module(
71 self::ANGIE_HANDLE,
72 \ElementsKit_Lite::plugin_url() . 'mcp/assets/elementskit-angie.js',
73 [],
74 $version
75 );
76 }
77
78 /**
79 * Print the config the Angie bundle reads (window.ElementsKitMcpConfig).
80 */
81 public function print_angie_config() {
82 static $printed = false;
83
84 if ( $printed ) {
85 return;
86 }
87 $printed = true;
88
89 $config = [
90 'restUrl' => esc_url_raw( get_rest_url( null, Rest_Proxy::NAMESPACE . Rest_Proxy::ROUTE ) ),
91 'nonce' => wp_create_nonce( 'wp_rest' ),
92 'adminUrl' => esc_url_raw( admin_url() ),
93 ];
94
95 printf(
96 "<script>window.ElementsKitMcpConfig = %s;</script>\n",
97 wp_json_encode( $config )
98 );
99 }
100
101 /**
102 * @return bool Whether the Angie plugin is active.
103 */
104 private function angie_active() {
105 if ( ! function_exists( 'is_plugin_active' ) ) {
106 require_once ABSPATH . 'wp-admin/includes/plugin.php';
107 }
108
109 return function_exists( 'is_plugin_active' ) && is_plugin_active( self::ANGIE_PLUGIN );
110 }
111 }
112