- Removes unused WordPress front-end payloads (
wp-emoji-release.min.js,wp-embed, guestdashicons.min.css,jquery-migrate,xmlrpc.php) via native hooks inWordPressCleanup.phpwith zero HTML regex overhead. - Tunes Heartbeat API independently across Front-End, Admin, and Post Editor (
HeartbeatControl.php), injecting awindow.wp.heartbeatsafety stub so dependent plugins never throw JSTypeErrors. - Cleans 8 database categories (
DatabaseCleanup.php) in cooperative Action Scheduler batches bounded by a12stime ceiling and80%PHPmemory_limitguard. - Protects custom post types, preserves your newest N revisions (
database_keep_revisions), previews exact row counts in a confirmation modal, and logs an itemized execution receipt.
Table of Contents (5 sections)
Two Silent Drags on Every Aging WordPress Site#
Over 12 to 24 months of publishing products, running WooCommerce promotions, and testing plugins, two forms of accumulated bloat steadily slow down both visitors and editors:
- Default Front-End &
admin-ajax.phpBloat: Every fresh WordPress install ships legacy compatibility payloads to every mobile visitor—wp-emoji-release.min.js+s.w.orgDNS hints,wp-embedoEmbed discovery scripts,jquery-migrate.min.js, and the 36 KBdashicons.min.cssicon font whenever a badly coded plugin listsdashiconsas a stylesheet dependency for logged-out guests. Meanwhile, open browser tabs hammer/wp-admin/admin-ajax.phpevery 15 to 60 seconds via the WordPress Heartbeat API, and bots probe/xmlrpc.phpwith brute-force multicall floods. - Unbounded MySQL Table Growth: Tens of thousands of old post revisions, expired transients, trashed drafts, orphaned
wp_postmeta/wp_termmetarows, and hundreds of thousands of completed WooCommerce Action Scheduler (wp_actionscheduler_actions+wp_actionscheduler_logs) rows bloat InnoDB buffer pools and slow down backups and uncached queries. Yet running a naiveDELETE FROM wp_postmeta ...plugin that executes one giant synchronous SQL query inside an HTTP request locks InnoDB tables and crashes PHP with504 Gateway TimeoutorAllowed memory size exhausted!
KadiCache solves front-end bloat cleanly in WordPressCleanup.php + HeartbeatControl.php, and solves MySQL table growth safely in DatabaseCleanup.php—both included in Free Core.
Dependency-Safe Bloat Removal (WordPressCleanup.php)#
Unlike optimization plugins that run expensive regex replacements over full HTML buffers just to strip an emoji tag, WordPressCleanup.php unhooks unused features cleanly at WordPress's native init and wp_print_styles lifecycle hooks—and respects excluded_paths:
- Disable WordPress Emojis (
disable_emoji): Removesprint_emoji_detection_script,wp_enqueue_emoji_styles, TinyMCEwpemoji, and the externals.w.orgDNS-prefetch hint while leaving native operating-system Unicode emojis 100% intact. - Disable Guest Dashicons Without Breaking Dependent Stylesheets (
disable_guest_dashicons): Simply callingwp_deregister_style('dashicons')is a notorious trap in WordPress: if a page-builder or mega-menu stylesheet declares['dashicons']in its$depsarray, deregisteringdashiconscauses WordPress to silently drop the entire mega-menu stylesheet too! KadiCache dequeuesdashiconsfor logged-out guests and filtersstyle_loader_srcwhile keeping thedashiconshandle registered, eliminating the 36 KB icon font for visitors without breaking dependent plugin CSS! - Disable jQuery Migrate (
disable_jquery_migrate) & oEmbeds (disable_embeds): Removesjquery-migratefromjquery's dependency array on the front end (!is_admin()so legacy admin meta boxes stay untouched) and dequeueswp-embedwhile keeping standard pasted YouTube/Vimeo embeds working natively. - Disable XML-RPC & Pingback Surface (
disable_xmlrpc): Disablesxmlrpc_enabled, emptiesxmlrpc_methodsatPHP_INT_MAX, strips theX-PingbackHTTP header, and removesrsd_link—and deliberately stays active as a security restriction even if page-cache optimizations are temporarily paused.
Stub-Protected 3-Zone Heartbeat Control (HeartbeatControl.php)#
Many WooCommerce extensions, form builders, and security plugins list heartbeat as a script dependency or call window.wp.heartbeat.enqueue() directly in JavaScript. When a typical optimization plugin calls wp_deregister_script('heartbeat'), two things break: dependent scripts stop loading altogether, and inline scripts crash with Uncaught TypeError: Cannot read properties of undefined (reading 'connectNow').
Cooperative Bounded-Batch Database Cleanup (DatabaseCleanup.php)#
WP Admin -> KadiCache -> Database targets 8 high-impact cleanup categories (DatabaseCleanupItems::ITEMS) with a Safe Quick Clean preset, configurable revision retention (database_keep_revisions, e.g., keep the latest 5 revisions per post while pruning older history), and automated Daily / Weekly / Monthly schedules:
| Cleanup Target Key | Database Tables Cleaned | Built-In Safety Boundary |
|---|---|---|
revisions | wp_posts (post_type = revision) + wp_postmeta | Honors database_keep_revisions per parent post and skips custom/excluded post types |
auto_drafts | wp_posts (post_status = auto-draft) | Preserves active recent editor sessions so authors currently typing never lose drafts |
trash_posts | Trashed standard posts & pages | Scoped strictly to safe post types (DatabaseCleanupItems::postTypes()), never touching WooCommerce orders |
trash_comments & spam_comments | wp_comments + wp_commentmeta | Cleans paired comment metadata alongside trashed and Akismet/spam comment rows |
transients | Expired wp_options / wp_sitemeta transients | Deletes only expired transients whose timeout timestamp has already passed |
actions | wp_actionscheduler_actions + wp_actionscheduler_logs | Prunes completed, canceled, or old failed Action Scheduler entries while leaving pending & in-progress jobs untouched |
orphans | Orphaned wp_postmeta, wp_commentmeta, wp_termmeta, wp_term_relationships | Verified relational check before removing metadata pointing to non-existent parent IDs |
Every cleanup run (kadicache_database_run) executes through cooperative Action Scheduler batches (kadicache_database_batch) protected by four production guardrails:
- 12-Second Time Budget &
80%Memory Ceiling: Each worker batch computes$deadline = min(microtime(true) + 12, REQUEST_TIME_FLOAT + max_execution_time - 3)and monitorsmemory_get_usage(true) >= $memory * 0.8. As soon as either threshold is approached, the worker checkpoints its cursor and yields to the next scheduled action—zero timeouts, zero OOM crashes even on 500,000-row WooCommerce tables. - Itemized Confirmation Modal: Clicking Run Cleanup opens
#kc-dialogshowing exact per-category candidate counts and active revision retention rules before a single row is deleted. - Instant Cooperative Cancel (
DatabaseCleanup::cancel()): Stores an independentkadicache_database_canceltoken (flushingnotoptionsobject cache between checks) so an admin can abort a multi-batch cleanup cleanly mid-run. - Permanent Execution Receipt (
kadicache_database_last): Records total rows removed, processed batch count, elapsed seconds, and proportional category share in the Last Cleanup Run receipt table.
Previewing (--dry-run) & Running Cleanup via WP-CLI#
DatabaseCli.php gives system administrators and DevOps pipelines full --dry-run inspection before queuing any background deletion:
# View live candidate row counts across all 8 categories + last run receipt
wp kadicache db status --format=json
# Dry-run specific categories (zero rows deleted; outputs exact candidate counts)
wp kadicache db clean --items=revisions,transients,actions --dry-run
# Queue bounded background cleanup for selected categories
wp kadicache db clean --items=revisions,auto_drafts,transients,actions,orphansCreator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.