# 🔌 Plugin Assistant

> Creates complete WordPress plugins from natural language descriptions. Generates WPCS-compliant code with security best practices.

| Field | Value |
|-------|-------|
| Slug | `plugin-assistant` |
| Version | 1.2.0 |
| Category | Developer |
| Author | Agentic Community |
| Required Capabilities | `manage_options` |

## What It Does

Plugin Assistant turns plain English descriptions into fully functional WordPress plugins. Describe what you need — a custom post type, a settings page, a REST API endpoint, a shortcode, or a React-powered Gutenberg block — and it generates production-ready code that follows WordPress Coding Standards (WPCS).

The agent uses a template-based code generation system with 36 specialised templates covering custom post types, taxonomies, settings pages, REST endpoints, AJAX handlers, shortcodes, admin menus, database tables, meta boxes, uninstall routines, and React Gutenberg blocks. Every generated plugin includes proper file headers, security hardening (nonces, capability checks, input sanitisation, output escaping), activation/deactivation hooks, and translation-ready strings.

## Tools

| Tool | Risk | Description |
|------|------|-------------|
| `create_plugin_scaffold` | High | Generate a complete plugin or MU plugin scaffold. Regular plugins get a full directory structure; MU plugins get a single self-contained file in `wp-content/mu-plugins/`. |
| `generate_custom_post_type` | None | Generate code for a custom post type with labels, arguments, and optional meta boxes with custom fields. |
| `generate_taxonomy` | None | Generate code for a custom taxonomy with labels, arguments, and optional hierarchy. |
| `generate_settings_page` | None | Generate a WordPress settings page with sections, fields, and sanitisation callbacks. |
| `generate_shortcode` | None | Generate a shortcode handler with attributes, default values, and output buffering. |
| `generate_rest_endpoint` | None | Generate a WordPress REST API endpoint with permission callbacks, argument validation, and response formatting. |
| `generate_admin_menu` | None | Generate admin menu and submenu page registration with capability checks. |
| `generate_uninstall` | None | Generate an uninstall routine that cleans up options, custom tables, and post type data. |
| `generate_ajax_handler` | None | Generate a WordPress AJAX handler with nonce verification, capability checks, and JSON response. |
| `generate_gutenberg_block` | None | Generate a React Gutenberg block with @wordpress/scripts build setup, editor and frontend components, REST API data fetching, block attributes with inspector controls, and server-side render template. |
| `generate_database_table` | None | Generate a custom database table with dbDelta migration, column definitions, and indexes. |
| `validate_plugin_code` | None | Validate generated plugin code for syntax errors, security issues, and WPCS compliance. |
| `save_plugin_file` | High | Write a generated PHP file to `wp-content/plugins/` or `wp-content/mu-plugins/`. Set `mu_plugin: true` for must-use plugins. |

## Example Prompts

- "Create a plugin that adds a Testimonials custom post type with fields for name, company, and quote"
- "Build a React news ticker block that scrolls the latest posts"
- "Create a Gutenberg block that shows a team members grid from a custom post type"
- "Build a plugin with a settings page for a Google Analytics tracking ID"
- "Make a shortcode that displays a countdown timer to a specific date"
- "Create a REST API endpoint that returns the 5 most popular posts"
- "Build a plugin that adds a custom database table for event registrations"
- "Create an MU plugin that disables XML-RPC"

## How It Works

1. **Describe your plugin** in plain English — what it should do, what features it needs
2. **Plugin Assistant generates the code** using its template library, combining the right templates for your requirements
3. **Review the generated code** — the agent shows you the complete plugin with explanation
4. **Approve the scaffold** — the code is written to your `wp-content/plugins/` directory (or `wp-content/mu-plugins/` for MU plugins)
5. **Activate and test** — go to Plugins, activate your new plugin, and verify it works. MU plugins activate automatically — no activation step needed

## React Gutenberg Blocks

Plugin Assistant can generate complete React-powered Gutenberg blocks using the modern WordPress block development stack:

- **@wordpress/scripts** — zero-config build toolchain (Webpack + Babel + React) via `package.json`
- **Block API v3** — `block.json` metadata with attributes, scripts, and styles
- **Editor component** (`edit.js`) — React component with InspectorControls for sidebar settings (TextControl, ToggleControl, SelectControl, RangeControl, NumberControl)
- **Frontend component** (`view.js`) — React component that mounts on the frontend via `createRoot`, with optional REST API data fetching
- **Server-side render** (`render.php`) — outputs a hydration div with `data-attrs` so the React component can pick up block attributes
- **REST API integration** — optional `data_source` parameter auto-generates a `useEffect` + `fetch` hook (e.g., `/wp-json/wp/v2/posts?per_page=5&_embed`)
- **Custom JSX** — pass fully custom React code for the view component and editor preview when defaults aren't enough

### Generated file structure

```
src/{block-slug}/
├── block.json      (block metadata)
├── index.js        (block registration)
├── edit.js         (editor React component)
├── view.js         (frontend React component)
├── render.php      (server-side render template)
├── style.scss      (shared styles)
└── editor.scss     (editor-only styles)
includes/
└── block-{slug}.php (PHP registration)
package.json         (@wordpress/scripts)
```

After saving, run `npm install && npm run build` in the plugin directory. WordPress core ships React as `wp.element` — the build system handles dependencies automatically.

## MU Plugins

Plugin Assistant can create must-use (MU) plugins — single-file plugins that live in `wp-content/mu-plugins/` and load automatically on every page. MU plugins:

- **Load before regular plugins** — ideal for custom functionality that must always run
- **Cannot be deactivated** from the WordPress admin — remove the file to disable
- **Single-file** — all code lives in one PHP file, no subdirectory
- **Common uses:** disable XML-RPC, custom login redirects, admin branding, security hardening, performance tweaks

Ask Plugin Assistant to "create an MU plugin" and it handles the single-file format automatically.

## Template Library

Plugin Assistant includes 36 code templates covering:

- **Plugin structure** — main file with headers, activation hooks, text domain
- **Custom Post Types** — full registration with labels, supports, meta boxes
- **Taxonomies** — hierarchical and flat, with term meta
- **Settings** — options pages with sections, fields, sanitisation
- **REST API** — endpoints with auth, validation, schema
- **AJAX** — handlers with nonce verification and capability checks
- **Shortcodes** — with attributes and output buffering
- **Admin menus** — top-level and submenu pages
- **Database tables** — dbDelta migrations with indexes
- **Meta boxes** — custom fields with save handlers
- **Gutenberg blocks** — block.json, editor/frontend React components, styles, render.php, package.json, PHP registration
- **Uninstall** — clean removal of all plugin data

---

_Generated by Agent Builder for WordPress_
