| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | |
| 16 | 16 | use ZipAI\MCP\Classes\Core\Container; |
| 17 | 17 | use ZipAI\MCP\Classes\Providers\Core_Service_Provider; |
| 18 | 18 | use ZipAI\MCP\Classes\Providers\Abilities_Service_Provider; |
| 19 | -use ZipAI\MCP\Classes\Cli\CLI_Commands; | |
| 20 | 19 | use ZipAI\MCP\Classes\Core\Helper; |
| 20 | +use ZipAI\MCP\Classes\Core\Service_Provider; | |
| 21 | 21 | |
| 22 | 22 | if ( ! class_exists( '\ZipAI\MCP\Plugin' ) ) { |
| 23 | 23 | /** |
| 24 | 24 | * Plugin Class |
| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | /** |
| 31 | 31 | * Instance |
| 32 | 32 | * |
| 33 | 33 | * @access private |
| 34 | - * @var object Class Instance. | |
| 34 | + * @var self|null Class Instance. | |
| 35 | 35 | * @since 1.0.0 |
| 36 | 36 | */ |
| 37 | 37 | private static $instance; |
| 38 | 38 | |
| @@ -45,9 +45,9 @@ | ||
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Service Providers. |
| 48 | 48 | * |
| 49 | - * @var array | |
| 49 | + * @var array<int, Service_Provider> | |
| 50 | 50 | */ |
| 51 | 51 | protected $providers = array(); |
| 52 | 52 | |
| 53 | 53 | /** |
| @@ -68,8 +68,12 @@ | ||
| 68 | 68 | * |
| 69 | 69 | * @since 1.0.0 |
| 70 | 70 | */ |
| 71 | 71 | public function __construct() { |
| 72 | + // Must be first — everything below (Container included) autoloads | |
| 73 | + // through it. | |
| 74 | + spl_autoload_register( array( __CLASS__, 'autoload' ) ); | |
| 75 | + | |
| 72 | 76 | $this->container = new Container(); |
| 73 | 77 | |
| 74 | 78 | $this->define_constants(); |
| 75 | 79 | |
| @@ -79,9 +83,8 @@ | ||
| 79 | 83 | // Boot Services. |
| 80 | 84 | add_action( 'plugins_loaded', array( $this, 'boot_services' ), 5 ); |
| 81 | 85 | |
| 82 | 86 | $this->setup_activation_hooks(); |
| 83 | - $this->register_cli_commands(); | |
| 84 | 87 | |
| 85 | 88 | // Site scanner — event-driven memory enrichment (after auth). |
| 86 | 89 | // \ZipAI\MCP\Classes\Core\Site_Scanner::register_hooks(); // TODO: class not yet committed. |
| 87 | 90 | |
| @@ -95,14 +98,75 @@ | ||
| 95 | 98 | // path (server-side ability, browser-proxied REST, admin UI, |
| 96 | 99 | // WP-CLI). Idempotent + slug-map gated. |
| 97 | 100 | \ZipAI\MCP\Classes\Core\Plugin_Abilities_Toggler::init(); |
| 98 | 101 | |
| 102 | + // Imported-chrome reader — renders imported header/footer template | |
| 103 | + // parts verbatim on ANY classic theme via a `template_include` | |
| 104 | + // canvas takeover when `zipai_chrome_mode === 'takeover'` (written | |
| 105 | + // by the importer) or a page carries the standalone marker meta. | |
| 106 | + // Inert on block themes (FSE renders the parts natively) and on | |
| 107 | + // sites that never imported. Registering the option doubles as the | |
| 108 | + // backend's capability probe. | |
| 109 | + \ZipAI\MCP\Classes\Core\Imported_Chrome::init(); | |
| 110 | + | |
| 99 | 111 | // Privacy policy disclosure (WordPress Guideline 7). |
| 100 | 112 | add_action( 'admin_init', array( $this, 'add_privacy_policy_content' ) ); |
| 101 | 113 | } |
| 102 | 114 | |
| 103 | 115 | /** |
| 116 | + * Plugin autoloader — single runtime autoloader for everything the | |
| 117 | + * plugin ships: its own classes (inc/) and the bundled | |
| 118 | + * composer-managed libraries in lib/ (mcp-adapter, php-mcp-schema). | |
| 119 | + * Composer's vendor/autoload.php is dev-tooling only and is never | |
| 120 | + * loaded at runtime. | |
| 121 | + * | |
| 122 | + * @param string $class Fully qualified class name to load. | |
| 123 | + * @return void | |
| 124 | + */ | |
| 125 | + public static function autoload( string $class ): void { | |
| 126 | + // Own classes — WordPress-style file names: namespace path | |
| 127 | + // lowercased, CamelCase split with hyphens, underscores as hyphens. | |
| 128 | + // ZipAI\MCP\Classes\Abilities\Core\RunWpCli -> inc/abilities/core/run-wp-cli.php. | |
| 129 | + $own_prefix = 'ZipAI\MCP\Classes\\'; | |
| 130 | + if ( 0 === strpos( $class, $own_prefix ) ) { | |
| 131 | + $filename = preg_replace( | |
| 132 | + array( '/([a-z])([A-Z])/', '/_/', '/\\\\/' ), | |
| 133 | + array( '$1-$2', '-', '/' ), | |
| 134 | + substr( $class, strlen( $own_prefix ) ) | |
| 135 | + ); | |
| 136 | + | |
| 137 | + if ( is_string( $filename ) ) { | |
| 138 | + $file = __DIR__ . '/inc/' . strtolower( $filename ) . '.php'; | |
| 139 | + | |
| 140 | + if ( is_readable( $file ) ) { | |
| 141 | + require_once $file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Path is derived from the class name. | |
| 142 | + } | |
| 143 | + } | |
| 144 | + return; | |
| 145 | + } | |
| 146 | + | |
| 147 | + // Bundled lib/ packages — strict PSR-4, directory case preserved. | |
| 148 | + $psr4 = array( | |
| 149 | + 'WP\MCP\\' => 'lib/mcp-adapter/includes/', | |
| 150 | + 'WP\McpSchema\\' => 'lib/php-mcp-schema/src/', | |
| 151 | + ); | |
| 152 | + | |
| 153 | + foreach ( $psr4 as $prefix => $base_dir ) { | |
| 154 | + if ( 0 === strpos( $class, $prefix ) ) { | |
| 155 | + $file = __DIR__ . '/' . $base_dir . str_replace( '\\', '/', substr( $class, strlen( $prefix ) ) ) . '.php'; | |
| 156 | + | |
| 157 | + if ( is_readable( $file ) ) { | |
| 158 | + require_once $file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Path is derived from a fixed prefix map. | |
| 159 | + } | |
| 160 | + return; | |
| 161 | + } | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 104 | 166 | * Register Service Providers. |
| 167 | + * | |
| 168 | + * @return void | |
| 105 | 169 | */ |
| 106 | 170 | private function register_services() { |
| 107 | 171 | $this->providers[] = new Core_Service_Provider( $this->container ); |
| 108 | 172 | $this->providers[] = new Abilities_Service_Provider( $this->container ); |
| @@ -113,8 +177,10 @@ | ||
| 113 | 177 | } |
| 114 | 178 | |
| 115 | 179 | /** |
| 116 | 180 | * Boot Service Providers. |
| 181 | + * | |
| 182 | + * @return void | |
| 117 | 183 | */ |
| 118 | 184 | public function boot_services() { |
| 119 | 185 | $this->load_vendor_dependencies(); |
| 120 | 186 | |
| @@ -132,14 +198,14 @@ | ||
| 132 | 198 | public function define_constants() { |
| 133 | 199 | define( 'ZIPAI_MCP_FILE', __DIR__ . '/zip-ai.php' ); |
| 134 | 200 | define( 'ZIPAI_MCP_DIR', plugin_dir_path( ZIPAI_MCP_FILE ) ); |
| 135 | 201 | define( 'ZIPAI_MCP_URL', plugins_url( '/', ZIPAI_MCP_FILE ) ); |
| 136 | - define( 'ZIPAI_MCP_VERSION', '0.0.5'); | |
| 202 | + define( 'ZIPAI_MCP_VERSION', '0.0.10' ); | |
| 137 | 203 | define( 'ZIPAI_MCP_MENU_SLUG', 'zip-ai' ); |
| 138 | 204 | |
| 139 | - // Base URL for ZIP AI credit server (Laravel app). | |
| 205 | + // Base URL for ZIP AI credit server. | |
| 140 | 206 | if ( ! defined( 'ZIPAI_MCP_BASE_URL' ) ) { |
| 141 | - define( 'ZIPAI_MCP_BASE_URL', 'https://credits.startertemplates.com' ); | |
| 207 | + define( 'ZIPAI_MCP_BASE_URL', 'https://credits.zipwp.com' ); | |
| 142 | 208 | } |
| 143 | 209 | |
| 144 | 210 | if ( ! defined( 'ZIPAI_MCP_MIDDLEWARE' ) ) { |
| 145 | 211 | define( 'ZIPAI_MCP_MIDDLEWARE', 'https://app.zipwp.com/auth/' ); |
| @@ -148,13 +214,12 @@ | ||
| 148 | 214 | if ( ! defined( 'ZIPAI_API_BASE' ) ) { |
| 149 | 215 | define( 'ZIPAI_API_BASE', 'https://api.zipwp.com/api/' ); |
| 150 | 216 | } |
| 151 | 217 | |
| 152 | - // Brain base URL for direct-to-brain calls (e.g. inline-edit), | |
| 153 | - // bypassing the Laravel relay. Override via wp-config.php or the | |
| 154 | - // `zipai_brain_url` filter. | |
| 218 | + // Base URL for direct server calls (e.g. inline-edit). Override via | |
| 219 | + // wp-config.php or the `zipai_brain_url` filter. | |
| 155 | 220 | if ( ! defined( 'ZIPAI_BRAIN_URL' ) ) { |
| 156 | - define( 'ZIPAI_BRAIN_URL', 'https://brain.startertemplates.com' ); | |
| 221 | + define( 'ZIPAI_BRAIN_URL', 'https://brain.zipwp.com' ); | |
| 157 | 222 | } |
| 158 | 223 | |
| 159 | 224 | // API endpoint for credit server. |
| 160 | 225 | if ( ! defined( 'ZIPAI_MCP_CREDIT_SERVER_API' ) ) { |
| @@ -159,30 +224,30 @@ | ||
| 159 | 224 | // API endpoint for credit server. |
| 160 | 225 | if ( ! defined( 'ZIPAI_MCP_CREDIT_SERVER_API' ) ) { |
| 161 | 226 | define( 'ZIPAI_MCP_CREDIT_SERVER_API', ZIPAI_MCP_BASE_URL . '/api/' ); |
| 162 | 227 | } |
| 163 | - | |
| 164 | 228 | } |
| 165 | 229 | |
| 166 | 230 | /** |
| 167 | - * Load vendor dependencies (mcp-adapter). | |
| 231 | + * Load bundled dependencies (mcp-adapter). | |
| 168 | 232 | * |
| 169 | 233 | * @since 1.0.0 |
| 170 | 234 | * @return void |
| 171 | 235 | */ |
| 172 | 236 | private function load_vendor_dependencies() { |
| 173 | - // Initialize mcp-adapter plugin if not already loaded. The library | |
| 174 | - // self-bootstraps (defines its own constants, runs its autoloader and | |
| 175 | - // calls \WP\MCP\Plugin::instance()) on require. Since it's bundled as a | |
| 176 | - // Composer dependency, its classes are already registered via our root | |
| 177 | - // vendor/autoload.php and it has no nested vendor/ of its own — so we | |
| 178 | - // tell it to skip its self-autoload, else it prints a false "Composer | |
| 179 | - // autoloader was not found" admin notice and bails before Plugin::instance(). | |
| 237 | + // Initialize mcp-adapter plugin if not already loaded. It is vendored | |
| 238 | + // in lib/mcp-adapter (git-committed) and its classes are served by the | |
| 239 | + // plugin autoloader (Plugin::autoload). The library self-bootstraps | |
| 240 | + // (defines its own constants, runs its autoloader and calls | |
| 241 | + // \WP\MCP\Plugin::instance()) on require, and its self-autoload expects | |
| 242 | + // a nested vendor/ it doesn't have — so we tell it to skip it, else it | |
| 243 | + // prints a false "Composer autoloader was not found" admin notice and | |
| 244 | + // bails before Plugin::instance(). | |
| 180 | 245 | if ( ! defined( 'WP_MCP_AUTOLOAD' ) ) { |
| 181 | 246 | define( 'WP_MCP_AUTOLOAD', false ); |
| 182 | 247 | } |
| 183 | - if ( ! defined( 'WP_MCP_VERSION' ) && file_exists( ZIPAI_MCP_DIR . 'vendor/wordpress/mcp-adapter/mcp-adapter.php' ) ) { | |
| 184 | - require_once ZIPAI_MCP_DIR . 'vendor/wordpress/mcp-adapter/mcp-adapter.php'; | |
| 248 | + if ( ! defined( 'WP_MCP_VERSION' ) && file_exists( ZIPAI_MCP_DIR . 'lib/mcp-adapter/mcp-adapter.php' ) ) { | |
| 249 | + require_once ZIPAI_MCP_DIR . 'lib/mcp-adapter/mcp-adapter.php'; | |
| 185 | 250 | } |
| 186 | 251 | } |
| 187 | 252 | |
| 188 | 253 | /** |
| @@ -205,9 +270,9 @@ | ||
| 205 | 270 | public function plugin_activated() { |
| 206 | 271 | // Add the required capability to administrator role. |
| 207 | 272 | $this->add_plugin_capabilities(); |
| 208 | 273 | |
| 209 | - // Generate and register shared secret with Laravel on activation. | |
| 274 | + // Generate and register shared secret with the server on activation. | |
| 210 | 275 | $this->register_hmac_secret(); |
| 211 | 276 | } |
| 212 | 277 | |
| 213 | 278 | /** |
| @@ -226,9 +291,9 @@ | ||
| 226 | 291 | |
| 227 | 292 | /** |
| 228 | 293 | * Suggest privacy policy content per WordPress Guideline 7. |
| 229 | 294 | * |
| 230 | - * Discloses what data is sent to the ZIP AI SaaS platform. | |
| 295 | + * Discloses what data is sent to the ZIP AI cloud service. | |
| 231 | 296 | * |
| 232 | 297 | * @since 1.0.0 |
| 233 | 298 | * @return void |
| 234 | 299 | */ |
| @@ -306,9 +371,9 @@ | ||
| 306 | 371 | } |
| 307 | 372 | } |
| 308 | 373 | |
| 309 | 374 | /** |
| 310 | - * Register HMAC shared secret with Laravel server. | |
| 375 | + * Register HMAC shared secret with the server. | |
| 311 | 376 | * |
| 312 | 377 | * @since 1.0.0 |
| 313 | 378 | * @return void |
| 314 | 379 | */ |
| @@ -321,22 +386,8 @@ | ||
| 321 | 386 | // Note: Error logging removed for production. |
| 322 | 387 | unset( $registration_result ); |
| 323 | 388 | } |
| 324 | 389 | } |
| 325 | - } | |
| 326 | - | |
| 327 | - /** | |
| 328 | - * Register WP-CLI commands. | |
| 329 | - * | |
| 330 | - * @since 1.0.0 | |
| 331 | - * @return void | |
| 332 | - */ | |
| 333 | - private function register_cli_commands() { | |
| 334 | - if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) { | |
| 335 | - return; | |
| 336 | - } | |
| 337 | - | |
| 338 | - \WP_CLI::add_command( 'zip-ai', CLI_Commands::class ); | |
| 339 | 390 | } |
| 340 | 391 | } |
| 341 | 392 | |
| 342 | 393 | /** |