is_plugin_active() || $this->host_mcp_enabled() ) { return $todo; } return array( 'label' => __( "Elementor's own MCP server is switched off. Your abilities work without it; turn it on only if you want an AI client to connect to Elementor's endpoint.", 'acrossai-abilities-manager' ), 'url' => admin_url( 'admin.php?page=elementor-mcp' ), ); } /** * Ask Elementor's MCP module to register its abilities. * * `Module::register_abilities()` is public and does nothing but loop its own registry calling * `register()` on each entry, so this invokes exactly what Elementor invokes — no * reimplementation to drift, and no ability of theirs declared by us. * * The one thing that makes this possible is an asymmetry in Elementor's own module: the * `elementor` ability CATEGORY is registered unconditionally (`module.php:150`, outside the * `if`), while the abilities are not. WP core silently rejects an ability whose category is * unregistered, so without that the registration would no-op and this whole approach would * fail quietly. * * Resolved lazily rather than captured when the hook was added: `maybe_enable()` runs at * `plugins_loaded` P20 ({@see AcrossAI_Integration_Ability_Base::enable_hook()}) and Elementor * builds its modules later, so there is no instance to hold at that point. * * Every dereference is guarded and the call is wrapped. This reaches into another plugin's * internals, so the failure mode must be "Elementor's abilities are absent", never a fatal on * a site that updated Elementor. * * @since 0.0.42 * @return void */ public function register_host_abilities(): void { // Elementor registers its own set when its switch is on. Doing it again would mean 27 // "already registered" notices on every request for no gain. if ( $this->host_mcp_enabled() ) { return; } try { $module = $this->host_module(); if ( ! is_object( $module ) || ! is_callable( array( $module, 'register_abilities' ) ) ) { return; } $module->register_abilities(); /* * Belt and braces for the priority note on `enable_filter()`. Nothing should have * resolved the grouping this early, so this is normally a no-op that costs one null * assignment. If something ever does resolve it first, this turns a silent "Elementor's * abilities are missing from every Toolset" into a rebuild. */ AcrossAI_Ability_Group::flush(); } catch ( \Throwable $e ) { if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( sprintf( 'AcrossAI integration [elementor] could not register the host\'s abilities: %s', $e->getMessage() ) ); } } } /** * Whether Elementor's own site-wide MCP exposure is switched on. * * Asks Elementor rather than reading `elementor_mcp_enabled` directly, so this answer follows * whatever Elementor decides the option means — its own settings controller treats an absent * value as off, despite a docblock there claiming the opposite. * * @since 0.0.42 * @return bool */ protected function host_mcp_enabled(): bool { if ( ! is_callable( array( '\Elementor\Modules\Mcp\Module', 'is_site_mcp_exposure_enabled' ) ) ) { return false; } return (bool) \Elementor\Modules\Mcp\Module::is_site_mcp_exposure_enabled(); } /** * Elementor's MCP module, or null when it cannot be reached. * * Resolved through Elementor's modules manager rather than constructed: the module owns its * registry, and building a second one would register ability objects Elementor never made. * * Every dereference is guarded. This walks another plugin's object graph, so the failure mode * must be "Elementor's abilities are absent", never a fatal on a site that updated Elementor. * * @since 0.0.42 * @return object|null */ protected function host_module(): ?object { if ( ! class_exists( '\Elementor\Plugin' ) ) { return null; } $plugin = \Elementor\Plugin::$instance; if ( ! is_object( $plugin ) || ! isset( $plugin->modules_manager ) || ! is_object( $plugin->modules_manager ) ) { return null; } if ( ! is_callable( array( $plugin->modules_manager, 'get_modules' ) ) ) { return null; } $module = $plugin->modules_manager->get_modules( 'mcp' ); return is_object( $module ) ? $module : null; } /** * What switching this on unlocks. * * Display-only, and deliberately not the full 27: this names the groups rather than every slug, * because Elementor's set moves between releases and a stale list here would describe abilities * that no longer exist. The live set is always what `toolset/elementor` discover returns. * * @since 0.0.42 * @return array */ protected function abilities(): array { return array( array( 'slug' => 'elementor/build-composition', 'label' => __( 'Build and edit V4 element trees', 'acrossai-abilities-manager' ), 'description' => __( 'Elementor\'s own authoring path for atomic (V4) elements, plus publishing and preview links.', 'acrossai-abilities-manager' ), ), array( 'slug' => 'elementor/manage-global-variable', 'label' => __( 'V4 global design system', 'acrossai-abilities-manager' ), 'description' => __( 'Global variables, global CSS classes and site-wide default styles on the active kit.', 'acrossai-abilities-manager' ), ), array( 'slug' => 'elementor/list-widget-schemas', 'label' => __( 'Widget schemas and guidance', 'acrossai-abilities-manager' ), 'description' => __( 'Per-widget JSON Schemas, dynamic tags, component and asset catalogues, and Elementor\'s own design guidance.', 'acrossai-abilities-manager' ), ), ); } }