-
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathemcp-tools.php
More file actions
178 lines (162 loc) · 6.78 KB
/
Copy pathemcp-tools.php
File metadata and controls
178 lines (162 loc) · 6.78 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Plugin Name: EMCP Tools
* Plugin URI: https://github.com/msrbuilds/elementor-mcp
* Description: Extends the WordPress MCP Adapter to expose Elementor data, widgets, and page design tools as MCP tools for AI agents.
* Version: 3.7.0
* Requires at least: 6.9
* Tested up to: 6.9
* Requires PHP: 8.1
* Author: Mian Shahzad Raza
* Author URI: https://msrbuilds.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: emcp-tools
* Domain Path: /languages
*
* This file is the bootstrap ONLY: plugin header, the legacy-rename guard,
* constants, the Freemius SDK helper, the uninstall hook, and the entry point
* that hands off to EMCP_Tools_Bootstrap. All feature logic lives in classes
* under includes/.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Legacy coexistence guard.
*
* This plugin was renamed from the `elementor-mcp` folder/slug to `emcp-tools`.
* On an existing site the old `elementor-mcp/elementor-mcp.php` plugin may still
* be active alongside this one during the transition. All PHP symbols were
* re-prefixed (EMCP_Tools_* / emcp_tools_*) so the two can coexist without
* "cannot redeclare" fatals — but they would still both register the same MCP
* abilities/server and share data. So while the old plugin is active we do NOT
* boot: we snapshot its settings (admin only) and show a notice, then bail
* before defining constants, initializing Freemius, or registering anything.
*/
require_once __DIR__ . '/includes/class-migration.php';
if ( EMCP_Tools_Migration::is_legacy_plugin_active() ) {
// Snapshot the old plugin's settings into the new keys WHILE it's still
// installed — once the user deletes it, its uninstall hook wipes them.
if ( is_admin() ) {
EMCP_Tools_Migration::migrate();
}
add_action(
'admin_notices',
function () {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
echo '<div class="notice notice-warning"><p>';
echo wp_kses(
__( '<strong>EMCP Tools:</strong> The previous “MCP Tools for Elementor” plugin (folder <code>elementor-mcp</code>) is still active. EMCP Tools has replaced it — please <strong>deactivate and delete</strong> the old plugin to finish the upgrade. Your settings and license carry over automatically. EMCP Tools stays paused until then.', 'emcp-tools' ),
array(
'strong' => array(),
'code' => array(),
)
);
echo '</p></div>';
}
);
// Bail before booting anything else (no constants, no Freemius, no abilities).
return;
}
// Plugin constants.
define( 'EMCP_TOOLS_VERSION', '3.7.0' );
define( 'EMCP_TOOLS_DIR', plugin_dir_path( __FILE__ ) );
define( 'EMCP_TOOLS_URL', plugin_dir_url( __FILE__ ) );
define( 'EMCP_TOOLS_BASENAME', plugin_basename( __FILE__ ) );
// Claim the WP\MCP namespace for our bundled MCP Adapter copy, at file-load —
// BEFORE any other plugin can autoload an adapter class. Other plugins bundle
// the adapter behind their own autoloaders (Rank Math SEO, …) and PHP allows
// only one class of a given name per request, so without this the namespace
// can shear across two adapter versions and the MCP session dies mid-request
// ("Session terminated", -32600). Lazy: registers a resolver, loads nothing.
require_once EMCP_TOOLS_DIR . 'includes/class-mcp-adapter-bootstrap.php';
EMCP_Tools_Adapter_Bootstrap::preload_bundled_namespace();
if ( ! function_exists( 'emcp_tools_fs' ) ) {
// Create a helper function for easy SDK access.
function emcp_tools_fs() {
global $emcp_tools_fs;
if ( ! isset( $emcp_tools_fs ) ) {
// Activate multisite network integration.
if ( ! defined( 'WP_FS__PRODUCT_30577_MULTISITE' ) ) {
define( 'WP_FS__PRODUCT_30577_MULTISITE', true );
}
// Include Freemius SDK.
require_once dirname( __FILE__ ) . '/includes/vendors/fremius/start.php';
// The premium build ships a `.emcp-pro` marker file at the plugin
// root; the free build does not. Freemius needs is_premium=true on
// the premium build so it shows the LICENSE-ACTIVATION flow (gated
// on is_premium()) instead of the free connect/opt-in screen. With
// it hardcoded false, the premium zip behaved like the free version
// and never offered license activation.
$emcp_tools_is_premium = file_exists( dirname( __FILE__ ) . '/.emcp-pro' );
$emcp_tools_fs = fs_dynamic_init( array(
'id' => '30577',
'slug' => 'emcp-tools',
'premium_slug' => 'emcp-pro',
'type' => 'plugin',
'public_key' => 'pk_2b2a026d5c27655581635abcd4556',
'is_premium' => $emcp_tools_is_premium,
'premium_suffix' => 'Pro',
'has_premium_version' => true,
'has_addons' => false,
'has_paid_plans' => true,
'is_org_compliant' => false,
'has_affiliation' => 'selected',
'menu' => array(
'slug' => 'emcp-tools',
'support' => false,
),
) );
}
return $emcp_tools_fs;
}
// Init Freemius.
emcp_tools_fs();
// Signal that SDK was initiated.
do_action( 'emcp_tools_fs_loaded' );
// Trim the Freemius-injected submenu items we surface elsewhere: Contact Us
// (Help & Support lives in the plugin header), Affiliation (shown in the
// header next to Changelog), and Pricing for licensed Pro users (free users
// keep the upgrade link). Freemius keeps the underlying pages reachable by
// URL, so the header links still work.
emcp_tools_fs()->add_filter(
'is_submenu_visible',
function ( $is_visible, $menu_id ) {
if ( 'contact' === $menu_id || 'affiliation' === $menu_id ) {
return false;
}
if ( 'pricing' === $menu_id && emcp_tools_fs()->can_use_premium_code() ) {
return false;
}
return $is_visible;
},
10,
2
);
}
// Uninstall cleanup runs via Freemius's after_uninstall action (uninstall.php
// was removed in v1.6.1 — Freemius rejects builds containing it).
require_once EMCP_TOOLS_DIR . 'includes/class-uninstaller.php';
if ( function_exists( 'emcp_tools_fs' ) ) {
emcp_tools_fs()->add_action( 'after_uninstall', array( 'EMCP_Tools_Uninstaller', 'run' ) );
}
/**
* Canonical "Upgrade to Pro" URL — the external pricing page on the EMCP Tools
* website. Used by every upgrade CTA in the plugin admin so users land on the
* public pricing page (with full plan comparison + FAQ) rather than Freemius's
* bundled in-admin pricing iframe.
*
* @since 1.7.1
*
* @return string
*/
function emcp_tools_upgrade_url(): string {
return 'https://emcptools.com/pricing';
}
// Hand off to the bootstrap (loads classes + wires hooks) once dependencies
// like Elementor are available.
require_once EMCP_TOOLS_DIR . 'includes/class-bootstrap.php';
add_action( 'plugins_loaded', array( 'EMCP_Tools_Bootstrap', 'boot' ), 20 );