-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordpress-webmcp.php
More file actions
94 lines (77 loc) · 2.99 KB
/
Copy pathwordpress-webmcp.php
File metadata and controls
94 lines (77 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Plugin Name: WordPress WebMCP
* Plugin URI: https://github.com/whtnxt/wordpress-webmcp
* Description: WebMCP (Web Model Context Protocol) server for WordPress — allows AI agents to navigate and engage with your WordPress site through browser-native MCP tools.
* Version: 1.0.0
* Author: Whtnxt
* Author URI: https://whtnxt.io
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wordpress-webmcp
* Requires at least: 6.5
* Requires PHP: 8.1
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* @package WordPress_WebMCP
*/
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'WP_WEBMCP_VERSION' ) ) {
define( 'WP_WEBMCP_VERSION', '1.0.0' );
}
if ( ! defined( 'WP_WEBMCP_PLUGIN_FILE' ) ) {
define( 'WP_WEBMCP_PLUGIN_FILE', __FILE__ );
}
if ( ! defined( 'WP_WEBMCP_PLUGIN_BASENAME' ) ) {
define( 'WP_WEBMCP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
}
if ( ! defined( 'WP_WEBMCP_PLUGIN_DIR' ) ) {
define( 'WP_WEBMCP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'WP_WEBMCP_PLUGIN_URL' ) ) {
define( 'WP_WEBMCP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'WP_WEBMCP_ASSETS_DIR' ) ) {
define( 'WP_WEBMCP_ASSETS_DIR', WP_WEBMCP_PLUGIN_DIR . 'assets' );
}
if ( ! defined( 'WP_WEBMCP_ASSETS_URL' ) ) {
define( 'WP_WEBMCP_ASSETS_URL', WP_WEBMCP_PLUGIN_URL . 'assets' );
}
require_once __DIR__ . '/includes/class-webmcp-registry.php';
require_once __DIR__ . '/includes/class-webmcp-rest.php';
require_once __DIR__ . '/includes/class-webmcp-scripts.php';
require_once __DIR__ . '/includes/class-webmcp-block.php';
require_once __DIR__ . '/admin/class-webmcp-settings.php';
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once __DIR__ . '/includes/cli.php';
}
register_activation_hook( __FILE__, [ WPCli\WebMCP\Registry::class, 'install' ] );
register_deactivation_hook( __FILE__, [ WPCli\WebMCP\Registry::class, 'uninstall' ] );
WPCli\WebMCP\REST::instance();
WPCli\WebMCP\Scripts::instance();
WPCli\WebMCP\Block::instance();
if ( is_admin() ) {
WPCli\WebMCP\Settings::instance();
}
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'webmcp', WPCli\WebMCP\CLI::class );
}
add_action( 'init', function () {
load_plugin_textdomain( 'wordpress-webmcp', false, dirname( WP_WEBMCP_PLUGIN_BASENAME ) . '/languages/' );
} );
// WebMCP requires origin isolation (SecureContext + COOP/COEP headers).
// These headers must be sent on all responses for document.modelContext to be available.
add_action( 'send_headers', function () {
if ( ! is_admin() ) {
header( 'Cross-Origin-Opener-Policy: same-origin' );
header( 'Cross-Origin-Embedder-Policy: require-corp' );
header( 'Cross-Origin-Resource-Policy: same-origin' );
}
} );