The theme from the previous lesson renders. Rendering correctly and being safe to run are two different bars, and an AI coding agent clears the first one far more reliably than the second. This lesson is the checklist you run before a generated theme, or any generated plugin code, gets to leave your local Studio site.
A generated theme or plugin from the previous lesson (or any AI-generated WordPress code) sitting in your local Studio site, ready for line-by-line review.
Step 1: escaping, checked at the point of output
Every dynamic value printed into a template needs to be escaped where it’s printed, not somewhere earlier in the code.
// Fails review: title printed with no escaping
<h1><?php echo $post_title; ?></h1>
// Passes review: escaped at the point of output
<h1><?php echo esc_html( $post_title ); ?></h1>
Step 2: capability checks on anything that changes state
A generated form handler, AJAX callback, or REST route needs an explicit capability check, independent of whether a nonce is also present.
// Fails review: nonce checked, but no capability check
function my_theme_handle_settings_save() {
check_admin_referer( 'my_theme_settings' );
update_option( 'my_theme_settings', $_POST['settings'] );
}
// Passes review: both checks present
function my_theme_handle_settings_save() {
check_admin_referer( 'my_theme_settings' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have permission to do this.', 'my-theme' ) );
}
update_option( 'my_theme_settings', sanitize_text_field( wp_unslash( $_POST['settings'] ) ) );
}
A nonce proves the request came from your own form. It says nothing about whether the person submitting it should be allowed to. Generated code frequently gets this wrong in exactly this way, a nonce check that reads like a complete security measure and isn’t one.
Step 3: nonces on every state-changing form
Step 4: accessibility, the category generated themes fail most quietly
Escaping and capability failures usually show up as a security bug someone eventually finds. Accessibility failures in generated theme markup tend to just sit there, technically working, genuinely excluding real users.
<!-- Fails review: image with no alt text, button with no accessible label -->
<img src="/hero.jpg">
<button class="menu-toggle"></button>
<!-- Passes review: alt text present, accessible label on an icon-only button -->
<img src="/hero.jpg" alt="Fresh sourdough loaves cooling on the bakery counter">
<button class="menu-toggle" aria-label="<?php esc_attr_e( 'Open menu', 'my-theme' ); ?>"></button>
Step 5: have the agent self-check first, then verify yourself
You can run this entire checklist as a prompt before you ever open the file yourself:
Review every template and PHP file in this theme against this checklist:
escaping at the point of output, capability checks on anything that changes
state, nonces on state-changing forms, and accessibility (alt text, heading
order, accessible names on icon-only controls). List every file where you
find a violation, with the specific line and what's wrong.
Treat the response as a starting point, not a verdict. Spot-check at least the files it flagged as clean, an agent grading its own generated output has the same blind spots reviewing that it had while writing.
Step 6: know when to reject a file outright
Some failures are worth patching in place. Others mean the file should be regenerated from scratch rather than fixed line by line.
A database query built with string concatenation instead of $wpdb->prepare(), a
form handler with no capability check at all (not just a weak one), or a file that
hallucinated a core function and built significant logic around it. These indicate
the generation missed a fundamental constraint, not a single line, and patching
around a fundamentally wrong approach tends to leave subtler versions of the same
mistake nearby.
Recap
Escaping at the point of output, capability checks independent of nonce checks, nonces on every state-changing form, and accessibility fundamentals, alt text, heading order, accessible names, keyboard reachability, are the four categories worth checking on every piece of AI-generated theme or plugin code before it’s trusted. Asking the agent to self-check against this list is a useful first pass, never a substitute for actually reading the files it flagged as clean, and a fundamentally wrong approach gets rejected and regenerated, not patched.
Resources & further reading
- Data Validation, developer.wordpress.org
- Nonces, developer.wordpress.org
- Accessibility Coding Standards, developer.wordpress.org