Creating Your First Module
Beginner~10 minBuild a Meteorack module from the current scaffold: manifest, bootstrap, activation, and verification.
Prerequisites
- A WordPress site with the Meteorack runtime active.
- WP-CLI access on the target environment.
- Basic familiarity with editing PHP and JSON files.
What You Will Finish With
- Scaffold a module with the canonical runtime directory layout.
- Return an AbstractModule instance from bootstrap.php.
- Activate the module and confirm the runtime recognizes it.
You Will Use
Related Docs
Scaffold the module
The runtime ships with a scaffold command that creates the canonical directory structure, bootstrap file, React entry, tests, and Vite config. Start there instead of inventing your own layout.
wp meteorack scaffold my-moduleGenerated structure
The scaffold command creates a layout that matches the runtime loader and asset pipeline.
wp-content/meteorack/modules/my-module/
├── module.json
├── bootstrap.php
├── includes/
│ ├── class-module.php
│ └── class-rest-routes.php
├── src/
│ ├── components/ExampleWidget.tsx
│ └── pages/MainPage.tsx
├── assets/
│ ├── package.json
│ └── vite.config.ts
├── migrations/
└── tests/
├── js/MainPage.test.tsx
└── php/ModuleTest.phpmodule.json
The runtime parses module.json before boot. Keep it focused on identity, compatibility, capabilities, dependencies, and entrypoints.
{
"slug": "my-module",
"name": "My Module",
"version": "1.0.0",
"min_sdk_version": "1.0.0",
"max_tested_sdk_version": "1.0.0",
"capabilities": ["manage_options"],
"requires": [],
"priority": 10,
"provider": "acme",
"entrypoints": {
"admin": ["my-module"]
},
"description": "My first Meteorack module"
}bootstrap.php
The runtime loads bootstrap.php and expects it to return an AbstractModule instance. onSdkReady() is the primary hook for wiring routes, settings, cron, and startup logic.
<?php
declare(strict_types=1);
use Meteorack\Sdk\Core\SdkContext;
use Meteorack\Sdk\RuntimeWp\AbstractModule;
class MyModule extends AbstractModule
{
public function getSlug(): string { return 'my-module'; }
public function getName(): string { return 'My Module'; }
public function getVersion(): string { return '1.0.0'; }
public function onSdkReady(SdkContext $ctx): void
{
parent::onSdkReady($ctx);
$ctx->logger()->info('my_module.boot', []);
$this->setSetting('enabled', true);
}
}
return new MyModule();Activate and verify
Activation validates module.json, capability requirements, dependencies, and signature rules before marking the module active.
wp meteorack modules activate my-module
wp meteorack modules list