=== BreakTrace ===
Contributors: foramshah1512
Tags: activity log, change tracking, security audit, troubleshooting, file integrity
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Track WordPress changes, file changes, and PHP errors so you can investigate what happened before a website issue occurred.

== Description ==

**BreakTrace** is a change tracking and troubleshooting tool for WordPress site administrators.

When something breaks on a site, the important question is often: *what changed?* BreakTrace records important WordPress activity, selected file changes, and PHP errors so you can investigate the timeline leading up to a problem.

The plugin adds a **BreakTrace** section to the WordPress admin area. It is designed to help with troubleshooting and change visibility; it is not a backup, malware scanner, firewall, or automatic repair tool.

= What it helps you do =

* See recent site changes on a clear admin dashboard
* Browse a filterable Change Timeline of logged events
* Investigate around a problem date and time
* Spot possible connections between PHP errors and earlier changes
* Monitor selected files for created, modified, and deleted changes
* Review Old vs New differences for supported text files
* Capture configuration snapshots and compare them
* Receive email alerts for selected high-impact events
* Exclude users, plugins, files, posts/pages, custom post types, ACF changes, or meta keys; selecting a category with no entries excludes the entire category
* Automatically clean up old event logs according to your retention setting
* Optionally record slow database queries in Slow Query Log (yellow: 100–499 ms; red: 500 ms or more)

= What BreakTrace tracks =

* Posts, pages, and public custom post types
* Post meta and ACF field updates (when ACF is available)
* Plugin, theme, and WordPress core updates
* Important WordPress settings
* User activity such as logins and role-related changes
* PHP errors, warnings, notices, and exceptions
* Selected file integrity changes (core, themes, plugins, and critical root files)

= Built with care =

* Sensitive values such as passwords, API keys, authentication tokens, and payment card data are filtered from intentional storage and email content
* `wp-config.php` and similar secret files are monitored by hash without storing file contents
* File scans are started manually by an administrator; the plugin does not scan the filesystem on every page request
* Deactivation preserves your data
* Uninstall removes only BreakTrace tables, options, and cron events

== Installation ==

1. Upload the `breaktrace` folder to the `/wp-content/plugins/` directory, or install the ZIP from **Plugins → Add New → Upload Plugin**.
2. Activate **BreakTrace** through the **Plugins** screen.
3. Open **BreakTrace** in the WordPress admin menu.
4. Optional: configure email notifications, exclusions, and log retention under **BreakTrace → Settings**.
5. Optional: run a file scan from **BreakTrace → File Monitor** to create the first integrity baseline.

== Frequently Asked Questions ==

= How do I enable Slow Query Log? =

Open BreakTrace → Settings, check Enable Slow Query Log, and save. The Slow Query Log submenu appears after saving. Browse your site or use WooCommerce product filters, then open Slow Query Log to inspect recorded slow queries. Unchecking and saving hides the submenu and stops new capture on subsequent requests; existing records remain subject to query log retention. Choose 7, 15, 30 days (default), or custom days (1–3650) in Slow Query Log settings. Daily automatic cleanup applies this policy separately from activity log retention, even with monitoring disabled. WP-Cron runs on site visits, so low traffic can delay cleanup.

Timing uses WordPress SAVEQUERIES and adds memory and processing overhead, so enable it while investigating and disable it afterward. An existing SAVEQUERIES=false configuration blocks capture and is reported on the monitor page. BreakTrace does not edit wp-config.php or override an existing constant.

Only queries taking at least 100 ms are persisted, with at most the 20 slowest per request. SQL literal values and comments are redacted; request bodies and URL parameters are not stored. Records include calling functions, an associated component when available, and request type. Component attribution is a clue, not proof of responsibility. Full SQL is temporarily held in WordPress request memory by SAVEQUERIES.

Capture starts when this plugin loads. Earlier bootstrap queries, full-page cache hits bypassing WordPress, queries on separate database connections, and work performed while switched to another multisite blog are not captured. This feature measures database queries, not the execution duration of individual filters or browser page loading.


= Does this plugin restore my site or act as a backup? =

No. Snapshots record configuration details for comparison. They are not full site backups and cannot restore files or the database.

= Will deactivating the plugin delete my logs? =

No. Deactivating BreakTrace keeps all your logs, snapshots, file baselines, and settings intact. Data is only removed when you uninstall the plugin.

= Does file scanning run automatically on every page load? =

No. File scans run only when an administrator with `manage_options` starts one from the File Monitor screen.

= Does it work without ACF, WooCommerce, or Elementor? =

Yes. Those plugins are optional. ACF field tracking is active only when ACF is installed and its hooks fire.

= Are passwords and API keys stored? =

BreakTrace is designed not to intentionally store or email passwords, API keys, authentication tokens, secret keys, auth cookies, or payment card data. Sensitive-looking keys are filtered in the logger and related trackers.

= How do email notifications work? =

Notifications are off by default. Enable them in Settings, choose an email address, and select the event types that should trigger alerts. Duplicate emails for the same event ID are prevented.

= Does BreakTrace send data to an external service? =

No. The plugin stores its logs in the WordPress database and uses WordPress `wp_mail()` for enabled email notifications. It does not include a third-party analytics or remote tracking service.

= Does the plugin change PHP error handling? =

BreakTrace registers lightweight handlers to record supported PHP errors, warnings, notices, fatal errors, parse errors, and uncaught exceptions. It does not change `error_reporting()`, `WP_DEBUG`, or public error display, and it passes control to existing handlers when available.

== Screenshots ==

1. Dashboard with summary cards and recent activities.
2. Change Timeline with search and filters.
3. Investigate view showing events around a problem time.
4. File Monitor with scan controls and change list.
5. File Difference Viewer showing Old vs New text changes.
6. Snapshots list, create, and compare screens.
7. Settings for notifications, exclusions, and log retention.

== Changelog ==

= 1.0.1 =
* Security hardening: added nonce verification for Change Timeline filters, Investigate queries, Snapshot view/compare actions, and file diff views, alongside `manage_options` capability checks across admin pages and settings.
* Code compliance updates: added direct file access (`ABSPATH`) guards across PHP files, removed unnecessary core file inclusion in the file scanner, and updated plugin contributor metadata.

= 1.0.0 =
* Initial release.
* Central event logger with risk levels and event meta.
* Dashboard, Change Timeline, Investigate, Error Logs, File Monitor, Snapshots, and Slow Query Log.
* Tracking for posts/CPTs, meta, ACF, plugins, themes, core, settings, users, and PHP errors.
* File integrity scanning, change detection, and text diff viewer.
* Email notifications, exclusions, log retention, and daily cleanup cron.
* Security hardening and performance improvements for queries and file scans.

== Upgrade Notice ==

= 1.0.1 =
Security hardening and WordPress.org compliance updates, including nonce verification on admin filters and views.

= 1.0.0 =
Initial public release of BreakTrace.