=== Tóg Widgets ===
Contributors: togstudio
Tags: ai chat, chatbot, loyalty, bookings, reviews
Requires at least: 5.8
Tested up to: 6.7
Requires PHP: 7.2
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Embed your Tóg Studio widgets (AI Chat, Loyalty, Bookings, Reviews, Lead Capture, Boost offers, Contact Desk) on your WordPress site with no code.

== Description ==

**Tóg Widgets** lets you place the widgets you have set up in your Tóg Studio account onto your WordPress site — without touching theme code. You manage your tools, plan and billing in your Tóg account at [app.togs.ie](https://app.togs.ie/); this plugin's only job is to embed the official Tóg widgets here using your own publishable key and site ID.

Switch the widgets on under **Settings → Tóg**, then drop each one exactly where you want it with the **Tóg Widget** block or the `[tog_widget]` shortcode. AI Chat is the exception — it floats in the page corner and loads site-wide automatically when enabled.

= The widgets you can embed =

* **AI Chat** — a friendly, on-brand AI chat assistant that floats in the corner of every page, answers visitor questions, and hands off to your team. *Floating — no placement needed.*
* **Loyalty** — an inline rewards widget: customers join your programme, see their balance and tier, redeem rewards, and share a referral link.
* **Bookings** — an inline booking widget: pick a service, see live availability, and book or cancel.
* **Reviews** — an inline reviews widget: shows your rating and recent reviews and lets customers leave one.
* **Lead Capture** — an inline lead-capture form to grow your list, with custom fields.
* **Boost Offers** — an inline upsell / cross-sell offers widget to surface promotions and deals.
* **Contact Desk** — an inline contact form that feeds your unified Tóg inbox.

Every widget except AI Chat is **inline**: it renders exactly where you place the **Tóg Widget** block or the `[tog_widget plugin="…"]` shortcode. Place the same widget in more than one spot if you like — the loader script is added once and each placement gets its own widget.

This plugin injects the official Tóg embed loader for the widgets you enable. The loader is served from `https://app.togs.ie/embed.js` and renders each widget inside an isolated Shadow DOM, so it never clashes with your theme's styles or scripts.

= How it works =

You need two values from your Tóg account:

1. **Publishable key** — starts with `pk_`. In your Tóg account, open **Developers** (API Keys & Developers) → **New key** → scope **Publishable**, then copy the `pk_live_…` value. It is shown **only once**, at mint time — if you lose it, revoke it and mint a new one. This key is *origin-bound*: it only works from the website origins you have authorised for your site (see below), which is why it is safe to put in your site's public HTML. It is **not** a secret.
2. **Site ID** — the `data-tog-site` value shown on your integration's **Embed** snippet (under **Integrations**) and on **Sites**.

Paste both into **Settings → Tóg**, tick the widgets you want, and save. Then place each inline widget with the block or shortcode; AI Chat appears automatically.

Finally, in your Tóg account, open **Sites → your site → Allowed origins** and add this site's exact origin (scheme + host, e.g. `https://www.yourbrand.com`) so the gateway accepts your publishable key. You can use `*` to allow any origin (only for fully public widgets).

> **Security note:** Only ever paste a *publishable* key (`pk_…`). Never paste a *secret* key (`sk_…`) — a secret key in your page source would be exposed to everyone. This plugin refuses to save anything that is not a publishable key.

= Privacy =

This plugin does not collect or send any data on its own. It only outputs the Tóg embed loader `<script>` tag (plus, for inline widgets, an empty mount element) into your pages. All widget behaviour, data handling, and network requests are performed by the Tóg embed loader and the Tóg gateway, governed by Tóg Studio's terms and privacy policy at https://togs.ie/. Your publishable key and site ID are stored in your WordPress database (the `wp_options` table) and printed into your page HTML by design.

== Installation ==

1. Upload the `tog-plugins` folder to the `/wp-content/plugins/` directory, **or** install it from your WordPress admin via **Plugins → Add New → Upload Plugin**.
2. Activate the plugin through the **Plugins** screen in WordPress.
3. Go to **Settings → Tóg**.
4. Paste your **Publishable key** (`pk_…`) and **Site ID**. Mint/copy the publishable key in your Tóg account under **Developers** (it is shown only once); the Site ID is the `data-tog-site` value on your integration's **Embed** snippet (**Integrations**) and on **Sites**.
5. Tick the widgets you want to enable (AI Chat, Loyalty, Bookings, Reviews, Lead Capture, Boost, Contact Desk).
6. Save changes.
7. For each inline widget, add the **Tóg Widget** block (Widgets category) to a page or post and choose the widget — or use the shortcode, e.g. `[tog_widget plugin="reviews"]`. (AI Chat needs no placement — it floats automatically when enabled.)
8. In your Tóg account, open **Sites → your site → Allowed origins** and add this site's exact origin (scheme + host, e.g. `https://www.yoursite.com`) so the gateway accepts your publishable key. You can use `*` to allow any origin (only for fully public widgets).

== Frequently Asked Questions ==

= Is my publishable key safe to put in my site? =

Yes. Tóg publishable keys (`pk_…`) are origin-bound: the Tóg gateway only accepts a key from the website origins you have explicitly authorised under **Sites → your site → Allowed origins**. That is why publishable keys are designed to live in client-side HTML. Never use a secret key (`sk_…`) here — this plugin will refuse to save one.

= How do I place a widget on a page? =

Add the **Tóg Widget** block (in the Widgets category) and pick the widget from the dropdown, or paste the shortcode `[tog_widget plugin="reviews"]` into any page, post or block that runs shortcodes. Use the widget id you want: `loyalty`, `bookings`, `reviews`, `capture`, `boost` or `desk`. AI Chat (`ai-chat`) is floating and needs no placement.

= Why isn't a widget showing up? =

Check the following:
1. Both the publishable key and site ID are saved under **Settings → Tóg**.
2. The widget is ticked (enabled) under **Settings → Tóg**.
3. For an inline widget, the **Tóg Widget** block or `[tog_widget]` shortcode is on the page you are viewing.
4. This site's origin (e.g. `https://www.yoursite.com`) is added under **Sites → your site → Allowed origins** in your Tóg account.
5. Any page or CDN cache has been cleared after saving.

= Do I need a Tóg account? =

Yes. This plugin embeds the widgets you have subscribed to and configured in your Tóg Studio account. You manage your tools, plan and billing at https://togs.ie/ (sign in at https://app.togs.ie/).

= Can I place the same widget in more than one spot? =

Yes. Add as many blocks/shortcodes for a widget as you like. The loader `<script>` is printed once per page and each placement gets its own widget instance.

= What about the AI Chat widget — where does it go? =

AI Chat is a floating launcher that appears in the page corner on every page once enabled. It does not use a block or shortcode.

= Does this plugin send any data to Tóg by itself? =

No. The plugin only outputs the Tóg embed loader script tag (and, for inline widgets, an empty mount element). All network requests and data handling are performed by the Tóg loader and gateway once a visitor interacts with a widget.

== Screenshots ==

1. The **Settings → Tóg** screen: paste your publishable key and site ID, then switch on the widgets you want.
2. The **Tóg Widget** block in the editor: choose which widget to embed on the page.
3. A live widget (Reviews) rendered inline on the front end inside its isolated Shadow DOM.

== Changelog ==

= 1.0.0 =
* Initial release.
* Settings → Tóg page: publishable key, site ID, and per-widget enable toggles.
* Embeds all seven Tóg storefront widgets: AI Chat (floating, site-wide), Loyalty, Bookings, Reviews, Lead Capture, Boost and Contact Desk (inline).
* "Tóg Widget" Gutenberg block and the universal `[tog_widget plugin="…"]` shortcode place inline widgets anywhere.
* Injects the official Tóg embed loader (https://app.togs.ie/embed.js), de-duplicated per request, with every attribute escaped.

== Upgrade Notice ==

= 1.0.0 =
First release of Tóg Widgets.
