=== TGP 360 ===
Tags: crm, leads, contact form 7, metform, lead capture
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Send this website's form submissions to your TGP 360 Lead Center and add the TGP 360 website chat — without editing theme files.

== Description ==

TGP 360 connects your WordPress website to your TGP 360 workspace.

**Lead capture**

* The plugin's own form — add `[tgp360_form]` to any page or post (name, email, phone, optional company, message and an optional consent box).
* Contact Form 7 — submissions that Contact Form 7 accepts (after its own validation and spam checks) are sent too.
* MetForm — new submissions of the MetForm forms you tick, after MetForm accepted and stored them. MetForm keeps its own entries, e-mails and integrations; entries it stored before are never imported.
* Submissions are sent from your website's server to TGP 360 (never from the visitor's browser), with the source "website" and a form name starting with "WordPress", so they are easy to recognise in the Lead Center.
* Each submission has its own idempotency key: a retry never creates a second lead.
* If TGP 360 cannot be reached, the visitor still sees "sent" and the submission is retried automatically (after 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours), then given up.
* A "Recent deliveries" log on the settings screen shows what happened to the last 50 submissions — without any personal data.

**Website chat**

* Shows your TGP 360 AI agent's chat on every page of the website. You only enter the agent's public ID; no key or password is ever put in your pages.

**Security**

* The workspace API key is stored on your website only, is never shown again after saving (only "tgp_…" and its last 4 characters), and is never sent to visitors' browsers. For extra safety you can define it in wp-config.php instead.
* Only administrators can see or change the settings.

== Installation ==

You need a TGP 360 workspace (https://www.tgp360.com) whose plan includes the Developer API and the Lead Center, and its Owner to create the API key.

1. Install the plugin:
   * from WordPress: **Plugins → Add New Plugin**, search for **TGP 360**, click **Install Now** (once the plugin is listed in the WordPress.org directory); or
   * from a ZIP: download it in TGP 360 (**Integrations → Available → WordPress**, or **Workspace Settings → Developer**), then in WordPress go to **Plugins → Add New Plugin → Upload Plugin**, choose the ZIP and click **Install Now**.
2. Click **Activate**.
3. In TGP 360, open **Workspace Settings → Developer**.
4. Create an API key with only the **leads:write** permission. Copy it — it is shown once.
5. In WordPress, go to **Settings → TGP 360**, paste the API key and save. The key is never part of the plugin's files: it is stored on your website only. For extra safety you can define it in wp-config.php instead: `define( 'TGP360_API_KEY', 'tgp_…' );`
6. Click **Test connection**: the status should become **Connected**. Set the **Default country** (for example JO) if visitors may type phone numbers without the +country code.
7. Turn on the form sources: add `[tgp360_form]` to a page, and/or turn on **Contact Form 7**, and/or turn on **MetForm** and tick the MetForm forms to send (none is ticked until you do).
8. Submit one form on your website and check that the lead appears in TGP 360's **Lead Center** (and in **Settings → TGP 360 → Recent deliveries**).

Website chat (optional): if the TGP 360 chat is already on your website (added another way), leave **Show the TGP 360 chat** off — turning it on as well shows two chats. Otherwise, in TGP 360 → AI Agents → your agent → Widget settings, make sure the agent is active and its widget enabled, add your website's hostname to **Allowed domains** (or leave the list empty), copy the agent ID (`wa_…`) into **Agent ID** and turn the chat on.

Updating: a newer version replaces the plugin's files only. Your settings, the API key, the delivery log and the retry queue stay as they are — also when you move from a ZIP you installed by hand to updates from WordPress.org (the plugin folder, `tgp-360`, is the same).

== Frequently Asked Questions ==

= Does Test connection create a lead? =

No. It only asks TGP 360 which workspace the key belongs to and what it may do. Because no lead is created, it cannot confirm that the Lead Center is turned on for the workspace — the first real submission does (see "Recent deliveries").

= What happens if TGP 360 is down? =

The visitor's form works as usual. The submission waits in a small queue on your website and is retried with the same idempotency key, so it is never recorded twice. After the last retry (about 21 hours) it is given up and deleted.

= Is the consent box a marketing opt-in? =

No. When the box is ticked, "Consent: Yes", the box's text and the time are sent as one of the form's answers. TGP 360 does not record it as marketing consent. You can choose to send a submission only when the box is ticked.

= Which Contact Form 7 fields are used? =

Name, email, phone, company and country are found by field name (configurable; the defaults match Contact Form 7's own `your-name`, `your-email`, …). Every other field of the form becomes an answer, except files, captcha and quiz fields and the consent field.

= Which MetForm fields are used? =

Name, email, phone, company and country are found by the field names above first, then by MetForm's own field types (email, telephone, first / last name) and by field labels such as Name, Phone, Company or Country (also in Arabic, e.g. الاسم, رقم الجوال). Every other field becomes an answer under its label (choices as the option text the visitor saw). Files, passwords, signatures, payment and card fields, captcha and hidden fields are never sent — also when they have custom names. If MetForm's field list for a form can't be read, nothing is sent and "Recent deliveries" says so.

= Will my existing MetForm entries be imported? =

No. Only new submissions of the ticked forms are sent, from the moment you turn MetForm on. MetForm's stored entries are never read.

= Is MetForm's newsletter opt-in a marketing opt-in in TGP 360? =

No. It is recorded as its own "Newsletter opt-in" answer (Yes / No), separate from the consent answer, and never counts as consent. TGP 360 never sets marketing consent from a lead.

= I already added the TGP 360 chat to my site another way =

Leave **Show the TGP 360 chat** off (it is off by default); turning it on as well shows two chat widgets.

= The chat does not appear =

Check in TGP 360 that the agent is active, its widget is enabled, and your website's hostname is in the widget's Allowed domains (or the list is empty). Page-optimisation plugins that combine or delay scripts can also stop it: exclude `widget/v1.js` from them.

= I installed the plugin from a ZIP. Will I get updates from WordPress.org? =

Yes, once the plugin is listed there: WordPress matches plugins by their folder and main file (`tgp-360/tgp-360.php`), so a copy installed from a TGP 360 ZIP is updated from WordPress.org like any other plugin. Updating keeps your settings and API key. Don't delete the plugin to update it — deleting removes its settings (see below).

= What is removed when I delete the plugin? =

Only what the plugin stored on this website: its settings, the API key, its log, its retry queue and its scheduled task. Nothing is ever deleted in TGP 360: leads and contacts already there are not affected. Deactivating the plugin keeps the settings.

== External services ==

This plugin connects your website to **TGP 360**, a customer-communication and lead-management service run by The Growth Pillars (https://www.tgp360.com). It does nothing until an administrator enters a TGP 360 API key in **Settings → TGP 360**, and it only uses the TGP 360 address shown there (normally https://www.tgp360.com).

* **Lead submission** — when a visitor submits a form the administrator turned on (the plugin's `[tgp360_form]`, a Contact Form 7 form or a ticked MetForm form), the website's server sends the submission to `POST <TGP 360 address>/api/v1/leads`: the details the visitor typed (name, email, phone, company, country, message and the form's other answers — never files, passwords, payment, captcha or hidden fields), the form's name, the page address, the referring page, campaign parameters (utm_source, utm_medium, utm_campaign, utm_term, utm_content) and, when the consent box is used, its text and the time. The API key is sent in the request's Authorization header. Failed sends are retried for about a day.
* **Test connection** — when the administrator clicks **Test connection**, the website's server calls `GET <TGP 360 address>/api/v1/me` with the API key, to learn which workspace the key belongs to. No visitor data is sent.
* **Website chat** — only when the administrator turns **Show the TGP 360 chat** on: every page loads the chat script from `<TGP 360 address>/widget/v1.js` in the visitor's browser, which then talks to TGP 360 to show the AI agent's chat. The chat keeps an anonymous session identifier in the visitor's browser, and what the visitor writes in the chat is sent to TGP 360.

TGP 360 terms: https://www.tgp360.com/terms — privacy policy: https://www.tgp360.com/privacy-policy

== Privacy ==

Form submissions (the details the visitor typed, the page address and campaign parameters) are sent to TGP 360. A submission waits on this website only while it is being retried (about one day at most). The plugin adds suggested text to Settings → Privacy → Policy Guide. The website chat is provided by TGP 360 and keeps an anonymous session identifier in the visitor's browser.

== Upgrade Notice ==

= 1.1.2 =
Translation loading follows WordPress.org: language packs from translate.wordpress.org are used first, and the bundled Arabic only when none is installed. The Arabic translation works again on WordPress 6.0 to 6.4. Settings and the API key are kept.

= 1.1.1 =
Prepares the plugin for the WordPress.org directory (external services disclosure, installation and update notes). Nothing changes in how it works; settings and the API key are kept.

== Changelog ==

= 1.1.2 =
* Translations: the plugin no longer calls `load_plugin_textdomain()`. WordPress loads its translations itself, and language packs from translate.wordpress.org take priority; the Arabic translation shipped with the plugin is used only when no language pack is installed for the site's language.
* Translations: the bundled Arabic loads again on WordPress 6.0 to 6.4. Since 1.1.0 its compiled file had a header those versions reject, so they showed English; WordPress 6.5 and later were not affected. The translations themselves are unchanged.
* MetForm: a redundant query argument flagged by Plugin Check was removed from the list of forms on the settings page. The same forms are listed.

= 1.1.1 =
* WordPress.org packaging: an "External services" section describing exactly what is sent to TGP 360 and when, with links to TGP 360's terms and privacy policy; installation from the plugin directory or a TGP 360 ZIP; how updates keep settings and the API key. No change to how the plugin works.


= 1.1.0 =
* MetForm: new submissions of the forms you tick are sent to the TGP 360 Lead Center (MetForm's `metform_after_store_form_data` hook), with answers under their labels, consent and the newsletter opt-in kept apart, the same retries and duplicate protection. Off by default; no historical import. English and Arabic.

= 1.0.0 =
* First release: TGP 360 form, Contact Form 7, retry queue, recent-deliveries log, website chat, English and Arabic.
