Examples

Three real-world workflows that demonstrate how the MCP tools fit together.


Example 1: Contact Manager Plugin

A plugin that stores contacts in a custom table, exposes a REST API, and provides admin settings.

Step 1 -- Scaffold the plugin

scaffold_plugin({
  "name": "Contact Manager",
  "slug": "contact-manager",
  "namespace": "MyVendor\\ContactManager",
  "prefix": "cm_",
  "textDomain": "contact-manager"
})

Step 2 -- Add the Contact CRUD module

scaffold_crud_module({
  "name": "Contact",
  "fields": [
    { "name": "first_name", "type": "string" },
    { "name": "last_name", "type": "string" },
    { "name": "email", "type": "string" },
    { "name": "phone", "type": "string", "nullable": true },
    { "name": "company", "type": "string", "nullable": true },
    { "name": "notes", "type": "text", "nullable": true },
    { "name": "status", "type": "string", "default": "active" }
  ],
  "hasRest": true,
  "hasViews": true
})

Step 3 -- Add REST endpoints

scaffold_rest_module({
  "name": "Contact",
  "methods": ["index", "show", "store", "update", "delete"]
})

Step 4 -- Add admin settings

scaffold_settings_page({
  "name": "Contact Settings",
  "sections": [
    {
      "id": "general",
      "title": "General Settings",
      "fields": [
        { "name": "per_page", "type": "number", "label": "Contacts Per Page", "default": 20 },
        { "name": "enable_api", "type": "checkbox", "label": "Enable Public API" }
      ]
    },
    {
      "id": "notifications",
      "title": "Notification Settings",
      "fields": [
        { "name": "notify_email", "type": "email", "label": "Notification Email" },
        { "name": "notify_on_create", "type": "checkbox", "label": "Notify on New Contact" }
      ]
    }
  ],
  "capability": "manage_options"
})

Resulting file tree

contact-manager/
|-- contact-manager.php
|-- bootstrap.php
|-- composer.json
|-- config/
|   +-- app.php
|-- database/
|   +-- migrations/
|       +-- create_contacts_table.php
|-- routes/
|   |-- admin.php
|   |-- ajax.php
|   +-- rest.php
|-- src/
|   |-- PluginContext.php
|   |-- Lifecycle.php
|   |-- Http/
|   |   +-- Controllers/
|   |       |-- ContactController.php
|   |       +-- ContactRestController.php
|   |-- Models/
|   |   +-- Contact.php
|   |-- Providers/
|   |   |-- ContactServiceProvider.php
|   |   +-- SettingsServiceProvider.php
|   +-- Settings/
|       +-- ContactSettingsPage.php
+-- resources/
    +-- views/
        +-- contacts/
            |-- index.php
            |-- create.php
            |-- edit.php
            +-- show.php

Example 2: WooCommerce Payment Gateway

A plugin that adds a custom payment gateway to WooCommerce.

Step 1 -- Scaffold the plugin

scaffold_plugin({
  "name": "MyPlugin Pay",
  "slug": "myplugin-pay",
  "namespace": "MyVendor\\MyPluginPay",
  "prefix": "mpp_",
  "textDomain": "myplugin-pay"
})

Step 2 -- Add the payment gateway

woo_scaffold_gateway({
  "name": "MyPluginGateway",
  "title": "MyPlugin Pay",
  "description": "Accept payments via MyPlugin Pay"
})

Generated gateway class (excerpt)

<?php

namespace MyVendor\MyPluginPay\WooCommerce;

use WC_Payment_Gateway;

class MyPluginGateway extends WC_Payment_Gateway
{
    public function __construct()
    {
        $this->id                 = 'myplugin_pay';
        $this->method_title       = __('MyPlugin Pay', 'myplugin-pay');
        $this->method_description = __('Accept payments via MyPlugin Pay', 'myplugin-pay');
        $this->has_fields         = true;
        $this->supports           = ['products', 'refunds'];

        $this->init_form_fields();
        $this->init_settings();

        $this->title   = $this->get_option('title');
        $this->enabled = $this->get_option('enabled');

        add_action(
            'woocommerce_update_options_payment_gateways_' . $this->id,
            [$this, 'process_admin_options']
        );
    }

    public function init_form_fields(): void
    {
        $this->form_fields = [
            'enabled' => [
                'title'   => __('Enable/Disable', 'myplugin-pay'),
                'type'    => 'checkbox',
                'label'   => __('Enable MyPlugin Pay', 'myplugin-pay'),
                'default' => 'no',
            ],
            'title' => [
                'title'       => __('Title', 'myplugin-pay'),
                'type'        => 'text',
                'description' => __('Title shown at checkout.', 'myplugin-pay'),
                'default'     => __('MyPlugin Pay', 'myplugin-pay'),
            ],
            'api_key' => [
                'title' => __('API Key', 'myplugin-pay'),
                'type'  => 'text',
            ],
            'secret_key' => [
                'title' => __('Secret Key', 'myplugin-pay'),
                'type'  => 'password',
            ],
            'sandbox' => [
                'title'   => __('Sandbox Mode', 'myplugin-pay'),
                'type'    => 'checkbox',
                'label'   => __('Enable sandbox mode', 'myplugin-pay'),
                'default' => 'yes',
            ],
        ];
    }

    public function process_payment($order_id): array
    {
        $order = wc_get_order($order_id);

        // TODO: Implement payment API call here.

        $order->payment_complete();
        WC()->cart->empty_cart();

        return [
            'result'   => 'success',
            'redirect' => $this->get_return_url($order),
        ];
    }

    public function process_refund($order_id, $amount = null, $reason = ''): bool
    {
        // TODO: Implement refund API call here.

        return true;
    }
}

Generated service provider (excerpt)

<?php

namespace MyVendor\MyPluginPay\Providers;

use WPZylos\Framework\Support\ServiceProvider;
use MyVendor\MyPluginPay\WooCommerce\MyPluginGateway;

class MyPluginGatewayServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        //
    }

    public function boot(): void
    {
        add_filter('woocommerce_payment_gateways', function (array $gateways) {
            $gateways[] = MyPluginGateway::class;
            return $gateways;
        });
    }
}

Example 3: Blueprint-Driven Generation

Build an entire plugin from a single blueprint specification.

The blueprint

build_from_blueprint({
  "spec": {
    "plugin": {
      "name": "Task Tracker",
      "slug": "task-tracker",
      "namespace": "MyVendor\\TaskTracker",
      "prefix": "tt_",
      "textDomain": "task-tracker",
      "description": "A task and project management plugin for WordPress."
    },
    "models": [
      {
        "name": "Project",
        "fields": [
          { "name": "title", "type": "string" },
          { "name": "description", "type": "text", "nullable": true },
          { "name": "status", "type": "string", "default": "active" },
          { "name": "owner_id", "type": "bigInteger" },
          { "name": "due_date", "type": "date", "nullable": true }
        ]
      },
      {
        "name": "Task",
        "fields": [
          { "name": "project_id", "type": "bigInteger" },
          { "name": "title", "type": "string" },
          { "name": "description", "type": "text", "nullable": true },
          { "name": "priority", "type": "string", "default": "medium" },
          { "name": "status", "type": "string", "default": "open" },
          { "name": "assignee_id", "type": "bigInteger", "nullable": true },
          { "name": "due_date", "type": "date", "nullable": true }
        ]
      },
      {
        "name": "Comment",
        "fields": [
          { "name": "task_id", "type": "bigInteger" },
          { "name": "author_id", "type": "bigInteger" },
          { "name": "body", "type": "text" }
        ]
      }
    ],
    "controllers": [
      "ProjectController",
      "TaskController",
      "CommentController"
    ],
    "rest": [
      { "resource": "Project", "methods": ["index", "show", "store", "update", "delete"] },
      { "resource": "Task", "methods": ["index", "show", "store", "update", "delete"] },
      { "resource": "Comment", "methods": ["index", "store", "delete"] }
    ],
    "routes": {
      "admin": [
        "/projects",
        "/projects/{id}",
        "/projects/{id}/tasks"
      ]
    },
    "settings": {
      "name": "Task Tracker Settings",
      "sections": [
        {
          "id": "general",
          "title": "General",
          "fields": [
            { "name": "default_priority", "type": "select", "label": "Default Priority", "options": ["low", "medium", "high"] },
            { "name": "tasks_per_page", "type": "number", "label": "Tasks Per Page", "default": 25 }
          ]
        },
        {
          "id": "notifications",
          "title": "Notifications",
          "fields": [
            { "name": "email_on_assign", "type": "checkbox", "label": "Email on Task Assignment" },
            { "name": "email_on_comment", "type": "checkbox", "label": "Email on New Comment" }
          ]
        }
      ]
    }
  }
})

Resulting file tree

task-tracker/
|-- task-tracker.php
|-- bootstrap.php
|-- composer.json
|-- config/
|   +-- app.php
|-- database/
|   +-- migrations/
|       |-- create_projects_table.php
|       |-- create_tasks_table.php
|       +-- create_comments_table.php
|-- routes/
|   |-- admin.php
|   |-- ajax.php
|   +-- rest.php
|-- src/
|   |-- PluginContext.php
|   |-- Lifecycle.php
|   |-- Http/
|   |   +-- Controllers/
|   |       |-- ProjectController.php
|   |       |-- TaskController.php
|   |       |-- CommentController.php
|   |       |-- ProjectRestController.php
|   |       |-- TaskRestController.php
|   |       +-- CommentRestController.php
|   |-- Models/
|   |   |-- Project.php
|   |   |-- Task.php
|   |   +-- Comment.php
|   |-- Providers/
|   |   |-- ProjectServiceProvider.php
|   |   |-- TaskServiceProvider.php
|   |   |-- CommentServiceProvider.php
|   |   +-- SettingsServiceProvider.php
|   +-- Settings/
|       +-- TaskTrackerSettingsPage.php
+-- resources/
    +-- views/
        |-- projects/
        |   |-- index.php
        |   |-- create.php
        |   |-- edit.php
        |   +-- show.php
        +-- tasks/
            |-- index.php
            |-- create.php
            |-- edit.php
            +-- show.php

The blueprint processor:

  1. Scaffolds the base plugin (entry file, bootstrap, PluginContext, Lifecycle, config)
  2. Creates all three models with their migrations
  3. Generates admin controllers and REST controllers
  4. Wires routes in routes/admin.php and routes/rest.php
  5. Creates a service provider for each module and registers it in config/app.php
  6. Builds the settings page with both sections
  7. Generates view templates for admin-facing resources

After generation, run validate_conventions and validate_security to confirm everything meets framework standards.


See Also