=== Mega Database Cleanup - Optimize Database, Clean Sweep & Speed Up Performance ===
Contributors: megawixtech
Donate link: https://www.megapluginhub.com
Tags: database cleaner, clean, optimize, postmeta, cleanup
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 3.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Mega Database Cleanup is your ultimate optimization suite to clean database junk, speed up your site, monitor real-time health, and automate cleanups safely.

== Description ==

Is your WordPress site feeling sluggish and bloated? Over time, your database fills up with useless data like old post revisions, spam comments, expired transients, and orphaned postmeta. This bloat slows down your website, ruins your performance, and makes database backups take forever.

Meet **Mega Database Cleanup** — a lightweight but incredibly powerful database cleaner built to help you optimize and clean your WordPress database safely. 

I built this plugin because I was tired of other database cleaners locking the best features behind expensive premium walls. With Mega Database Cleanup, you can easily clean up your database, optimize performance, and get rid of junk without breaking your site.

🔥 **Premium Features... But for FREE!** 🔥
Why pay for premium add-ons? We give you the tools you need to speed up your website absolutely FREE:
* **Beautiful Database Analytics & Charts**: Visually track your database size and see exactly what junk is slowing you down.
* **Action Scheduler Cleanup**: If you run WooCommerce, your database is likely filled with thousands of Action Scheduler logs. We let you clean completed and canceled actions for free!

### Why You Need to Clean Your Database

👉 **Speed Up Website Performance**: A clean database means faster queries, quicker load times, and a better experience for your visitors.
👉 **Reduce Database Bloat**: Easily clean postmeta, user meta, and term meta that are no longer linked to anything.
👉 **100% Safe to Use**: We built a unique **Safety Vault System**. Before any cleanup runs, your data is safely backed up locally so you can restore it if needed.

= 🚀 Everything You Get for Free =
* **One-Click Quick Clean**: Instantly remove old Post Revisions, Trashed Content, Spam Comments, and Expired Transients.
* **Database Growth Analytics**: Free visual charts to monitor your optimization efforts.
* **Action Scheduler Cleaner**: Keep your WooCommerce database lean.
* **Granular Control**: Safely clean Auto-drafts, Pingbacks, Trackbacks, Pending Comments, Orphaned Relationships, and oEmbed Caches.
* **Item-by-Item Cleanup**: Want to manually inspect and delete? You can view and clean Options, Cron Jobs, Post Meta, User Meta, and Term Meta line by line.
* **Empty Meta Scanner**: Detect and remove empty, null, or serialized-empty metadata effortlessly.

= ⚡ Need More Power? (Mega Database Cleanup Pro) =
For power users and agencies, our Pro version adds:
* **Automated Background Cleanups**: Set it and forget it. Schedule hourly or daily cleanups via WordPress cron.
* **Automatic Safety Backups**: Take a snapshot of your tables before every scheduled run.
* **WooCommerce Junk Cleaner**: Clean expired shop sessions and abandoned carts.
* **Media Optimizer**: Remove unattached images and orphaned media.
* **ACF Cleanup Engine**: Deep scanning for orphaned Advanced Custom Fields (ACF) data.

✨ **Take control of your database today!** [Learn more about Pro here](https://www.megapluginhub.com/plugins/mega-database-cleanup).

#### 🛡️ Safe, Secure, and Hub-Connected
This plugin connects directly to the Mega Plugin Hub dashboard, allowing you to manage your cleanup settings remotely. It's perfect for developers managing multiple client sites. All data sync happens securely via webhooks.

== External services ==

This plugin relies on external third-party services and APIs to provide licensing and settings synchronization features. By using this plugin, you agree to their respective terms and privacy policies:

1. Mega Plugin Hub (https://api.megapluginhub.com / https://www.megapluginhub.com)
   - **Usage**: Used to verify your license key, sync plugin settings, and trigger cleanup actions remotely.
   - **Data Sent**: Sends your license key and plugin settings during sync. No database content or user data is ever transmitted.
   - **Terms & Privacy**: Terms of Service: https://www.megapluginhub.com/terms-condition/ , Privacy Policy: https://www.megapluginhub.com/privacy-policy/

== Installation ==

= Automatic Installation =
1. Go to **WordPress Admin → Plugins → Add New**
2. Search for **Mega Database Cleanup**
3. Click **Install Now** → **Activate**
4. Look for **Mega Database Cleanup** in your left sidebar menu!

= Manual Installation =
1. Download the plugin ZIP file.
2. Go to **Plugins → Add New → Upload Plugin**.
3. Select the ZIP and install.
4. Click **Activate Plugin**.

= Initial Setup =
1. Open **Mega Database Cleanup** from your WordPress sidebar.
2. Enter your Mega Plugin Hub License Key to connect.
3. Your settings will automatically sync.
4. Run your first database optimization and enjoy a faster site!

== Frequently Asked Questions ==

= Is this database cleaner safe to use on a live site? =
Absolutely! We designed this to be the safest database cleaner on the market. Before running any major cleanup, data goes into our **Safety Vault**. You can also create manual snapshots. Just to be extra safe, we always recommend taking a full database backup before doing any aggressive optimization.

= Will it accidentally delete my actual posts or users? =
Never. The plugin only targets orphaned data, postmeta junk, and temporary caches that WordPress no longer needs. Your real content is 100% safe.

= What are revisions and why should I clean them? =
Every time you save a draft in WordPress, it stores a revision. Over months, these pile up and bloat your database. Cleaning them removes this dead weight. We use native, safe SQL queries like: `DELETE FROM posts WHERE post_type = 'revision'`

= What are expired transients? =
Transients are temporary caches stored in your `wp_options` table. Sometimes they expire but don't delete themselves. We clean these up to help improve your site's response time (TTFB).

= How does the Action Scheduler cleanup work? =
If you use WooCommerce, you probably have thousands of action scheduler logs taking up space. Our free tool lets you clear completed, failed, or canceled logs in one click.

= What is the Safety Vault? =
It's a custom table on your own server where we temporarily store deleted metadata. If something goes wrong, you can restore it from the Snapshot Manager. Your data never leaves your server!

== Screenshots ==

1. Health Dashboard - Real-time database health metrics and score
2. Cleanup Modules - One-click targeted cleanup for revisions, spam, and transients
3. Meta Cleaner - Advanced orphaned meta scanner and filter
4. Snapshot Manager - Backup and restore deleted metadata
5. Settings - License key, scheduler, and Hub sync configuration

== Changelog ==

= 3.0.0 =
* New: Real-time Settings Sync via Mega Plugin Hub webhook integration.
* New: License-aware tier detection (Free vs Pro) with automatic feature gating.
* New: Secure `X-Mega-License` header authentication for all Hub communications.
* Improved: Modular settings architecture with per-setting toggle persistence.
* Improved: Background cleanup actions now report status back to Hub dashboard.
* Fixed: Settings not persisting correctly across plugin updates.

= 2.0.0 =
* Major Overhaul: Completely redesigned modular class-based architecture.
* New: Health Score Dashboard with real-time database diagnostics.
* New: Support for User, Term, and Comment metadata cleanup.
* New: Targeted cleanup modules for Revisions, Trash, Spam, and Transients.
* New: Safety Vault system to temporarily secure deleted data.
* New: Metadata Snapshot system for manual backups and restoration.
* New: Modern tabbed UI with improved user experience.
* Added: Telemetry system for anonymous site optimization diagnostics.

= 1.1.1 =
* Fixed: Critical PHP compatibility issue by replacing modern arrow functions with traditional anonymous functions, ensuring support for older server environments.
* Fixed: Resolved a glitch that caused plugin deactivation during the update process due to script execution timeouts on some servers.
* Improved: Better handling of plugin state during version transitions.

= 1.1.0 =
* Added optional activation popup: subscribe to plugin update tips (email stored locally only)
* Added deactivation feedback popup: 6 selectable reasons + custom text (stored locally only)
* Plugin now appears as a top-level menu item in the WordPress sidebar
* Quick-access link added to the WordPress admin bar (header)
* All new features are fully WordPress.org compliant

= 1.0.0 - Initial Release =
* Empty meta scanner and preview mode
* ACF orphan cleanup with pattern-based detection
* Scheduled automatic cleanup (hourly/daily/weekly)
* Backup table to store deleted meta rows
* Retention rule: keep latest N entries per meta_key
* One-click delete all empty metadata
* Add/remove ACF patterns
* Inline logs and real-time reports
* Fully optimized SQL cleanup
* Admin UI with jQuery enhancements

== Upgrade Notice ==

= 3.0.0 =
Major Hub integration update. Enables real-time settings sync from Mega Plugin Hub and license-tier-based feature gating. Recommended for all users.

= 2.0.0 =
A major performance and safety upgrade with a new health dashboard, expanded cleanup modules, and a professional modular engine. Recommended for all users.

= 1.1.1 =
Critical hotfix that improves PHP compatibility and fixes a bug where the plugin would deactivate itself after an update. Recommended for all users.

= 1.0.0 =  
Initial release of Mega Database Cleanup.  
Adds full database cleanup toolkit with backup, preview, and automated cleanup scheduler.

== Privacy Policy ==

Mega Database Cleanup is committed to transparency regarding user data:

* **No external data transmission** — No database content ever leaves your site.
* **License sync only** — Only your license key and plugin settings are sent to Mega Plugin Hub for verification and sync. No user data, posts, or database rows are transmitted.
* **Database backups** — Backup data is stored in a dedicated custom table on your own database server and never sent externally.
* **Activation popup (optional)** — If you enter your email in the welcome popup, it is saved to your site's `wp_options` table only. It is never sent to any third-party server.
* **Deactivation feedback (optional)** — If you submit a deactivation reason, it is saved locally to your site's `wp_options` table. It is never sent externally.

== Developer Hooks ==

= Filters =
* `mega_db_cleanup_patterns` - Modify cleanup patterns
* `mega_db_cleanup_retention_limit` - Change default "keep latest N" count

= Actions =
* `mega_db_cleanup_before_delete` - Fires before deletion
* `mega_db_cleanup_after_delete` - Fires after deletion

== Credits ==

Developed with ❤️ by [MegaWix Technologies](https://www.megawix.com/)

* Plugin Development: MegaWix Technologies
* Testing & QA: MegaWix Technologies

== Support ==

Need help? Have a question or feature request?

* Website: https://www.megapluginhub.com
* Email: support@megapluginhub.com

We are committed to providing reliable support and regular updates to ensure this plugin remains compatible with the latest WordPress versions.