=== Konfyra Omni Guard ===
Contributors:      gsrcoimbatore
Tags:              plugin dependencies, safety, fatal error, white screen of death, dependency guard
Requires at least: 6.0
Tested up to:      7.1
Requires PHP:      8.0
Stable tag:        1.0.1
License:           GPL-2.0-or-later
License URI:       https://www.gnu.org/licenses/gpl-2.0.html

Prevents WordPress "White Screen of Death" crashes caused by missing plugin dependencies. Scans, guards, and alerts — silently.

== Description ==

**The problem Omni Guard solves:**

Prevents WordPress White Screen of Death from missing plugin dependencies. Static scanner, runtime guard, pre-flight checks. Free.

This happens constantly. WordPress has no built-in protection for it. Omni Guard fills that gap.

**How it works — four layers of protection:**

**1. Static Scanner**
Analyses the PHP source code of all active plugins using PHP's tokeniser (no regex, no exec). Builds a dependency map: which plugin calls functions defined in which other plugin. Runs twice daily via WP-Cron and whenever a plugin is activated or deactivated.

**2. Runtime Error Handler**
Registers a `set_error_handler()` and `register_shutdown_function()` at priority 1, before any other plugin fires. If an undefined function call occurs at runtime, Omni Guard catches it, logs the incident, and — in admin — shows a clean recovery page instead of a blank screen.

**3. Dependency Pre-flight Check**
On every admin request, reads the dependency map and verifies that every mapped cross-plugin function actually exists right now. If any is missing, an admin notice fires *before* any plugin code tries to call it.

**4. Developer Safety Shims — `og_call()`, `og_exists()`, `og_guard()`**
Global helper functions that plugin developers can use to make their cross-plugin calls crash-proof:

```php
// Returns WP_Error if missing — never crashes
$result = og_call( 'some_plugin_function', $arg1, $arg2 );

// Boolean existence check
if ( og_exists( 'some_plugin_function' ) ) { ... }

// Call with a fallback
$result = og_guard( 'some_plugin_function', fn() => 'default', $arg1 );
```

**Admin Dashboard includes:**
* Live dependency health overview with KPI cards
* Full dependency map (filterable by risk level: high / medium / low)
* Incident log with detection method, timestamp, URL, and alert status
* Pre-flight status: functions missing *right now*
* Settings: scan depth, email alerts, whitelist, ignore list, danger zone

**Email alerts** are throttled to once per function per hour, with a maximum of 5 per day, to avoid noise.

**Zero impact on production performance** — scanning runs in WP-Cron background jobs. The runtime guard adds a single error handler registration at init. No database queries on the frontend unless a pre-flight is triggered.

== Installation ==

1. Upload `omni-guard.zip` via Plugins → Add New → Upload Plugin
2. Activate
3. Go to **Omni Guard → Dashboard**
4. Click **Run Scan Now** to build the initial dependency map
5. Optionally enable email alerts under **Omni Guard → Settings**

== Frequently Asked Questions ==

= Does this fix missing dependencies? =
No. It prevents your site from crashing when they go missing, logs the incident, and alerts you. You still need to re-activate the missing plugin or remove the dependency.

= Does the scanner modify any plugin files? =
Never. Omni Guard is read-only at the filesystem level. It analyses files but never writes to them.

= Will this slow down my site? =
No. Scanning runs in WP-Cron background tasks. The runtime guard registers one error handler — effectively zero overhead.

= What PHP version is required? =
PHP 8.0 or higher (uses match expressions, named arguments, first-class callables).

= What is a risk level? =
High (3): Functions related to auth, payment, security, or sanitisation.
Medium (2): Data functions — get_, set_, update_, delete_, etc.
Low (1): Utility/helper functions unlikely to cause data loss if missing.

== Changelog ==
= 1.0.1 =
* Updated compatibility information for WordPress 7.1.
= 1.0.0 =
* Initial release.
* Static scanner with PHP tokeniser.
* Runtime error handler + shutdown handler.
* Pre-flight dependency checker.
* og_call(), og_exists(), og_guard() global shims.
* Admin dashboard: Dashboard, Dependency Map, Incident Log, Settings.
* Email alerts with throttling.
* REST API endpoints for live dashboard refresh.
* Deactivation detection: immediate alert when a provider plugin is turned off.
