=== Media Guard ===
Contributors: paulsperfectpc
Tags: pdf viewer, media protection, content protection, woocommerce, role-based access
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Protect PDFs, eBooks, video, audio, and documents in WordPress — with role-based access, print/download blocking, watermarks, and WooCommerce gating. 30+ file types, one plugin, no monthly fees.

== Description ==

Media Guard lets you serve protected media files only to authorized users based on their WordPress role. Files are streamed through PHP so they never get a direct URL, and the built-in PDF.js viewer strips print, download, and open-file buttons from the toolbar.

= Key Features =

* **Role-Based Access** — Gate files by any WordPress role (subscriber, student, customer, or custom roles).
* **Hardened PDF Viewer** — Embedded PDF.js viewer with print/download blocking, right-click protection, and keyboard shortcut interception.
* **Secure Streaming** — Files served via PHP with path traversal prevention, nonce validation, and security headers (no-cache, no-store, nosniff).
* **WooCommerce Integration** — Attach protected PDFs and PPTX files to product variations. Customers see their content library after purchase with automatic payment gating.
* **Watermarks (Pro)** — Overlay semi-transparent watermarks with dynamic tags: `{email}`, `{username}`, `{date}`.
* **File Manager** — Upload, list, and delete protected files from the admin dashboard with drag-and-drop support.
* **Multiple File Types** — Supports PDF, EPUB, PPTX, DOCX, XLSX, MP4, MP3, and 30+ more formats.
* **EPUB Reader** — Built-in epub.js viewer for eBooks with navigation and watermark support.
* **Access Groups** — Create custom groups and assign users and files for fine-grained access control.
* **Access Logs (Pro)** — Track who viewed, downloaded, or was denied access to each file.
* **NGINX Ready** — X-Accel-Redirect support for high-performance streaming. Settings page displays copy-paste NGINX config.
* **Auto-Updates** — Licensed sites receive automatic plugin updates from wpmediaguard.com.
* **Translation Ready** — Full i18n support with `.pot` file included.

= How It Works =

1. Upload files to the protected directory via the File Manager or SFTP.
2. Use the `[mediaguard]` shortcode to embed a viewer or download link on any page.
3. Only logged-in users with the specified role or group can access the file.
4. PDFs open in a hardened viewer; EPUBs open in the built-in reader; other file types stream as downloads.

= Shortcodes =

**Single file:**
`[mediaguard path="lesson-1.pdf" roles="student" embed="true" height="800px"]`

**With group access:**
`[mediaguard path="manual.pdf" groups="1,3"]`

**Content library (Pro, requires WooCommerce):**
`[mediaguard_library]`

= Free vs Pro =

* **Free** — 2 protected files, 10 MB max file size, role gating, PDF viewer, print/download blocking, WooCommerce integration.
* **Pro** ($79/yr, 1 site) — Unlimited files, unlimited file size, extended file types (EPUB, DOCX, PPTX, video, audio, images), watermarks, access logs, NGINX X-Accel, content library shortcode.
* **Agency** ($199/yr, up to 10 sites) — Everything in Pro, dynamic watermarks, REST API, white label, priority support.

== Installation ==

1. Download `media-guard.zip` from [wpmediaguard.com](https://wpmediaguard.com/getting-started/).
2. In WordPress, go to **Plugins → Add New → Upload Plugin** and upload the zip.
3. Click **Activate Plugin**.
4. Go to **Settings → Media Guard** and enter your license key (Pro/Agency).
5. Upload files via **Media Guard → File Manager**.
6. Add `[mediaguard path="yourfile.pdf" roles="subscriber"]` to any page or post.

= NGINX Users =

Add the deny rule shown on the Settings page to block direct access to the protected directory. For high-performance streaming, enable X-Accel-Redirect in Settings → Advanced and add the provided NGINX location block.

= WooCommerce Setup =

1. Ensure WooCommerce is active — the integration loads automatically.
2. Edit a variable product and expand a variation.
3. Fill in the **Protected PDF Path**, **Required Role**, and optional PPTX/Printable paths.
4. Place `[mediaguard_library]` on a page to show customers their purchased content.

== Frequently Asked Questions ==

= Does this work without WooCommerce? =

Yes. The core plugin — role-gated streaming, PDF viewer, shortcodes, file manager, and access groups — works without WooCommerce. The WooCommerce module only loads when WooCommerce is active.

= Can users still screenshot or screen-record? =

No browser plugin can prevent screenshots or screen recording. Media Guard blocks the most common vectors: direct downloads, print dialogs, keyboard shortcuts, and right-click saving. Watermarks (Pro) add a visible deterrent.

= What happens if my license expires? =

Pro features (watermarks, extended file types, access logs, content library) stop working. Your files remain protected and the PDF viewer continues to function under free-tier limits.

= What file types are supported? =

Free tier supports PDF. Pro and Agency unlock EPUB, DOCX, PPTX, XLSX, ODT, RTF, MP4, WebM, MP3, WAV, FLAC, JPG, PNG, GIF, WebP, SVG, and more. Documents and presentations are converted to PDF for viewing via LibreOffice (server-side).

= Does it support multisite? =

Not yet. Multisite support is planned for a future release.

= Which PHP versions are supported? =

PHP 7.4 and above. PHP 8.x is fully supported.

== Screenshots ==

1. Settings page with viewer options, directory config, and NGINX snippet.
2. File Manager with drag-and-drop upload and file listing.
3. Hardened PDF.js viewer with blocked toolbar buttons.
4. WooCommerce variation meta fields for protected content.
5. Content library shortcode output for customers.
6. Access groups management page.
7. Access log dashboard with stats and filters.

== Changelog ==

= 1.0.0 =
* Initial release.
* Role-based media streaming with nonce validation.
* Hardened PDF.js viewer with print/download blocking.
* EPUB reader with epub.js.
* Extended file type support (30+ formats) with LibreOffice conversion.
* Custom access groups with user and file assignments.
* Access logging with admin dashboard (Pro).
* WooCommerce product variation integration (HPOS compatible).
* Admin settings page with WP Settings API.
* File Manager with drag-and-drop upload and bulk operations.
* License system with free/pro/agency tiers.
* Automatic update system for licensed installations.
* Watermark support with dynamic tags (Pro).
* NGINX X-Accel-Redirect support (Pro).
* Content library shortcode (Pro).
* Full i18n support with .pot file.
* Uninstall cleanup of all options, transients, and custom tables.

== Upgrade Notice ==

= 1.0.0 =
Initial release.
