Guides

Creating Your First Module

Beginner~10 min

Build 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.

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-CLI
wp meteorack scaffold my-module

Generated structure

The scaffold command creates a layout that matches the runtime loader and asset pipeline.

Directory structure
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.php

module.json

The runtime parses module.json before boot. Keep it focused on identity, compatibility, capabilities, dependencies, and entrypoints.

module.json
{
  "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.

bootstrap.php
<?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-CLI
wp meteorack modules activate my-module
wp meteorack modules list