Brandon Hubbard Engineering / wp-cleanup-scripts
SHELL & SQL · WORDPRESS DBA TOOLKIT

wp-cleanup-scripts — High-Speed WP-CLI & SQL Database Maintenance Toolkit

wp-cleanup-scripts is a collection of battle-tested WP-CLI bash routines and indexed SQL queries for cleaning bloated WordPress production databases. It safely purges expired transients, orphaned postmeta, post revisions, and Action Scheduler logs without locking high-traffic tables.

$ wp eval-file cleanup-orphans.php
GitHub ↗
Autoload Target < 800 KB
Orphaned Meta Purge LEFT JOIN Indexed
Table Optimization InnoDB Reclaim
Dry-Run Safety 100% Transactional
Interactive `wp_options` Autoload & Orphaned Postmeta SQL Planner
Deterministic Execution Output & Telemetry STATUS: READY // 0 ERRORS

        
SQL / WP-CLI Hygiene Script
-- 1. Inspect top autoloaded wp_options bloat in bytes
SELECT option_name, LENGTH(option_value) AS bytes
FROM wp_options WHERE autoload IN ('yes', 'on')
ORDER BY bytes DESC LIMIT 20;

-- 2. Safely remove orphaned wp_postmeta rows with no parent post
DELETE pm FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL;
Production Engineering Specifications
Repository:    https://github.com/bhubbard/wp-cleanup-scripts
Live Studio:   https://code.brandonhubbard.com/wp-cleanup-scripts/
Portal:        https://code.brandonhubbard.com/
Install:       git clone https://github.com/bhubbard/wp-cleanup-scripts
Design System: Brandon Hubbard Swiss Modernist (#0A0A0C / 1px Exposed Structural Grid)