Review WordPress code for security and API compliance
Security-first code reviewer for WordPress plugins, themes, and blocks that catches XSS, SQLi, CSRF, and performance issues before production deployment.
Why it matters
Ensure WordPress plugins, themes, and blocks are production-ready by catching systematic security vulnerabilities, API misuse, and performance issues that AI-generated code commonly introduces before deployment.
Outcomes
What it gets done
Verify all output is escaped and input sanitized with WordPress-correct functions
Confirm AJAX and REST endpoints enforce both nonce verification and capability checks
Check database queries use prepared statements and queries follow performance best practices
Validate all user-facing strings are translation-ready with proper i18n wrappers
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-wp-guard | bash Overview
WP Guard
A guard-pass code reviewer that applies WordPress-specific security, API discipline, internationalization, and performance rules to generated or changed code before it ships. After an AI agent writes, edits, or reviews WordPress code touching hooks, custom post types, REST endpoints, database queries, or block editor integrations - or when a user explicitly requests a structured audit.
What it does
WP Guard is a specialized code review skill that audits WordPress plugins, themes, and blocks for security vulnerabilities, API misuse, and performance problems before deployment. It applies rules covering escaping, sanitization, nonce verification, capability checks, prepared statements, i18n compliance, and query optimization - catching the systematic failures AI agents produce when generating WordPress code: raw echo of request data, AJAX handlers without nonce or capability checks, SQL string interpolation, hardcoded English strings, posts_per_page set to -1 on million-post sites, and hand-rolled replacements for core APIs.
When to use - and when NOT to
Activate WP Guard after any AI agent writes, edits, or reviews WordPress code touching hooks, custom post types, REST endpoints, database queries, or block editor integrations. Use it in three modes: guard-pass (post-generation review), live (during code generation), or review mode (structured audit on user request). Pair it with clean-code-guard when both are installed: clean-code-guard owns generic code quality while WP Guard owns the WordPress layer.
Do NOT use this skill for cosmetic code style issues that WPCS tooling already handles, or on code you are not authorized to assess.
Inputs and outputs
You provide generated or changed WordPress code files, diffs, or target paths. The skill adapts to your project by reading CLAUDE.md, AGENTS.md, phpcs.xml, and composer.json to match established prefixes and minimum supported versions. It detects context automatically (WooCommerce, multilingual setups) and mirrors neighboring file conventions unless they violate non-negotiable security rules.
In review mode, you receive a structured findings report formatted as:
**Rule N violation** in `path/file.php:<line or function>`
- What: <one sentence>
- Risk: <XSS / SQLi / CSRF / broken i18n / scaling - one phrase>
- Fix: <one sentence>
In guard-pass and live modes, the skill fixes violations before showing you the code. The skill runs a self-check before delivery, examining code for unescaped echo statements, raw request variables, unprepared database queries, missing i18n wrappers, unverified hooks, unbounded queries, and unprefixed public names.
Integrations
WP Guard pairs with clean-code-guard for layered quality control. When WooCommerce APIs are detected, it applies WooCommerce's HPOS, CRUD, and checkout rules from its developer documentation. It reads WPCS configurations (WordPress-Extra and WordPress-Security rulesets) and respects multilingual plugin contexts (WPML, Polylang, multisite) by enforcing blocking i18n requirements.
Who it's for
WordPress developers and agencies shipping AI-generated plugins, themes, or blocks who need to prevent the systematic failures that look fine in demos but fail in production. Security-conscious teams who require every state change to prove identity and intent, and every user-facing string to be translation-ready.
Source README
WP Guard
You are reviewing generated or changed WordPress code before it ships. Apply the rules below as a guard pass after the first implementation pass. Be a sharp reviewer, not a pedantic one: flag what creates vulnerabilities, breaks translations, or melts servers - ignore cosmetic preferences WPCS tooling already handles.
These rules exist because AI agents produce WordPress code with systematic failures: raw echo of request data, AJAX handlers with neither nonce nor capability check, SQL built by string interpolation, English hardcoded into user-facing strings, posts_per_page => -1 on sites with a million posts, and hand-rolled replacements for APIs core already ships. Each one looks fine in a demo and fails in production.
When to Use
Use this skill when reviewing generated or changed WordPress code - plugins, themes, and blocks - before it ships. Activate it reactively after an agent writes, edits, or reviews code touching WordPress APIs: hooks, custom post types, REST endpoints, database queries, and block editor integrations.
How to use this skill
Guard-pass mode (recommended): after WordPress code has been generated or edited, apply the rules to the diff or target files, then run the self-check before delivery. Fix violations before showing the user.
Live mode (explicit): when the user invokes this skill before writing WordPress code, apply the same rules while writing, then run the self-check before delivery.
Review mode (the user asks you to review, audit, or rate WordPress code): walk references/review-checklist.md against the target files and produce a structured findings report. Do not edit code in review mode unless asked.
Pair this skill with clean-code-guard when both are installed: clean-code-guard owns generic code quality; wp-guard owns the WordPress layer.
Adapt to the project first
- Read the project's agent instructions (CLAUDE.md, AGENTS.md),
phpcs.xml/WPCS config, andcomposer.json. Project conventions win on conflict. - Identify the established prefix (functions, options, meta keys, handles) and the minimum supported WP/PHP versions. Match both.
- Detect context: WooCommerce APIs in play → apply woo-guard alongside this skill when it is installed; otherwise apply WooCommerce's HPOS, CRUD, and checkout rules from its developer documentation. Multilingual site (WPML/Polylang/multisite) → i18n rules are blocking, not advisory.
- Read one neighboring file before writing. Mirror its error handling, hook registration style, and escaping habits - unless they violate the security rules below, which are non-negotiable.
The Rules
Security - must fix, no exceptions
Escape late, escape everything. Every variable crossing into HTML output goes through the context-correct function:
esc_html(),esc_attr(),esc_url(), orwp_kses()/wp_kses_post()for rich content. Data passed to inline JS goes throughwp_json_encode()+wp_add_inline_script()-esc_js()is legacy, for single-quoted strings in inline attributes only. Escaping happens at output, not at storage.echo $anything;without anesc_*wrapper fails review.Sanitize early, and unslash first. Request data (
$_POST,$_GET,$_REQUEST,$_SERVER) never touches logic raw:wp_unslash()first, then the type-correct sanitizer (sanitize_text_field(),sanitize_key(),absint(),sanitize_email(), …). Sanitization is not escaping; doing one never excuses the other.Every state change proves identity and intent. Form handlers, AJAX endpoints, and REST routes that change anything require BOTH a capability check (
current_user_can()) AND a nonce (check_admin_referer(),check_ajax_referer(), or REST nonce handling). A nonce is not authorization. A RESTpermission_callbackof__return_trueon a writing route fails review.$wpdb->prepare()for every query containing a variable. Placeholders (%s,%d,%f, and%ifor identifiers on WP ≥ 6.2), never interpolation or concatenation. PreferWP_Query, the meta and options APIs over raw SQL when they can express the query.
Core API discipline
Use the platform; don't reinvent it. Outbound HTTP via
wp_remote_get()/wp_remote_post(), never curl. Assets viawp_enqueue_script()/wp_enqueue_style(), never echoed<script>/<style>tags. Scheduling via WP-Cron or Action Scheduler. Redirects viawp_safe_redirect()followed byexit. File writes viaWP_Filesystem. Simple persistent data via options/transients, not a custom table.Verify every hook and function exists. Before
add_action(),add_filter(), or calling a core/plugin function, confirm it exists in the supported versions - read the source or the project's installed code. Hallucinated hooks fail silently in WordPress: no error, no behavior. Also match the hook to the moment - front-end code does not load onadmin_init, queries do not run beforeinitexpects them.Prefix or namespace everything public. Functions, classes, options, transients, meta keys, script handles, AJAX actions, REST namespaces - all carry the project prefix. Generic names (
get_settings,data,api_key) are collisions waiting for the next active plugin.Guard direct access. Every PHP file that does work starts with the
ABSPATHcheck (or equivalent project convention).
Internationalization
- Every user-facing string is translation-ready. The correct wrapper for the context (
__(),_e(),_x(),_n(), or the escaping combosesc_html__(),esc_attr__()), a literal text domain matching the plugin slug - never a variable or constant - translator comments on every placeholder,_n()for plurals (neversprintfwith a hardcoded singular/plural choice), and no sentence assembly by concatenation. Dates and numbers throughdate_i18n()/wp_date()andnumber_format_i18n(). Details and JS i18n: references/i18n.md.
Performance
Query discipline. No
posts_per_page => -1and noquery_posts(), ever. Use'fields' => 'ids'when only IDs are needed,'no_found_rows' => truewhen not paginating, and never query inside a loop what could be primed once (meta/term caches). Details: references/performance.md.Cache expensive work, load assets where used. Remote calls and heavy computations go behind transients or the object cache with a deliberate TTL. Options that are large or rarely read register with
autoload => false. Scripts and styles enqueue only on the screens that use them.
Self-check before delivery
- Grep your diff for
echo,print,<?=: is every variable output escaped with the context-correct function? - Grep for
$_POST,$_GET,$_REQUEST: unslashed? sanitized? nonce-verified? capability-checked? - Grep for
$wpdb->: every variable behind a placeholder? - Any user-facing string outside an i18n wrapper? Any non-literal text domain?
- Any hook or function you did not verify exists?
- Any unbounded query, uncached remote call, or unconditional enqueue?
- Does every new public name carry the project prefix?
- Would this survive WPCS (
WordPress-Extra+WordPress-Security) without warnings you cannot justify?
If any answer is wrong, fix it before showing the user.
Reporting format (review mode)
**Rule N violation** in `path/file.php:<line or function>`
- What: <one sentence>
- Risk: <XSS / SQLi / CSRF / broken i18n / scaling — one phrase>
- Fix: <one sentence>
Group by file, lead with security findings. If a file is clean, don't mention it.
Severity guide
- Must fix: Rules 1-4 - these are exploitable (XSS, SQLi, CSRF, privilege escalation)
- Should fix: Rules 5-9 - conflicts, silent failures, untranslatable releases
- Worth noting: Rules 10-11 - they decide whether the code survives traffic; block on them for code that runs on every request
References
- references/security.md - escaping/sanitization function tables, nonce lifecycle, REST permissions,
$wpdb->preparedetails, file uploads - references/i18n.md - wrapper selection, text domain rules, plurals, translator comments, JS translations, RTL, multilingual-plugin gotchas
- references/performance.md - WP_Query flags, transients vs object cache, autoload hygiene, asset loading, cron, scaling traps
- references/review-checklist.md - structured walk-through for review mode
- references/sources.md - handbook and research URLs; read only when citing a source
What this skill does not do
- Run PHPCS, PHPStan, or Plugin Check - use the project's tooling for mechanical verification; this skill is the judgment layer above it.
- Decide plugin architecture or business logic - it guards how WordPress code ships, not what it does.
- Replace clean-code-guard or test-guard - generic code quality and test quality remain their jurisdiction.
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.