=== Saral PDF Preview for WooCommerce ===
Contributors: akaalcreatives
Tags: woocommerce, pdf, preview, lightbox, product
Requires at least: 6.5
Tested up to: 6.9
Requires PHP: 8.1
Requires Plugins: woocommerce
Stable tag: 1.2.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Add a PDF preview button to WooCommerce product pages. Customers can view a PDF sample in a lightbox without downloading.

== Description ==

Saral PDF Preview lets you attach a PDF file to any WooCommerce product. A configurable button appears on the product page and opens the PDF in a clean, distraction-free lightbox — no download, no print, just a smooth in-browser reading experience powered by PDF.js.

**Features**

* Upload a PDF per product via a dedicated meta box in the product editor.
* Configurable button text (default: "Preview Book").
* Choose from 7 hook locations on the product page — a live visual diagram shows exactly where the button will appear.
* **Protected mode** (default): the real PDF URL is never exposed to visitors; the file is streamed through a signed REST endpoint.
* **Public mode**: uses the standard WordPress attachment URL.
* Zoom in / zoom out controls inside the lightbox.
* Keyboard accessible — press Escape to close.
* Responsive layout on mobile.
* No tracking, no external requests, no upsells.

== Installation ==

1. Upload the `saral-pdf-preview-for-woocommerce` folder to `/wp-content/plugins/`.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. Go to **WooCommerce → PDF Preview** to configure the button text, position, and serving mode.
4. Edit any product, find the **PDF Preview** meta box, and upload a PDF.

== Frequently Asked Questions ==

= Does this work with any WooCommerce theme? =

Yes. The button is injected via standard WooCommerce action hooks so it works with any theme that respects the WooCommerce template hierarchy.

= Can customers download the PDF? =

No. The lightbox intentionally has no download or print controls. In Protected mode the real file URL is never sent to the browser, so determined users cannot easily retrieve it either.

= Is a login required to view the preview? =

No. All visitors (logged-in or not) can open the lightbox.

= How large can the PDF be? =

There is no hard limit imposed by this plugin. Your server's `max_execution_time` and `memory_limit` settings apply as usual. For very large PDFs, consider splitting them into a shorter sample.

= Which PDF.js version is bundled? =

PDF.js 5.7.284.

== Screenshots ==

1. Admin settings page — configure button text, hook position, and file serving mode.
2. The "Preview Book" button on a WooCommerce product page.
3. The PDF lightbox open on a product page — zoom controls, keyboard accessible, no download option.

== Changelog ==

= 1.2.0 =
* Upgraded PDF.js from 3.11.174 to 5.7.284.
* PDF.js now loads lazily on first lightbox open via dynamic import — reduces initial page weight.
* Hardened output escaping: button HTML is now passed through wp_kses() with an explicit allowlist; admin meta box attribute conditionals rewritten to eliminate unescaped echo calls.

= 1.1.0 =
* Added data-pdf-preview-trigger attribute as the lightbox trigger — any custom element can now open the lightbox without relying on the plugin's CSS class.
* Added saral_pdf_preview_for_woocommerce_trigger_attr() helper function for use in theme templates and custom markup.
* Added saral_pdf_preview_for_woocommerce_trigger_attr filter to override the trigger attribute string.
* Settings page now documents the custom trigger element feature with usage examples.

= 1.0.6 =
* Added shortcode [saral_pdf_preview_for_woocommerce] — place the preview button in any custom location on a product page without touching theme files. Accepts an optional id attribute to target a specific product from any page.
* Added PHP template tag support: echo do_shortcode( '[saral_pdf_preview_for_woocommerce]' ) for use directly in theme templates.
* Settings page now includes a Manual Embedding section with copy-ready shortcode and PHP snippets.

= 1.0.5 =
* Added "Data on Uninstall" setting — choose whether to keep or remove PDF assignments from products when the plugin is deleted. Defaults to keeping the data so assignments are restored on reinstall.

= 1.0.4 =
* Security: protected endpoint now verifies the product exists and is published before streaming the PDF.
* Security: Content-Disposition filename is now sanitised before being sent in the response header.
* Fixed: REST endpoint returns a proper error response instead of calling wp_die().
* Fixed: loading spinner now hides correctly if a network error occurs during PDF load.
* Fixed: uploading a non-PDF attachment no longer leaves stale metadata on the product.
* Fixed: preview button is now guarded against malformed button hook settings.
* Fixed: PDF attachment MIME type is verified in public serving mode before use.
* Improved: admin media frame strings (Select PDF, Use this PDF) are now translatable.
* Improved: modal dialog now uses aria-labelledby for better screen reader support.

= 1.0.3 =
* Added loading spinner shown while PDF is downloading and rendering.

= 1.0.2 =
* Bumped asset version to bust browser cache after identifier rename.

= 1.0.1 =
* Renamed all internal identifiers to match plugin slug.
* Fixed 403 on protected PDF endpoint for logged-in users.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.2.0 =
Security and compatibility improvement — upgrade recommended. PDF.js updated to 5.7.284; output escaping hardened throughout.

= 1.1.0 =
No action required. The default button continues to work as before — the custom trigger is an opt-in feature for developers.

= 1.0.6 =
No action required. Existing automatic button placement is unchanged — the shortcode is an opt-in addition.

= 1.0.5 =
No action required. PDF assignments are kept by default on uninstall.

= 1.0.4 =
Security and stability improvements — upgrade recommended for all users.

= 1.0.0 =
Initial release — no upgrade steps required.
