PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / MCP / Actions / RegisterMCPServer.php

RegisterMCPServer.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/MCP/Actions/RegisterMCPServer.php

64 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace Give\MCP\Actions;
4
5 use Give\Framework\Support\Facades\Scripts\ScriptAsset;
6
7 /**
8 * Loads the GiveWP MCP server frontend assets into the dashboard.
9 *
10 * @since 4.9.0
11 */
12 class RegisterMCPServer
13 {
14
15 public const HANDLE = 'givewp-mcp-server';
16
17 /**
18 * Register the GiveWP MCP server into Elementor's Angie SDK if the Angie plugin
19 * is activated and the user has access.
20 *
21 * @action wp_enqueue_scripts
22 * @action admin_enqueue_scripts
23 *
24 * @since 4.9.0
25 *
26 * @return void
27 */
28 public function __invoke(): void
29 {
30 // The angie plugin isn't installed or activated.
31 if ( ! defined('ANGIE_VERSION') ) {
32 return;
33 }
34
35 // The current user doesn't have permission to use angie.
36 if ( ! current_user_can( 'use_angie' ) ) {
37 return;
38 }
39
40 // If we're not logged in, no reason to include this large script.
41 if ( ! is_user_logged_in() ) {
42 return;
43 }
44
45 $scriptAsset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/angieMcp.asset.php');
46
47 wp_register_script(
48 self::HANDLE,
49 GIVE_PLUGIN_URL . 'build/angieMcp.js',
50 array_merge($scriptAsset['dependencies'], ['angie-app']),
51 $scriptAsset['version'],
52 true
53 );
54
55 wp_localize_script( self::HANDLE, 'GiveMcpServerOptions',
56 [
57 'adminUrl' => admin_url(),
58 ]
59 );
60
61 wp_enqueue_script(self::HANDLE);
62 }
63 }
64