PluginProbe
Elementor Website Builder – more than just a page builder / trunk
Elementor Website Builder – more than just a page builder vtrunk
4.3.3 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 All 456 releases
← All changes | modules/mcp/module.php +96 -4 4.3.0-beta1 → trunk View file →
@@ -2,8 +2,11 @@
2 2
3 3 namespace Elementor\Modules\Mcp;
4 4
5 5 use Elementor\Core\Base\Module as BaseModule;
6 +use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
7 +use Elementor\MCP\Composer\Admin\McpSettingsController;
8 +use Elementor\MCP\Composer\Admin\Page as Mcp_Admin_Page;
6 9 use Elementor\MCP\Composer\Mcp\Registry as Shared_Registry;
7 10 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
8 11 use Elementor\Modules\Mcp\Abilities\Abstract_Ability;
9 12 use Elementor\Modules\Mcp\AdminMenuItems\Editor_One_Mcp_Menu;
@@ -10,8 +13,9 @@
10 13 use Elementor\Modules\Mcp\Preview\Public_Preview_Handler;
11 14 use Elementor\Modules\Mcp\Registry\Ability_Registry;
12 15 use Elementor\Modules\Mcp\RestApi\Mcp_Proxy_REST_API;
13 16 use Elementor\Modules\Mcp\Utils\Editor_Sync_State;
17 +use Elementor\Utils;
14 18 use WP\MCP\Core\McpAdapter;
15 19
16 20 if ( ! defined( 'ABSPATH' ) ) {
17 21 exit;
@@ -19,8 +23,11 @@
19 23
20 24 class Module extends BaseModule {
21 25
22 26 const ANALYTICS_REGISTRAR_HANDLE = 'elementor-mcp-analytics-registrar';
27 + const PROMOTION_REGISTRAR_HANDLE = 'elementor-mcp-promotion-registrar';
28 + const MCP_PROMOTION_UPGRADE_URL = 'https://go.elementor.com/go-pro-mcp-connector-page-upgrade/';
29 + const MCP_PROMOTION_ALLOWED_DOMAIN = 'elementor.com';
23 30
24 31 private Ability_Registry $registry;
25 32
26 33 public function get_name() {
@@ -30,14 +37,91 @@
30 37 public function enqueue_analytics_registrar(): void {
31 38 wp_enqueue_script(
32 39 self::ANALYTICS_REGISTRAR_HANDLE,
33 40 $this->get_js_assets_url( 'mcp-analytics-registrar' ),
34 - [ 'elementor-common', \Elementor\MCP\Composer\Admin\Page::SCRIPT_HANDLE ],
41 + [ 'elementor-common', Mcp_Admin_Page::SCRIPT_HANDLE ],
35 42 ELEMENTOR_VERSION,
36 43 true
37 44 );
38 45 }
39 46
47 + public function enqueue_promotion_registrar(): void {
48 + if ( ! $this->should_enqueue_mcp_admin_promotion() ) {
49 + return;
50 + }
51 +
52 + wp_enqueue_script(
53 + self::PROMOTION_REGISTRAR_HANDLE,
54 + $this->get_js_assets_url( 'mcp-promotion-registrar' ),
55 + [
56 + 'elementor-common',
57 + Mcp_Admin_Page::SCRIPT_HANDLE,
58 + 'react',
59 + 'react-dom',
60 + 'wp-i18n',
61 + ],
62 + ELEMENTOR_VERSION,
63 + true
64 + );
65 +
66 + wp_localize_script(
67 + self::PROMOTION_REGISTRAR_HANDLE,
68 + 'elementorMcpPromotionConfig',
69 + [
70 + 'upgradeUrl' => $this->get_promotion_upgrade_url(),
71 + ]
72 + );
73 +
74 + wp_set_script_translations( self::PROMOTION_REGISTRAR_HANDLE, 'elementor' );
75 + }
76 +
77 + private function should_enqueue_mcp_admin_promotion(): bool {
78 + if ( ! current_user_can( 'manage_options' ) ) {
79 + return false;
80 + }
81 +
82 + if ( ! class_exists( Utils::class ) ) {
83 + return false;
84 + }
85 +
86 + if ( Utils::has_pro() && Utils::is_license_active() ) {
87 + return false;
88 + }
89 +
90 + return true;
91 + }
92 +
93 + private function get_promotion_upgrade_url(): string {
94 + $promotion_data = Filtered_Promotions_Manager::get_filtered_promotion_data(
95 + [ 'upgrade_url' => self::MCP_PROMOTION_UPGRADE_URL ],
96 + 'elementor/mcp/custom_promotion',
97 + 'upgrade_url'
98 + );
99 +
100 + $upgrade_url = $promotion_data['upgrade_url'] ?? '';
101 +
102 + return $this->is_allowed_promotion_url( $upgrade_url )
103 + ? $upgrade_url
104 + : self::MCP_PROMOTION_UPGRADE_URL;
105 + }
106 +
107 + private function is_allowed_promotion_url( $url ): bool {
108 + if ( ! is_string( $url ) ) {
109 + return false;
110 + }
111 +
112 + $host = wp_parse_url( $url, PHP_URL_HOST );
113 +
114 + if ( ! is_string( $host ) ) {
115 + return false;
116 + }
117 +
118 + $host = strtolower( $host );
119 +
120 + return self::MCP_PROMOTION_ALLOWED_DOMAIN === $host
121 + || str_ends_with( $host, '.' . self::MCP_PROMOTION_ALLOWED_DOMAIN );
122 + }
123 +
40 124 public static function is_active() {
41 125 return class_exists( McpAdapter::class ) &&
42 126 function_exists( 'wp_register_ability' ) &&
43 127 class_exists( Shared_Registry::class );
@@ -42,8 +126,12 @@
42 126 function_exists( 'wp_register_ability' ) &&
43 127 class_exists( Shared_Registry::class );
44 128 }
45 129
130 + public static function is_site_mcp_exposure_enabled(): bool {
131 + return McpSettingsController::is_enabled();
132 + }
133 +
46 134 public function __construct() {
47 135 parent::__construct();
48 136
49 137 $this->registry = self::build_core_registry();
@@ -51,16 +139,20 @@
51 139 ( new Mcp_Proxy_REST_API( $this->registry ) )->register_hooks();
52 140 ( new Public_Preview_Handler() )->register();
53 141 ( new Editor_Sync_State() )->register_hooks();
54 142
55 - if ( ! $this->is_active() ) {
143 + if ( ! self::is_active() ) {
56 144 return;
57 145 }
58 146
59 - add_action( 'wp_abilities_api_categories_init', [ $this, 'register_ability_category' ] );
60 - add_action( 'wp_abilities_api_init', [ $this, 'register_abilities' ] );
61 147 add_action( 'init', [ $this, 'register_shared_registry_slugs' ], 5 );
62 148 add_action( 'elementor/editor-one/menu/register', [ $this, 'register_editor_one_menu' ], Editor_One_Mcp_Menu::REGISTER_PRIORITY_AFTER_SUBMISSIONS );
149 +
150 + add_action( 'wp_abilities_api_categories_init', [ $this, 'register_ability_category' ] );
151 +
152 + if ( self::is_site_mcp_exposure_enabled() ) {
153 + add_action( 'wp_abilities_api_init', [ $this, 'register_abilities' ] );
154 + }
63 155 }
64 156
65 157 public function registry(): Ability_Registry {
66 158 return $this->registry;