=== Civilized Embed ===
Contributors: civilizedai
Tags: chat, search, ai, widget, embed
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 0.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Add the Civilized chat widget, search bar, search page, and Contact Us link. No code to paste — set it up in Settings > Civilized.

== Description ==

Civilized helps your visitors find answers and get in touch. This plugin adds four embeddable surfaces to your WordPress site:

* **Search bar** — a search box visitors type a question into. Available as the "Civilized Search Bar" block, the `[civilized_search]` shortcode, or the `civilized_search()` template tag. Size is adjustable per instance with a live preview in the editor.
* **Chat widget** — a floating chat button enabled site-wide with one toggle. Pick which corner it sits in and how far from the edges.
* **Search page** — a full inline chat on one dedicated page of your site (for example yoursite.com/chat). Visitors get a complete conversation without leaving your domain. Available as the "Civilized Search Page" block, the `[civilized_search_page]` shortcode, or the `civilized_search_page()` template tag.
* **Contact Us link** — opens the Civilized contact form. Available as the "Civilized Contact Us Link" block, the `[civilized_contact_us]` shortcode, or the `civilized_contact_us()` template tag.

Your organization's colors, dark mode, logo, and FAQ questions stay in your Civilized Admin Dashboard. Everything that lives in the embed code itself — search bar size and shape, chat widget position — is set in WordPress, and this plugin replaces the dashboard's install snippets for your site.

The plugin uses domain-based authentication. There is no API key to configure — you just need to add your site domain to your organization's allowed-domains list in the Civilized Admin Dashboard.

This plugin is built for organizations that are existing Civilized customers. It only functions on sites whose domains have been explicitly allowlisted by the partner organization on Civilized's backend; it does nothing on any other site.

== Installation ==

1. Upload the `civilized-embed` folder to `/wp-content/plugins/`, or install via Plugins → Add New → Upload Plugin.
2. Activate the plugin through the **Plugins** menu.
3. Go to **Settings → Civilized** and click **Check connection** to verify that your site domain is on your organization's allowed-domains list.
4. Toggle the chat widget on, and add whichever of the other three embeds you want — each section on the settings page has the block, shortcode, and template-tag options.

== Privacy & external services ==

This plugin communicates with a single external service: **api.civilized.ai**, operated by Civilized AI.

**When the plugin contacts api.civilized.ai:**
Only when you click the **Check connection** button on the **Settings → Civilized** page. The plugin makes no automatic, scheduled, or page-load HTTP calls to any external service.

**What is sent:**
The HTTP `Origin` header containing your site's scheme and host (e.g., `https://example.com`). No other data, content, or user information leaves your site through this plugin.

**What is returned:**
A small JSON response indicating whether your domain is on your organization's allowed-domains list, plus your organization name, hosted-chat URL, and — if you have set one up — your Search page URL (only if allowlisted). These values are stored locally in WordPress as part of the plugin's settings option (`civilized_embed_settings`) and are used to display status on the settings page and to generate the optional Contact Us link.

**Loader scripts on the front-end:**
When the chat widget, search bar, or search page is rendered on a page of your site, the corresponding loader script is fetched from `chat.civilized.ai/sdk/...` by the visitor's browser. This is the same pattern as embedding any third-party widget (Stripe, Intercom, etc.) and only happens on pages where you've explicitly placed the widget or enabled the chat toggle.

**Civilized's policies:**

* Privacy policy: https://civilized.ai/privacy
* Terms of service: https://civilized.ai/terms

== Why the loader uses @latest ==

The widget loader scripts are referenced from a Civilized-controlled domain (`chat.civilized.ai`) at the unversioned `@latest` URL:

`https://chat.civilized.ai/sdk/civilized-ai@latest/loader.js`

We use `@latest` rather than a pinned version for the following reasons:

1. **Closed-customer plugin, not a public widget.** This plugin is a runtime for a managed product. It only functions for organizations whose domains we have explicitly allowlisted. It is not, and is not intended to be, a general-purpose widget that arbitrary sites can use.

2. **Civilized-controlled infrastructure.** The loader is served from `chat.civilized.ai`, which is owned and operated by Civilized AI — not a third-party CDN. We do not load executable code from any uncontrolled source.

3. **Server-coupled releases.** The loader is updated in lock-step with the Civilized backend it talks to (`api.civilized.ai`). Pinning a loader version inside this plugin would force a plugin re-release every time we ship a routine server-side change, and would break partners during the lag.

4. **No data exfiltration surface.** The plugin itself never transmits page content, user data, or credentials. All runtime traffic goes through partner-domain-authenticated requests to Civilized's own backend.

Customers who require strict version control on the loader can self-host the loader files; contact support@civilized.ai for guidance.

== Frequently Asked Questions ==

= What happens to my embeds if I delete the plugin? =

They stop appearing, and how cleanly depends on how you added them.

**Blocks** are clean. The block stays in the post but renders nothing, and the editor shows the usual "this block is not supported" placeholder. Reinstall the plugin and every block comes back exactly as it was.

**Shortcodes** are not. WordPress prints an unregistered shortcode as plain text, so visitors would see `[civilized_search]` on the page. Remove them before deleting the plugin.

**PHP template tags** will break the page unless you used the `function_exists` check shown on the settings screen. Without it, calling `civilized_search()` after the plugin is gone is a fatal error.

Deleting (rather than deactivating) also clears this plugin's own settings, so you would press **Check connection** again and re-set the chat widget position after reinstalling. Nothing is lost on the Civilized side: your colors, FAQ questions, and registered Search page all live in your Civilized Admin Dashboard.

= Will updating the plugin break embeds I already added? =

No. Blocks store only their own settings, and anything a newer version no longer uses is ignored rather than left behind. Shortcodes behave the same way — an attribute that no longer applies is skipped, not printed.

= Where do I add my domain? =

Your organization's primary website domain is allowlisted automatically when you become a Civilized customer. If you want to add additional domains (e.g., a staging or marketing site), reach out to Civilized — only Civilized staff and your designated org admins can modify the allowed-domains list.

= Will the plugin survive a theme switch? =

Yes — the plugin is theme-independent. The chat widget hooks into `wp_footer`, which exists on every theme. The search bar, search page, and Contact Us link are all available as blocks, shortcodes, and template tags, so they work on block themes and classic themes alike.

= Does the chat widget show up in feeds or REST API responses? =

No. The plugin explicitly suppresses widget output in RSS/Atom feeds, REST API responses, AJAX requests, and XML-RPC payloads to avoid corrupting those formats with script tags.

= Can I move the chat bubble to a different corner of the page? =

Yes. On the **Settings → Civilized** page, the *Chat widget position* section lets you pick which corner the floating bubble sits in (Bottom right, Bottom left, Top right, or Top left) and how far from the horizontal and vertical edges. A live preview updates as you drag the sliders.

= Can I customize the search bar size and colors? =

Size, yes — each **Civilized Search Bar** block has its own sliders in the editor sidebar with a live preview, so you can have a wide bar on the homepage and a compact one in the footer. Text size follows height automatically to keep the bar balanced.

No. Every colour — search field, placeholder, input text, outline, submit button and its hover, in both light and dark — comes from your Civilized Admin Dashboard and reaches every bar on your site as soon as you save it there. The blocks set size and shape only.

For the shortcode and template tag, pass optional overrides:

* Shortcode: `[civilized_search max_width="640" height="64" text_size="20" radius="16"]`
* Template tag: `<?php civilized_search( array( 'maxWidth' => 640, 'height' => 64 ) ); ?>`

Any unset value falls back to the default (max width 745px, height 55px, text 18px, radius 12px). Because the bar uses `max-width`, it also shrinks to fit narrower containers.

= What is the Search page, and do I need one? =

The Search page is a full inline chat on one dedicated page of your site. It is optional, but worth adding: once you have one, the search bar sends questions there instead of opening a separate window, and the Contact Us link becomes a plain link with no JavaScript to load.

Add the **Civilized Search Page** block (or `[civilized_search_page]`) to a single page and publish it. The page registers itself the first time a visitor loads it. Then press **Check connection** on the settings page so WordPress notices.

Only add it to one page — that page becomes your Search page.

= How does the Contact Us link decide where to open? =

Automatically, based on whether you have a Search page:

* **With a Search page** — a plain link straight to that page. No JavaScript, nothing extra to load.
* **Without one** — the link hands the request to the chat widget already on the page, so the contact form opens right there.

The block, shortcode, and template tag all pick the correct version for you and keep working if you add a Search page later. The settings page also shows the raw snippet if you would rather paste it somewhere the plugin cannot reach, such as a theme menu.

Contact Us only works once your organization has set a **Forwarding Email Address** in the Civilized Admin Dashboard.

= Where do I change colors, dark mode, or my logo? =

In your Civilized Admin Dashboard, under Settings. Those are organization-level settings shared by every surface — your website embeds, your hosted chat page, and your search page all read from the same palette. That is why the plugin does not duplicate them: changing them in one place updates everything.

== Source code and build instructions ==

The plugin's Gutenberg block ships both its compiled output (in `blocks/search/build/`) and the original, human-readable source (in `blocks/search/src/`). The `package.json` file in the plugin root lists the build toolchain.

To rebuild from source:

1. Install Node.js 16 or later.
2. From the plugin root, run `npm install` followed by `npm run build`.

The build uses the standard `@wordpress/scripts` toolchain. No other JavaScript or CSS in the plugin is compressed or minified.

== Changelog ==

= 0.3.0 =

* Search bar colors are no longer set in WordPress. Every color — search field, placeholder, input text, outline, submit button and its hover, in both light and dark — comes from your Civilized Admin Dashboard and reaches every embed as soon as you save it there.
* Blocks now set size and shape only. Colors a block saved earlier are ignored.
* Added a settings dropdown to the search bar and Contact Us blocks' toolbars, so their controls stay reachable when the editor's settings sidebar is closed.
* Contact Us block now stores which version it uses only when you pick one, and only offers a destination your site can actually reach.
* Chat widget offsets now match the dashboard's range (0–64).
* Renamed the verification button to **Check connection**, and made the guidance depend on whether your site has been checked and whether a Search page exists.
* Corrected the settings page: your organization's colors, dark mode, logo, and FAQ questions live in the dashboard; size, shape, and position live here.

= 0.2.0 =

* Added the **Search page** embed — a full inline chat for one dedicated page, as a block, shortcode, and template tag.
* Added the **Contact Us link** as a block, shortcode, and template tag. Picks between the Search page link and the chat-widget hand-off automatically.
* Search bar inherits colors and dark mode from the Civilized Admin Dashboard.
* Search bar text size now follows height proportionally, matching the dashboard.
* Settings page reorganized into the same four sections as the Civilized Admin Dashboard: Search bar, Chat widget, Search page, Contact Us.
* Search bar appearance is now passed on the loader URL, matching the dashboard's snippet exactly.


= 0.1.0 =

* Initial release.
* Chat widget (site-wide toggle, floating bubble) with configurable position (Bottom right / Bottom left / Top right / Top left) plus horizontal and vertical offset sliders, all on the Settings page with a live preview.
* Search bar Gutenberg block with per-instance size/color sliders, a live preview inside the block canvas, plus `[civilized_search]` shortcode and `civilized_search()` template tag (both accept optional appearance overrides).
* Theme-aware settings-page guidance (block theme vs. classic theme).
* Domain status check via `api.civilized.ai/public/embed/config`, button-gated and result-cached locally.
* Contact Us link surfaced as a copy-paste HTML snippet.
* Renderable-context guard prevents script leakage into feeds, REST, AJAX, and XML-RPC.
