=== Harvify Database Cleaner ===
Contributors: jethalal
Tags: database, cleanup, optimize, revisions, transients
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.26
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Scan and clean your WordPress database, with a dry-run preview before anything is deleted. Pro adds daily scheduling and one-click rollback.

== Description ==

Harvify Database Cleaner helps you reclaim wasted database space from post revisions, auto drafts, trashed posts and comments, spam, pingbacks and expired transients, and shows you what is taking up room before anything is removed.

**Free features:**

- Scan and report: row counts + estimated sizes for every category this download
  can clean
- **Clean revisions, keeping the last N per post** — you choose how many, and
  zero means delete them all
- Clean auto drafts, trashed posts, spam/trashed comments
- Clean expired transients and pingbacks/trackbacks
- Table optimization (reclaim freed space)
- Orphaned table & option detection (read-only report + keep-list)
- **Autoloaded-options analysis** — the total size of your autoloaded options
  against the point where it starts to hurt, and the largest offenders listed by
  size.
- Basic scheduled cleanup (weekly/monthly)

**Pro features (Harvify Pro Bundle):**

- Orphaned metadata (post, user, term, comment meta)
- Duplicate meta detection
- oEmbed cache cleanup
- WooCommerce: orphaned order items, expired sessions
- Delete orphaned options (known removed-plugin signatures only)
- **Action Scheduler table cleanup** — removes completed, failed and cancelled
  actions older than 30 days, with their log rows; pending work is never
  touched.
- **Pre-cleanup snapshots** with one-click rollback
- Advanced scheduling (daily) + email reports + cleanup history log

== Installation ==

1. In your dashboard go to Plugins → Add New, search for "Harvify Database Cleaner",
   then install and activate it (or upload the ZIP under Plugins → Add New → Upload).
2. Open **Harvify → Database Cleaner**. The first time, you are asked whether to
   share usage data with Freemius; choose **Skip** to use every free feature without
   sending anything.

= Cleaning your database =

1. Back up your database first. Deleted rows cannot be brought back without a backup.
2. On the **Cleanup** tab click **Scan database**. Each category shows how many rows
   it would remove and roughly how much space that frees. Nothing is deleted by a scan.
3. Tick the categories you want to clean. For post revisions, enter how many to keep
   in **Keep last … revisions per post** and click **Save** (0 removes them all).
4. Click **Dry run (preview)** to see exactly what would be removed, then
   **Clean selected**.

= Other tabs =

* **Schedule** — tick **Enable scheduled cleanup**, choose weekly or monthly, pick the
  categories (scan first so they are listed) and click **Save schedule**.
* **Orphans** — tables and options that look left behind by plugins you have
  removed. It is a report: nothing here is deleted in the free version, and
  **Keep selected (hide)** removes an item from the list if you still need it.
* **Insights** — after a scan, what takes up the most room, and how large your
  autoloaded options are.

== Frequently Asked Questions ==

= Does a scan delete anything? =

No. A scan only counts. Nothing is removed until you click **Clean selected**, and
**Dry run (preview)** shows exactly what would be removed first.

= What does it remove? =

Only the categories you tick: post revisions (beyond the number you keep), auto
drafts, posts and comments already in the trash, spam comments, pingbacks and
trackbacks, and expired transients. Published posts and pages, and approved
comments other than pingbacks and trackbacks, are not removed. Table optimization
reclaims space without deleting rows.

= Can I undo a cleanup? =

In the free version, only by restoring a backup, so back up before a large
cleanup. Pro takes a snapshot before each cleanup and offers one-click rollback.

= Does it work with WooCommerce? =

Yes. Pro adds WooCommerce cleanup for orphaned order items and expired sessions.

== Screenshots ==

1. Scan first: row counts and estimated sizes per category, before anything is
   deleted.
2. Insights: what is taking up room, and what a cleanup would reclaim.
3. What the free tier cleans, and what a licence adds.

== External services ==

This plugin connects to Freemius, the licensing and update service Harvify uses to
sell and deliver the Pro tier of its plugins.

Nothing is sent to Freemius unless you choose to send it. On activation you are shown
Freemius's standard opt-in screen. Until you answer it a fresh install makes no
outbound request at all, and if you choose Skip the free tier stays fully usable
and still sends nothing. Data is transmitted only when you take one of these
actions:

* **You click "Allow & Continue" on the Freemius opt-in screen.** This sends your
  site address, your administrator email address, and your WordPress, PHP and active
  plugin/theme details, so Harvify can provide support and know which environments to
  test against. Skipping that screen sends nothing and leaves the plugin working
  normally.
* **You enter a Pro Bundle licence key.** This sends the key together with your site
  address so the licence can be activated for that site. While a licence is active the
  site also re-checks periodically that it is still valid and whether a Pro update is
  available.

Service provided by Freemius, Inc. - https://freemius.com/
Terms of service: https://freemius.com/terms/
Privacy policy: https://freemius.com/privacy/

== Changelog ==

= 1.0.26 =

* Readme: step-by-step setup and usage instructions, a frequently asked questions
  section, and a plainer description of what the free and Pro tiers include.

= 1.0.24 =

* **Fixed: the "Keep last N revisions per post" control now appears on the
  Cleanup screen in the free tier.** 1.0.23 made the setting free and the cleaner
  honoured it without a licence, but the box to change it was still drawn only for
  licensed sites, so a free user had no way to set it. It now shows after a scan in
  every licence state.
* Changed: the External services section now describes the Freemius opt-in screen
  shown on activation. Until you answer it a fresh install makes no outbound
  request, and choosing Skip keeps the free tier fully usable and sends nothing.

= 1.0.23 =

* **"Keep last N revisions per post" is now free.** The setting existed and the
  cleaner that honours it shipped in every download; only a licence check stopped
  it working, so a free user could not keep a single revision. Set it to 0 to
  delete them all, as before.
* Changed: the twelve Pro cleaner categories — orphaned and duplicate metadata,
  orphaned term relationships, oEmbed caches, pending comments, the WooCommerce
  categories and Action Scheduler cleanup — are supplied by the separately
  distributed Pro plugin rather than being present-but-inactive in this download.
  This download scans and cleans the eight categories it owns.
* Changed: daily scheduling is likewise supplied by the Pro plugin. Weekly and
  monthly scheduling are unchanged and remain free.
* **Changed: every identifier this plugin owns has been renamed** off its old
  three-character `hdc_` prefix, which is shorter than WordPress.org accepts.
  Functions, options and the plugin's own actions and filters are now
  `harvify_dbclean_*`; global constants are `HARVIFY_DBCLEAN_*`; classes are
  `Harvify_DBClean_*`.
* **Developers: the REST namespace is now `harvify-dbclean/v1`. The old `hdc/v1`
  namespace is GONE and there is no compatibility alias** — any code calling it
  will 404 until updated. The admin script and style handle `hdc-admin` is now
  `harvify-dbclean-admin`, and the localized JavaScript object `hdcSettings` is
  now `harvifyDbcleanSettings`.
* **Fixed (Pro): "Duplicate post meta" and "Duplicate user meta" no longer delete
  legitimate values.** A duplicate now means the same key AND the same value. The
  cleaner previously removed every additional value stored under one key — for
  example all but one of the previous-slug records WordPress keeps so old links
  still redirect.
* **Fixed (Pro): "WooCommerce orphaned order items" no longer matches real
  orders.** On stores using WooCommerce's high-performance order storage it
  counted — and would have deleted — the line items of every order, and on older
  storage it also matched refund and subscription line items. An item is now only
  treated as orphaned when its order no longer exists anywhere.
* Fixed: asking for a cleanup frequency this installation cannot run is now
  refused with a clear message naming the frequencies that are available. It
  used to answer "saved" and quietly store weekly instead.
* Fixed: the Schedule screen now shows your saved schedule on every site.
  Weekly and monthly scheduling are free, but the screen only read the saved
  schedule when Pro was active, so a free site always showed it as unset.
* Fixed: when the server refuses a request, the screen now shows the reason.
  Every refusal used to be treated as a success, so a refused save said
  "Schedule saved." and a refused cleanup reported "Cleaned undefined rows".
* Fixed: when the frequencies a site can run change, the scheduled cleanup is
  rescheduled to match on the next admin visit or cron run. Your saved
  frequency is not changed.
* **Fixed (Pro): when the Pro licence is not active, the Pro plugin stops
  running Pro features** — its twelve cleaner categories, daily scheduling,
  pre-cleanup snapshots, cleanup history and email reports. Nothing you saved
  is removed: the twelve categories stay listed and are still counted by a
  scan, a daily schedule keeps running weekly, and re-activating the licence
  restores everything. Asking to clean one of those categories now says why it
  cannot run instead of reporting zero rows.
* Fixed (Pro): a scheduled cleanup is recorded once in the cleanup history. It
  used to appear twice, once labelled as a manual cleanup.
* Fixed: Table Optimization reads the free space of the table it names. A
  table name was matched as a pattern, so a table with nothing to reclaim could
  be offered because a similarly named table had free space. The size shown for
  a leftover table uses the same exact match.
* Changed: the plugin's loader no longer creates an unprefixed global variable.
* Fixed: the Schedule screen lists frequencies in order: Daily, Weekly, Monthly.
* Fixed: the upgrade card no longer lists "keep last N revisions" as a Pro
  feature, and the Plan screen lists it under the free tier, where it is.
* Fixed: the Action Scheduler cleanup (Pro) is described accurately. It removes
  completed, failed and cancelled actions older than 30 days, with their log
  rows; it never empties the tables.
* Your settings, your schedule and your scheduled cleanup are migrated onto the
  new names on the first page load after updating. Your cleanup history and
  snapshot tables are untouched — those names never changed.





= 1.0.17 =

* Added: a single **Support** entry in the Harvify menu, so you can reach us from
  inside WordPress. Until now no plugin offered a contact route at all. One entry for
  the whole suite rather than one per plugin.
* No behaviour changes.

= 1.0.16 =

* Added: an **External services** section to this readme, naming every third-party
  service the plugin can contact, exactly what is sent, when, and each provider's terms
  and privacy policy. Required for WordPress.org submission.
* Changed: the `Contributors` field now names the correct WordPress.org account.
* No behaviour changes.

= 1.0.15 =

* Fixed: deactivating or deleting the plugin now cancels the scheduled cleanup.
  The cleanup is queued through Action Scheduler, but the cancellation used the
  WordPress cron function, which reads an entirely different store -- so it
  reported success and removed nothing.

= 1.0.14 =

* Rebuild: the published 1.0.13 package was generated from an earlier tree. Documentation
  only; no behaviour changes.
= 1.0.13 =
* Added: a single **Manage licence** link on the Plan screen, so an active customer can
  deactivate this site, change their licence key or re-check their licence without
  needing a URL from support. No per-plugin Account tab is added.
= 1.0.12 =
* Fixed: opting in to "delete all data on uninstall" now removes hdc_db_version.
  It was written at runtime but never included in the cleanup, so a user who
  asked for their data to be deleted kept it.
= 1.0.11 =
* **Fixed: updating the plugin did not update its database.** WordPress only runs a plugin's
  setup routine when you *activate* it, never when it updates — so a change to the plugin's own
  tables never reached sites that had simply updated. On those sites some features failed with a
  database error. The update now applies itself on the next page load.
* **Fixed: a malformed API request returned a PHP error** instead of a normal "bad request"
  response.
* **One upgrade link instead of one per plugin.** With several Harvify plugins active the
  menu showed a row called "Upgrade" for each of them, all identically labelled, and it kept
  saying Upgrade to people who had already bought. They are replaced by a single **Plan**
  screen that says what the bundle costs, what it covers, and whether your licence is active.
* **The dashboard is quiet again.** Each plugin used to add its own "opt in to make this
  better" notice to the main WordPress dashboard, so five plugins meant five notices. Harvify
  plugins now share one queue: promotional notices appear only on Harvify's own screens, and
  only one at a time. Licence and account messages are never held back.
* **Fixed: the "Data & uninstall" box covered the page.** It was being drawn into the admin
  footer, which WordPress pins to the bottom of the screen, so it floated on top of whatever was
  underneath it. It now sits in the page like any other card. Saving it also tells you what it
  saved, instead of just reloading.
* **Fixed: the upgrade screen advertised the wrong number of sites.** Several plugins listed
  the Freelancer and Agency plans as covering 5 and 25 sites. They cover 3 and 10.

= 1.0.10 =
* **Uninstall no longer destroys your data by default.** Deleting the plugin used to remove
  everything it had stored, with no way to stop it -- so deleting it to troubleshoot took the lot
  with it. Now the default is to KEEP your data, and a new **Data & uninstall** control on the
  plugin's own screen lets you opt in to a full wipe if that is what you want. Scheduled jobs are
  always tidied up either way, and the wipe works with no internet connection.

= 1.0.9 =
* Two long-standing WPCS errors cleared (a `strlen()` in a loop condition in the orphan
  scanner, and a doubled blank line in the Pro scheduler). No behaviour change -- but they
  were failing the build gate, so the plugin could not be packaged for Freemius at all.
* **Deleting the plugin left its database tables behind, on every site, since 1.0.0.** The main
  plugin file used a variable named `$file` while loading its includes. WordPress runs
  `include_once` on that file from INSIDE its own `uninstall_plugin()` function, so the
  assignment overwrote WordPress's `$file`; core then fired its uninstall action under a nonsense
  name, the cleanup callback was never reached, and the plugin's tables, options and scheduled
  events survived deletion forever. The loader variable is now prefixed.

= 1.0.8 =
* **Fixed: Undo could not always put everything back.** The snapshot used to be built from a
  list of the tables we expected each cleanup to touch. WordPress deletes more than that on our
  behalf, so four cleanups removed rows the snapshot never saw: Post Revisions destroyed the
  trash metadata of trashed posts (which is what lets WordPress restore them to their previous
  status), Trashed Posts destroyed those posts' revisions and their comments' metadata, and
  Action Scheduler cleanup destroyed the log entries of the tasks it removed. The snapshot is
  now taken from the deletions themselves, as they happen, so it covers whatever the cleanup
  actually removes.
* Fixed: "Undo last cleanup" returned an error after a Table Optimization run. Optimising tables
  deletes no rows, so there was nothing to undo -- it now says so instead of failing.
* **Fixed: orphan detection offered options belonging to live plugins for deletion.** Plugins
  bundle each other's libraries, so an option can look abandoned while a plugin that is running
  right now depends on it. Detection now checks whether any installed plugin or the active theme
  actually references an option or table before calling it orphaned.
* Fixed: the orphaned-tables report listed tables created by plugins that were installed and
  running, because a table name rarely contains its plugin's name.

= 1.0.7 =
* Your licence is now manageable from the plugin itself. The Account screen was previously
  hidden, which also hid **Deactivate License** — so a licence could not be released from one
  site to move it to another without contacting support. It is visible again, along with the
  licence key, plan, Sync and Change License.
* **Harvify → Tools** now opens with a **Your licences** table: every installed Harvify plugin,
  the plan it is on, whether Pro features are actually running, and a link to its Account screen.
  Freemius gives each product its own separate Account page, so this is the one place that
  answers "what am I on" across the whole bundle.
* The repeated *"Opt in to make … better!"* admin notice no longer appears. Licence, plan and
  update notices are unaffected — only the opt-in prompt is suppressed.

= 1.0.6 =
* Change: License activation now uses per-plugin key entry — enter your bundle license key on each Pro plugin to unlock Pro. Improves activation reliability.

= 1.0.5 =
* New: autoloaded-options analysis in Insights — total autoloaded size (vs the 800 KB Site Health threshold) and the largest autoloaded options with a likely-source guess (core / theme / widgets / transient / plugin, active or removed). Read-only: nothing is deleted from this view; option deletion remains the snapshotted, signature-matched Orphans path.

= 1.0.4 =
* New admin design system (Harvify Admin Kit): branded header, first-run onboarding, section navigation (Cleanup, Orphans, Schedule, Insights), skeleton loader, coaching empty states, an at-a-glance Insights panel (reclaimable rows & space, categories with waste, biggest offenders, what-can-be-reclaimed breakdown), and a contextual, dismissible upgrade card. UI layer only — scanning, cleaning, dry-run, snapshots and free/Pro gating are unchanged.

= 1.0.3 =
* Fix: Pro features now unlock only on the premium build with a valid license (per-plugin gate). Previously a shared bundle flag could make the free build report Pro when another Harvify plugin was licensed.

= 1.0.2 =
* Internal: uninstall cleanup now runs on Freemius's after_uninstall hook (removed uninstall.php) for Freemius Deployment compatibility. What gets removed on uninstall is unchanged.

= 1.0.1 =
* Keep-last-N-revisions is now correctly Pro-gated server-side (free deletes all revisions, matching the matrix).
* Clarified the free/Pro split: orphan detection (tables + options) is free and read-only; deleting orphaned options is Pro.

= 1.0.0 =
* Initial release.
