# How to Review AI-Generated WordPress Code Before It Goes Live

- Link: https://matthummel.com/how-to-review-ai-generated-wordpress-code-before-it-goes-live/
- Published: 2026-11-21T14:00:00+00:00
- Author: Matt Hummel

Before AI-generated WordPress code goes live, write down what it should do, who 
can use it, and how it should fail. Review the diff against those notes. Then test
the workflow on staging with the same roles people use in production. Here’s the
checklist I’d use.

> **At a glance**
>  * Can an unauthorized user trigger the action or edit someone else’s data?
>  * Is saved data checked before it’s accepted and escaped when displayed?
>  * What happens when input is empty or invalid, or a service fails?
>  * Does the feature still work by keyboard and on a phone?
>  * Have I read the diff and tested the real workflow on staging?

## 1. Write down the behavior before reviewing syntax

Start with four questions. What is the feature supposed to do? Who can use it? Where
does the data come from? What should happen when something fails?

Then test against your answers. If an AI-generated admin action updates a setting,
try it as a user who shouldn’t have permission. If the feature sends an email, test
both delivery and failure.

A precise requirement catches mistakes that a style-only review won’t.

## 2. Check permissions and intent separately

A nonce is a short-lived token WordPress adds to a form or link. It helps confirm
the request came from the screen you expect. It doesn’t prove the user is allowed
to do the thing.

For privileged actions, check both. Use `current_user_can()` for the capability,
and verify the nonce. Don’t assume a logged-in user may edit every post or manage
every option.

For AJAX handlers, check the action’s authentication, nonce, and capability requirements.
For custom REST routes, review the [permission callback](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/)
and check capabilities against the specific record. A user should never reach a 
different record just by changing an ID.

## 3. Sanitize input and escape output

Clean incoming values by type. A plain-text field might use `sanitize_text_field()`.
An email address uses `sanitize_email()`. URLs have their own rules.

Escape when you print, with the function that fits the spot: `esc_html()` for text,`
esc_attr()` for attributes, and `esc_url()` for links. Don’t sanitize once and assume
the string is safe everywhere.

If rich text is allowed, use a deliberate HTML allowlist. The [WordPress security handbook](https://developer.wordpress.org/apis/security/)
covers validation, sanitization, and escaping.

## 4. Review queries, hooks, and dependencies

Check for `$wpdb->prepare()` wherever query values are dynamic. Where a WordPress
API can do the job, use it instead of custom SQL.

Review hook priority, and check whether the callback runs on pages where it isn’t
needed. An admin-only feature shouldn’t load large scripts on every front-end request.
I cover that problem in my speed post under [plugins that load code everywhere](https://matthummel.com/why-is-my-wordpress-site-slow-seven-problems-to-check-first/#4-plugins-load-code-everywhere).

Before you add a new dependency, check whether WordPress already does the same job.

## 5. Test failure cases and accessibility

Try missing records, empty fields, malformed requests, and expired nonces. Errors
should make sense to the user without exposing server details.

Where the interface changes, test with a keyboard and a screen reader. Code can 
be secure and still unusable. Labels, visible focus, status messages, and predictable
behavior all belong in review.

## 6. Run tools, then read the changes

Run PHP_CodeSniffer with the [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards),
PHP static analysis, and whatever automated tests the project supports.

Then read the diff. Don’t accept a generated replacement of a whole file.

I learned this on my own theme. An AI-written change to Cobble & Candle pasted two
lines of cookie code a second time, at the very top of the theme’s main script. 
It passed review because I skimmed the diff. It sat there for five weeks before 
I read the file from the top and saw it. The fix was deleting two lines. Now I read
the first and last ten lines of every file an AI touches, not just the part I asked
it to change.

Run the feature on staging with realistic data, review the logs, and keep a rollback
path. Automated checks help, but they don’t know your client’s workflow unless you
turn it into tests.

## A small example: escape a saved title

Say a function prints a title saved in an option. The risky version drops the value
straight into HTML:

    ```wp-block-code
    echo '<h2>' . get_option( 'my_plugin_heading', '' ) . '</h2>';
    ```

The safer version escapes at the point of output:

    ```wp-block-code
    echo '<h2>' . esc_html( get_option( 'my_plugin_heading', '' ) ) . '</h2>';
    ```

`esc_html()` converts special characters to HTML entities, so a saved script tag
prints as text. That’s one piece of the feature. The admin screen that saves the
title still needs its own capability and nonce checks.

## Record what passed on staging

For a change that saves a setting, write down the role you tested, the expected 
result, and what you saw.

| Staging check | Expected result | 
| Editor with the right capability saves a valid value | The setting updates and stays updated after reload. | 
| User without the capability tries the same workflow | The request is denied and the previous value remains. | 
| Authorized editor submits an invalid value | A clear error appears and the previous value remains. |

Record how to revert both the code and any data changes.

## An example from a real WordPress product

In [Cobble & Candle](https://matthummel.com/themes/cobbleandcandle/), the Core plugin
stores restaurant information and the theme presents it. If I were reviewing a change
to menu editing, I’d follow the owner workflow from the dashboard to the public 
menu.

I’d check who can save a dish and whether the new price shows where guests expect
it. I’d also check that the previous value stays intact if saving fails. The [Cobble & Candle setup guide](https://github.com/matthummel-pa/wp-cobbleandcandle-docs/blob/main/getting-started.md)
shows the owner’s side of that workflow.

## Why reviewing AI-generated WordPress code matters to clients

A business owner shouldn’t need to care whether a developer used an AI assistant.
They should care whether the site is safe to run, easy to maintain, and properly
tested.

I’ve written more about my tools in [my AI WordPress workflow](https://matthummel.com/ai-workflow-for-wordpress-development/),
and about why the fundamentals still matter in [Should you still learn to code?](https://matthummel.com/should-you-still-learn-to-code-in-2026-what-ai-changed-and-what-it-didnt/)

## Common questions

### Is AI-generated WordPress code safe to use?

It can be, once someone has reviewed it. Treat it like code from a new teammate.
Check permissions, input and output handling, and failure cases, then test it on
staging before it goes live.

### Can automated tools replace a manual review?

No. Linters and static analysis catch style problems and some risky patterns. They
don’t know who should be allowed to do what on your client’s site. You still need
to read the diff and test with real roles.

### Do I need a staging site to review AI-generated code?

Yes, for anything that saves data or changes what users can do. Staging lets you
test with different roles and bad input without putting live data at risk.
