Skip to main content
KadiCache
Core & Object CacheFree Core

Bloat Removal & Database Cleanup

Cleans emojis, oEmbeds, XML-RPC noise, and aggressive Heartbeat polling while providing scheduled or WP-CLI cleanup for post revisions, expired transients, orphan metadata, and completed Action Scheduler logs.

Admin Heartbeat Load
-62%
Verified Source Entry
apps/wordpress-plugin/src/Support/DatabaseCleanup.php
Verified Engine Capabilities

Engineered for zero regressions.

  • Granular Heartbeat API throttling separately for Dashboard, Editor, and Frontend
  • One-click & scheduled cleanup for Revisions, Auto-Drafts, Trash, Transients & Action Scheduler logs
  • WordPressCleanup removes emoji scripts, RSD/WLW links, and unnecessary query noise
  • Full WP-CLI automation via wp kadicache db status|clean
Dry-Run & Bounded WP-CLI Database Cleanup
$ wp kadicache db status --format=json
$ wp kadicache db clean --items=revisions,transients,actions --dry-run
$ wp kadicache db clean --items=revisions,auto_drafts,transients,actions
# Previews exact candidate counts, then queues bounded <=12s / <80% RAM batches
Inside the KadiCache WordPress Plugin

Bloat Removal & Database Cleanup — Plugin Interface

4 live 2x Retina plugin screens
WP Admin -> KadiCache -> Bloat Removal
MODULE 14 · 2X RETINA
Trim unused WordPress front-end scripts and tune Heartbeat API intervals across Front end, Admin, and Post Editor.2880×1840 WebP
100% Source-Code Verified9 min engineering readUpdated 2026-11-23
Executive Summary · 30-Second SpecZero-Regressions Spec
WP Admin Path
WP Admin -> KadiCache -> Bloat Removal + Database
Measured Impact
8 Safe DB Targets · Stub-Protected Heartbeat · Zero Lockouts
Verification Marker
wp kadicache db status | kadicache_database_last
  • Removes unused WordPress front-end payloads (wp-emoji-release.min.js, wp-embed, guest dashicons.min.css, jquery-migrate, xmlrpc.php) via native hooks in WordPressCleanup.php with zero HTML regex overhead.
  • Tunes Heartbeat API independently across Front-End, Admin, and Post Editor (HeartbeatControl.php), injecting a window.wp.heartbeat safety stub so dependent plugins never throw JS TypeErrors.
  • Cleans 8 database categories (DatabaseCleanup.php) in cooperative Action Scheduler batches bounded by a 12s time ceiling and 80% PHP memory_limit guard.
  • 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:

  1. Default Front-End & admin-ajax.php Bloat: Every fresh WordPress install ships legacy compatibility payloads to every mobile visitor—wp-emoji-release.min.js + s.w.org DNS hints, wp-embed oEmbed discovery scripts, jquery-migrate.min.js, and the 36 KB dashicons.min.css icon font whenever a badly coded plugin lists dashicons as a stylesheet dependency for logged-out guests. Meanwhile, open browser tabs hammer /wp-admin/admin-ajax.php every 15 to 60 seconds via the WordPress Heartbeat API, and bots probe /xmlrpc.php with brute-force multicall floods.
  2. Unbounded MySQL Table Growth: Tens of thousands of old post revisions, expired transients, trashed drafts, orphaned wp_postmeta / wp_termmeta rows, 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 naive DELETE FROM wp_postmeta ... plugin that executes one giant synchronous SQL query inside an HTTP request locks InnoDB tables and crashes PHP with 504 Gateway Timeout or Allowed 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): Removes print_emoji_detection_script, wp_enqueue_emoji_styles, TinyMCE wpemoji, and the external s.w.org DNS-prefetch hint while leaving native operating-system Unicode emojis 100% intact.
  • Disable Guest Dashicons Without Breaking Dependent Stylesheets (disable_guest_dashicons): Simply calling wp_deregister_style('dashicons') is a notorious trap in WordPress: if a page-builder or mega-menu stylesheet declares ['dashicons'] in its $deps array, deregistering dashicons causes WordPress to silently drop the entire mega-menu stylesheet too! KadiCache dequeues dashicons for logged-out guests and filters style_loader_src while keeping the dashicons handle registered, eliminating the 36 KB icon font for visitors without breaking dependent plugin CSS!
  • Disable jQuery Migrate (disable_jquery_migrate) & oEmbeds (disable_embeds): Removes jquery-migrate from jquery's dependency array on the front end (!is_admin() so legacy admin meta boxes stay untouched) and dequeues wp-embed while keeping standard pasted YouTube/Vimeo embeds working natively.
  • Disable XML-RPC & Pingback Surface (disable_xmlrpc): Disables xmlrpc_enabled, empties xmlrpc_methods at PHP_INT_MAX, strips the X-Pingback HTTP header, and removes rsd_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').

FIG 01Itemized candidate row counts and revision retention verification before running bounded batchesZoom 2x

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 KeyDatabase Tables CleanedBuilt-In Safety Boundary
revisionswp_posts (post_type = revision) + wp_postmetaHonors database_keep_revisions per parent post and skips custom/excluded post types
auto_draftswp_posts (post_status = auto-draft)Preserves active recent editor sessions so authors currently typing never lose drafts
trash_postsTrashed standard posts & pagesScoped strictly to safe post types (DatabaseCleanupItems::postTypes()), never touching WooCommerce orders
trash_comments & spam_commentswp_comments + wp_commentmetaCleans paired comment metadata alongside trashed and Akismet/spam comment rows
transientsExpired wp_options / wp_sitemeta transientsDeletes only expired transients whose timeout timestamp has already passed
actionswp_actionscheduler_actions + wp_actionscheduler_logsPrunes completed, canceled, or old failed Action Scheduler entries while leaving pending & in-progress jobs untouched
orphansOrphaned wp_postmeta, wp_commentmeta, wp_termmeta, wp_term_relationshipsVerified 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:

  1. 12-Second Time Budget & 80% Memory Ceiling: Each worker batch computes $deadline = min(microtime(true) + 12, REQUEST_TIME_FLOAT + max_execution_time - 3) and monitors memory_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.
  2. Itemized Confirmation Modal: Clicking Run Cleanup opens #kc-dialog showing exact per-category candidate counts and active revision retention rules before a single row is deleted.
  3. Instant Cooperative Cancel (DatabaseCleanup::cancel()): Stores an independent kadicache_database_cancel token (flushing notoptions object cache between checks) so an admin can abort a multi-batch cleanup cleanly mid-run.
  4. 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:

BASHSafe Dry-Run Inspection & Targeted Database Cleanup via WP-CLI
# 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,orphans
Gergis — Lead Systems & Cache Architect
Principal WordPress & Cloud Edge Architect
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

apps/wordpress-plugin/src/Optimization/WordPressCleanup.phpapps/wordpress-plugin/src/Optimization/HeartbeatControl.phpapps/wordpress-plugin/src/Support/DatabaseCleanup.phpapps/wordpress-plugin/src/Support/DatabaseCleanupItems.phpapps/wordpress-plugin/src/Cli/DatabaseCli.php

Technical FAQ

Can Database Cleanup accidentally delete WooCommerce orders, products, or custom post types?

No. DatabaseCleanupItems::postTypes() scopes post/trash/revision operations strictly to safe content post types and explicitly reports excluded custom post types (such as shop_order, shop_Order_placehold, product_variation, and shop_coupon) in DatabaseCleanup::status().

Why does disabling Guest Dashicons in other plugins sometimes break my theme header or mega-menu?

When a plugin stylesheet declares dashicons as a dependency, calling wp_deregister_style("dashicons") causes WordPress to skip printing the dependent stylesheet too. WordPressCleanup.php dequeues dashicons and filters style_loader_src for logged-out guests while keeping the handle registered so dependent CSS files still load.

Will turning Heartbeat API Off break Gutenberg autosave or plugins that call wp.heartbeat?

No. HeartbeatControl.php never disables Heartbeat inside the Post Editor screen ($screen->base === "post"), and on Front-end or Admin screens where Heartbeat is set to Off, it rewires script dependencies and injects a safe window.wp.heartbeat no-op stub so third-party JS never throws TypeErrors.

How does KadiCache prevent PHP timeouts or out-of-memory crashes on huge databases?

DatabaseCleanup::batch() runs inside cooperative Action Scheduler jobs capped at a 12-second wall-clock deadline (and max_execution_time - 3s) plus an 80% PHP memory_limit ceiling, saving its cursor and yielding cleanly to the next batch whenever a limit approaches.

Can I keep the most recent 3 or 5 post revisions instead of deleting all revisions?

Yes. Set Keep Revisions per Post (database_keep_revisions) in WP Admin -> KadiCache -> Database (for example to 5). KadiCache retains the 5 newest revisions of every post and deletes only older historical revisions.

Does cleaning Action Scheduler tables cancel my pending WooCommerce subscriptions or webhooks?

Never. The actions cleanup target removes only completed, canceled, or aged-out historical Action Scheduler rows and their logs—leaving all pending and in-progress scheduled actions untouched.

What happens if my WordPress timezone changes when Scheduled Cleanup is active?

DatabaseCleanup::register() hooks update_option_timezone_string and update_option_gmt_offset to automatically reschedule kadicache_database_scheduled to your updated local maintenance window.