Home › WordPress › WordPress plugin CLAUDE.md

WordPress plugin CLAUDE.md

CLAUDE.md for WordPress plugin development: prefixes, hooks, nonces and capabilities, sanitizing, escaping, and wp-env.

Claude Code (CLAUDE.md)WordPress

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

CLAUDE.mdDownload  
# CLAUDE.md: WordPress plugin

## Commands
- Local site: `npx wp-env start` · WP-CLI: `npx wp-env run cli wp plugin list`
- Lint: `vendor/bin/phpcs --standard=WordPress` · Tests: `vendor/bin/phpunit` (WP test suite) · JS: `npm run build` (`@wordpress/scripts`)

## Structure
- Main file `my-plugin.php` with the plugin header; logic in namespaced classes under `includes/` (Composer autoload). Guard every PHP file with `defined( 'ABSPATH' ) || exit;`.
- Prefix everything global (functions, options, hooks, CPT slugs, script handles) with the plugin slug, or use a PHP namespace.
- Hook into WordPress instead of running code at include time (`add_action( 'init', ... )`).

## Security rules (non-negotiable)
- Capability check on every privileged action: `current_user_can( 'manage_options' )`.
- Nonces on every form and AJAX/REST mutation: `wp_nonce_field` + `check_admin_referer`, or `wp_verify_nonce`.
- Sanitize input (`sanitize_text_field`, `absint`, `sanitize_email`, `wp_kses_post`) and escape output late (`esc_html`, `esc_attr`, `esc_url`, `wp_kses`).
- SQL only via `$wpdb->prepare()`; prefer WP APIs (`WP_Query`, `get_posts`, options, meta) over raw SQL.
- REST routes via `register_rest_route` with a real `permission_callback` (never `__return_true` for writes) and `args` validation.

## Other
- Enqueue assets with `wp_enqueue_script/style` and the generated `*.asset.php` dependencies; never hard-code `<script>` tags.
- Make strings translatable: `__( 'Text', 'my-plugin' )`, `esc_html__`.
- Clean up on uninstall in `uninstall.php`, not on deactivation.

More: all WordPress rules · all Claude Code (CLAUDE.md) rules

Related rules

WordPress block theme & blocks rules

Cursor rules for WordPress block themes and custom blocks: theme.json v3, block.json, patterns, and @wordpress/scripts.

CursorWordPress

Shopify app AGENTS.md

AGENTS.md for Shopify apps built with Shopify CLI and the React Router template: auth, GraphQL Admin API, and webhooks.

AGENTS.mdShopify

Shopify Liquid theme rules

Cursor rules for Shopify Online Store 2.0 themes: sections and blocks, JSON templates, Liquid performance, Theme Check.

CursorShopify

API route security .claude/rules file

A path-scoped Claude Code rules file for API routes and handlers: auth, ownership checks, validation, and safe errors.

Claude Code (CLAUDE.md)Security

AWS CDK (TypeScript) CLAUDE.md

CLAUDE.md for AWS CDK v2 apps in TypeScript: constructs, least-privilege grants, snapshot tests, and safe deploys.

Claude Code (CLAUDE.md)AWS CDK

Bun runtime CLAUDE.md

CLAUDE.md for TypeScript projects on Bun 1.2+: bun test, Bun.serve, built-in SQLite/Postgres, and bundling.

Claude Code (CLAUDE.md)Bun

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.