=== Intouch Orphan Table Cleaner ===
Contributors: intouchdesigndev, ikaroweb
Tags: database, cleanup, optimization, orphan tables, database cleaner
Requires at least: 6.2
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.1.5
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Scan the database for "orphan" tables created by uninstalled plugins and safely remove them to keep your WordPress lightning fast.

== Description ==

**Intouch Orphan Table Cleaner** is an essential tool to keep your WordPress database clean and optimized. When you uninstall plugins, they often leave behind "orphan" tables that consume space, clutter your database, and can slow down your site over time. This plugin intelligently scans your database to identify these unnecessary tables and helps you manage them.

The plugin uses an extensive local dictionary of known plugins and table structures, ensuring that it correctly identifies exactly which plugin an orphaned table belonged to.

### Key Features:
* **Smart Scanner:** Identify abandoned database tables left by uninstalled plugins.
* **Smart Dictionary:** Safely maps tables to their original plugins using an extensive built-in mapping system.
* **Dry Run Mode:** Temporarily suspend tables by renaming them safely before committing to permanent deletion.
* **Single Table Backup:** Download single-table backups directly from the admin panel.
* **Database Optimization:** Reclaim fragmented overhead space with one click.


== Installation ==

1. Upload the plugin files to the `/wp-content/plugins/intouch-orphan-table-cleaner` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress.
3. Access the Intouch Orphan Table Cleaner dashboard from your WordPress admin menu to start scanning for orphan tables.

== Frequently Asked Questions ==

= Is it safe to delete orphan tables? =

While the plugin is designed to carefully identify tables that are no longer in use, it is **highly recommended** to create a full database backup before deleting any tables. A backup ensures you can easily restore your data if something goes wrong.

= Will this break my site? =

The plugin allows you to test table removal using Dry Run (Suspend) mode first. Furthermore, it uses a smart mapping system to protect core WordPress tables and popular shared libraries (like Action Scheduler).

== External services ==

This plugin uses Freemius to handle plugin updates, optional license activation for the paid upgrade, and anonymous, opt-in diagnostic usage data (you are asked for consent on activation and can decline).

* Service: Freemius (https://freemius.com)
* Data sent: plugin slug/version, site URL, and (only if you opt in) anonymous, non-personal usage data used to check for updates and, for opted-in sites, to improve the plugin.
* Terms of Use: https://freemius.com/terms/
* Privacy Policy: https://freemius.com/privacy/

Aside from Freemius, this plugin does not connect to any other external service. All orphan-table detection runs locally against a built-in dictionary of known plugin table prefixes; no data about your database is sent anywhere.

InTouchDesign's own Terms of Use and Privacy Policy (covering this website and paid plugin purchases) are available at:
* Terms of Use: https://dev.intouchdesign.it/terms/
* Privacy Policy: https://dev.intouchdesign.it/privacy/

== Screenshots ==

1. The main Scanner dashboard showing orphan tables mapped to their original plugins.
2. The Settings tab with automated Cron optimizations.
3. Pro: Automatic Optimization and Monthly Email Report settings.

== Changelog ==

= 1.1.5 =
* Fix: The Freemius SDK helper was only guarded against redeclaration, not the rest of the plugin's main-file logic (activation/deactivation hooks, core bootstrap). If the Free and Premium plugin folders were ever both present and active at once (e.g. right after uploading the Premium package under a different folder name), this caused a fatal `Cannot redeclare function iotc_plugin_activate()` error. All main-file logic is now wrapped per Freemius's documented pattern, calling `set_basename()` instead of redeclaring when a second copy loads.
* Fix: Guarded the `IOTC_VERSION` constant definition with `defined()` to avoid a "Constant already defined" warning under the same dual-folder scenario.

= 1.1.4 =
* Fix (Pro): Email Reports interval was hardcoded to monthly and ignored settings; now the report frequency (weekly/monthly/custom days) is configurable and actually reschedules the cron job.
* Fix (Pro): Report email body now states the site name and URL, so multi-site license holders can tell which site sent it.

= 1.1.3 =
* Fix: Emergency-restore standalone page now loads its stylesheet via `wp_register_style()`/`wp_enqueue_style()` instead of an echoed `<link>` tag, per WordPress.org review feedback.

= 1.1.2 =
* Fix: Removed all inline `style` attributes and `onclick` handlers from the admin dashboard screen; moved to the enqueued CSS/JS files per Guideline standards.
* Fix: Asset cache-busting version was hardcoded and had drifted from the plugin version; now driven by a single `IOTC_VERSION` constant.
* Fix: Corrected a fragile `plugins_url()` base-path argument in the emergency-restore AJAX handler.
* Fix: Narrowed the Wordfence table-prefix match (`wf`) to reduce false-positive orphan detection on unrelated tables.

= 1.1.1 =
* Fix: Excluded `.claude` and `skills-lock.json` dev tooling files from the production ZIP (.distignore).
* Fix: Corrected "External services" section in readme.txt to properly disclose Freemius (the actual external service used) with valid Terms of Use/Privacy Policy links, and updated InTouchDesign's own Terms/Privacy links to live pages.
* Fix: Unified emergency-restore table rename query to use `$wpdb->prepare()` with `%i` identifier placeholders.
* Fix: Updated hardcoded asset cache-busting version to match plugin version.
* Fix: Restored a missing closing brace in class-iotc-actions.php (fatal parse error introduced by a prior edit).

= 1.1.0 =
* Fix: Removed all license checks and gated logic from free cron code.
* Fix: Updated Terms and Privacy URLs in readme.txt to valid public pages.
* Fix: Removed ABSPATH string replacement in emergency-restore script per Guideline location standards.
* Fix: Removed inline styles from emergency restore page to use enqueued CSS.
* Fix: Excluded .wordpress-org folder from production release zip package.

= 1.0.9 =
* Fix: Updated Freemius initialization for WordPress.org compliance.
* Fix: Separated Pro features trait for clean free vs pro deployment.
* Fix: Aligned menu page slugs and asset enqueue URLs.

= 1.0.8 =
* Fix: Resolved trialware guidelines compliance by removing Pro locks/teasers in free mode.
* Fix: Separated premium code actions into a trait for conditional loading.
* Fix: Removed inline styles from emergency restore script and extracted them to CSS file.
* Fix: Excluded po/mo translation files from package to use translate.wordpress.org.

= 1.0.7 =
* Fix: Inlined `$wpdb->prepare` calls inside `$wpdb->query` to satisfy strict `WordPress.DB.PreparedSQL.NotPrepared` coding standard checks.

= 1.0.6 =
* Fix: Prefixed AJAX actions and cron hooks with `iotc_` to comply with Plugin Guidelines.
* Security: Refactored SQL queries to use `$wpdb->prepare()` with the `%i` identifier placeholder for safe schema modifications.
* Fix: Excluded build artifacts and hidden directories from deployment zip to comply with WordPress.org Plugin Checker.

= 1.0.5 =
* Fix: Addressed strict edge cases in Plugin Checker for I18n translations on error responses.
* Fix: Adjusted ABSPATH security check structure in emergency-restore script to pass static AST tests.

= 1.0.4 =
* Fix: Preserved I18n translation comments during Freemius minification by extracting strings into variables.
* Fix: Added direct database query overrides and `ABSPATH` fallbacks for `emergency-restore.php`.

= 1.0.3 =
* Fix: Addressed WordPress Plugin Checker errors (i18n missing translators comments, unprefixed variables/functions, and emergency restore security).

= 1.0.2 =
* Minor fixes.

= 1.0.0 =
* Initial release on WordPress.org repository.
