=== Plairsoft Integration ===
Contributors: plairsoft
Tags: airsoft, calendar, events, booking, sports
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 1.7.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Show your airsoft field's games from Plairsoft on your own website and let players sign up and pay without leaving it.

== Description ==

Plairsoft Integration connects an airsoft field's WordPress site with [Plairsoft](https://plairsoft.com), the platform where fields publish their games and players sign up for them.

Once connected, your site shows:

* **A game calendar** (grid, list or month view) with the field's upcoming games, prices and free spots.
* **A page for each game** with its date, schedule, rules, itinerary, power limits, roles and free spots, teams, players, photo gallery, attached files, video, location, sign-up and leave deadlines, rules for minors and a sign-up button. Each game gets its own URL (`/partida/{name}-{id}/`), title, meta description, canonical link, Open Graph and Twitter tags and structured data (SportsEvent); finished or cancelled games are set to `noindex`, and upcoming games are added to the sitemap. If the site uses an SEO plugin, the game's tags go through it instead of being printed twice.
* **Sign-up and payment from your site.** Players log in with their Plairsoft account (or create one, also with Google) in a pop-up window, pick team, role and extras, fill in the insurance form if the field requires it, and pay by card or choose cash. With card, payment happens on Stripe before the sign-up is completed. The price shown is the one Plairsoft charges with each payment method (the early-payment offer only applies paying online in advance).
* **Waiting list.** When a game is full, players can join its waiting list for free. When a spot frees up it goes to the first in line: those who pay at the field get in directly, and those who pay online get the spot held for a while to pay it. The game page shows their position, the held spot with its countdown, and lets them pay, confirm or leave the list.
* **Field closures.** If the field closes temporarily or for good, the calendar says so, with the reopening date.
* **A user menu** for the player: the plugin adds a log-in button to the site's navigation menu (themes that use `wp_nav_menu()`), and once logged in, the player's name with "Mis partidas" (their upcoming games and waiting lists at this field) and log out. The `[plairsoft_user_menu]` shortcode shows the same menu anywhere else, for example in a block theme's header.
* **Your field's look.** Out of the box it uses the Plairsoft colours on a light background and your theme's font. In Plairsoft → Apariencia you choose the main, secondary, background and text colours, corner radius, fonts, content width and how the calendar looks (cards, list or month, with an optional side panel about the field); the calendar, game page, booking window and user menu all follow them.
* **A leads register** (Plairsoft → Leads) for your site's own forms. The plugin does not replace your form plugin: your theme or form code saves each submission by calling `Plairsoft_Leads::record()` (and can print the consent checkbox with `Plairsoft_Leads::plairsoft_consent_field()`). The plugin stores them in WordPress with the consent given and its exact text, lists and counts them, exports them as CSV, and supports WordPress' personal data export and erase tools.

The plugin is for fields that already have a Plairsoft account. The field manager creates the API key in Plairsoft Manager, and the Plairsoft team registers the site's login client. See Installation.

The plugin is in Spanish and European Portuguese (pt_PT, also used for other Portuguese locales without their own translation): it follows the site language. On sites in any other language it is shown in Spanish. Currency, time zone and the ID document asked for the insurance follow the country of the field (Spain, Portugal, Colombia…), not the language.

= Shortcodes =

* `[plairsoft_calendar]` — upcoming games of the field.
* `[plairsoft_game_detail]` — page of a single game, with sign-up.
* `[plairsoft_user_menu]` — log-in button or player menu, for the header.

When it is activated, the plugin creates a "Calendario de partidas" page with `[plairsoft_calendar]` and a "Partida" page with `[plairsoft_game_detail]` (or reuses the ones a previous installation left, since uninstalling keeps them). If they are deleted, the "Crear páginas automáticamente" button in Plairsoft → Configuración creates them again.

= Caching =

Pages seen by a logged-in player include their name, so they are sent with no-cache headers, and the session cookie is registered with LiteSpeed Cache and WP Rocket. With other page caches (Cloudflare "Cache Everything", Varnish…), bypass the cache for the `plairsoft_uid` cookie.

== External services ==

This plugin is a client for the Plairsoft platform. It does not work without it.

**Plairsoft API** (`https://app.plairsoft.com`), operated by Plairsoft.

* **What it is used for:** reading the field, its games and the page of each game; logging players in; signing them up for games, leaving games, and starting card payments.
* **What is sent and when:**
  * When a visitor opens the calendar or a game page, your site sends the field's API key and the requested game or field ID. Responses are cached.
  * When a player logs in, the browser goes to Plairsoft's login page, and your site exchanges the login code for a token.
  * When a player signs up, or joins the waiting list of a full game, your site sends, with that player's token, the chosen payment type, team, role and extras. If the field requires insurance, it also sends their ID document number, address, birth date and signature.
  * When a logged-in player opens a game page or their games menu, your site asks Plairsoft, with that player's token, whether they are signed up and their place in the game's waiting list, and the price of their held spot if they have one. These answers are not cached.
  * When a player logs in to sign up for a game of a field that requires insurance, your site asks Plairsoft for permission to read their ID document number, address and birth date, to fill in the insurance form. The player sees this on Plairsoft's consent screen. Other logins only get the player's name, username, email and avatar.
  * The administrator's "Check login" button and Site Health test send the site's client ID and callback URL.
  * Each request to the Plairsoft API includes the plugin version, so Plairsoft can keep the API compatible with the sites that use it, and the site language (Accept-Language), so the API answers in it.
  * **Only if the administrator turns it on** (Plairsoft → Configuración → "Enviar a Plairsoft el estado técnico de esta web", off by default): with every request to the Plairsoft API, and once a day through WP-Cron, your site also sends technical information about itself so the Plairsoft team can see which sites need an update or are failing: the site URL, the WordPress and PHP versions, whether automatic updates are on for this plugin, the site language, the active theme and which plugin templates it overrides, the page cache plugin detected, whether the login client is configured, and the last error the plugin had talking to Plairsoft. Nothing about visitors or players is included. Unchecking the box stops it, including the daily request.
* **Terms and privacy:**
  * Terms of use: https://plairsoft.com/terminos-y-condiciones
  * Privacy policy: https://plairsoft.com/politica-de-privacidad

**Stripe** (`https://checkout.stripe.com`), operated by Stripe, Inc.

* **What it is used for:** paying by card.
* **What is sent and when:** when a player chooses to pay by card, Plairsoft creates a Stripe Checkout session and the player's browser is redirected to Stripe's page. Card data is entered on Stripe, never on your site. Afterwards Stripe sends the player back to the same game page.
* **Terms and privacy:**
  * Terms: https://stripe.com/legal/ssa
  * Privacy policy: https://stripe.com/privacy

**Video providers.** If a game has a video (for example YouTube or Vimeo), it is embedded with WordPress' own oEmbed feature. That provider receives the visitor's request when the video is shown.

Leads from your forms are stored only in your WordPress database. They are not sent to Plairsoft or anyone else by this plugin.

== Installation ==

1. Install and activate the plugin. It creates a "Calendario de partidas" page (`[plairsoft_calendar]`) and a "Partida" page (`[plairsoft_game_detail]`).
2. In Plairsoft Manager → Integraciones, create an API key for your field.
3. In WordPress, go to Plairsoft → Configuración, enter the Field ID and the API key, and click "Validar".
4. Ask the Plairsoft team (info@plairsoft.com) to register your site's login client, using the callback URL shown on that screen (`https://your-domain/plairsoft/callback`). Enter the client ID and secret there, or in `wp-config.php` as `PLAIRSOFT_OAUTH_CLIENT_ID` and `PLAIRSOFT_OAUTH_CLIENT_SECRET`.
5. Click "Comprobar inicio de sesión" and check Tools → Site Health.

== Frequently Asked Questions ==

= Do I need a Plairsoft account? =

Yes. The plugin shows the games of a field registered in Plairsoft. Registering a field is free at https://manager.plairsoft.com.

= Can players pay by card? =

Yes, if the field offers online payment and has connected Stripe in Plairsoft. The payment happens on Stripe before the sign-up. The payment methods of each game (online, cash or card at the field) are the ones the field sets in Plairsoft; if online payment is not possible, the player is told so and can choose to pay at the field.

= What happens if Plairsoft is down? =

The site keeps showing the last good copy of the games (up to 24 hours), and the administrator sees a notice in the dashboard. The same happens if Plairsoft answers with data this version of the plugin does not understand.

= Should I turn on automatic updates? =

Yes. Plugins → Plairsoft Integration → "Enable auto-updates". Fixes to the plugin then reach your site as soon as they are released. The plugin's screens show a button to do it while they are off.

= Does it work with page caches? =

Yes. See "Caching" above.

= Where do I get help? =

In this plugin's support forum, or by writing to info@plairsoft.com. For anything about your field's account, games or payments, use Plairsoft Manager.

== Screenshots ==

1. Game calendar with the field's games: date, price, free spots and status of each one.
2. Game page: poster, description, power limits, players and the box with price, spots and sign-up.
3. Booking window, payment step: summary of the booking and the payment methods ("Pago online", "Efectivo en el campo", "Tarjeta en el campo").
4. A full game: the player joins its waiting list for free.
5. "Mis partidas": the player's upcoming games and waiting lists at this field.
6. Settings screen (Plairsoft → Configuración).

== Changelog ==

= 1.7.0 =
* New look based on the Plairsoft design system: the brand colours by default (light theme), clearer type hierarchy, tabular figures, visible keyboard focus and larger touch targets. Shadows only on floating elements (booking window and menus).
* Everything follows the colours set in Appearance: the calendar, game page, booking window, user menu, "Mis partidas" and the waiting list (before, some parts kept fixed colours). Sites that never changed the default colours get the new brand ones; custom colours are kept.
* Buttons on the main colour pick a readable text colour automatically (dark on light colours, white on dark ones).
* Icons are drawn as SVG instead of emoji, and a status is never shown by colour alone: it always has its text and an icon.
* Capacity bar: the fuller the game, the greener (as in Plairsoft).
* In block themes (such as Twenty Twenty-Five) the calendar and game page use the content width set in Appearance instead of the narrow reading column, and the empty "Partida" page no longer appears in the page list of the navigation.
* The booking window uses the same payment method names as the game page.
* Fixed: the default skin was never applied, and the Plairsoft logo was always dark (invisible on dark themes): it now takes the text colour.

= 1.6.1 =
* The game poster (a portrait image, 4:5) is shown whole on the cards, the list and the game page, over a blurred copy of itself, instead of being cropped. Field photos are shown as before.

= 1.6.0 =
* Waiting list for full games: join it for free, see your position, pay or confirm the held spot with its countdown, or leave it. Your waiting lists also appear in "Mis partidas".
* A game with people on the waiting list is full for everyone else, as in Plairsoft, even if a spot is free.
* Field closures (temporary or permanent) are shown above the calendar.
* The price is the one Plairsoft charges with each payment method. The early-payment offer only applies paying online in advance, and is shown as such.
* The game page shows the itinerary, photo gallery, attached files, roles with free spots, location, sign-up and leave deadlines, rules for minors and the photo policy. Cancelled and finished games say so.
* If the field hides how many players are signed up, the plugin hides it too.
* A signed-up player can leave a full game, and leaving explains who gets the spot and the refund policy.
* Clearer messages for more errors (sign-ups closed, bans, invalid team…).

= 1.5.2 =
* Activating the plugin creates the calendar and game pages, as described (until now only the button in the settings did). If a previous installation left them, they are reused instead of creating duplicates.
* "Mis partidas" (the player's upcoming games) is also in the `[plairsoft_user_menu]` shortcode.
* Each game page has its own meta description, Open Graph and Twitter tags, structured data (SportsEvent) and sitemap entry on any site. If the site uses an SEO plugin, the game's title, description, address and robots go through it, so nothing is printed twice.
* The description says exactly what the plugin does, including that the leads register is for your own forms.

= 1.5.1 =
* The calendar and game pages are created with the address in the site language (/jogo/ in Portuguese, /partida/ in Spanish), whatever the language of the administrator's profile.
* If the game page changes its address, links to the old one redirect to the new one (301).

= 1.5.0 =
* European Portuguese translation of the whole plugin: game calendar and page, booking window, user menu, settings, appearance, leads and Site Health.
* The insurance form asks for the ID document of the field's country (DNI/NIE in Spain, Cartão de Cidadão or NIF in Portugal, cédula in Colombia).
* Requests to the Plairsoft API carry the site language, so texts translated by the API match the page.
* The month view starts the week on the day set in Settings → General.
* Power limits and ratings use the decimal separator of the site language.
* Fixed: after paying by card, the confirmation showed the amount in euros even for games in other currencies.
* Fixed: in the list view on mobile, long prices (such as Colombian pesos) overlapped the game name.

= 1.4.4 =
* A sold-out extra stays visible in the booking with a «Agotado» (sold out) badge instead of its price and a note that no units are left, so players don't think they have to ask the field for it.

= 1.4.3 =
* Game times are shown in the time zone of the field where the game is played, in 24-hour format, instead of the WordPress site time zone. If the visitor is in another time zone, the game page also shows their local time.
* The month view asks the API for the month in the field time zone.
* Prices use the currency of each game, and day and month names follow the site language.
* Fixed: with some WordPress languages (such as Portuguese AO90), the game page could lose its log-in and leave buttons when the visitor was in another time zone.
* Until the Plairsoft API sends each field's time zone, fields in the Canary Islands, the Azores and Madeira get it from their province name.

= 1.4.2 =
* Extras with no units left in a game are shown as sold out and can't be chosen; with 10 or fewer left, the booking says how many remain.
* If an extra sells out while the player is booking, Plairsoft rejects the booking without charging; the plugin now says which extra it was, removes it from the selection and goes back to the extras step.

= 1.4.1 =
* Sending the site's technical information to Plairsoft is now opt-in (off by default), with a setting in Configuración. Without it, only the plugin version is sent with the regular API requests, and there is no daily request.
* The automatic updates notice can be dismissed.

= 1.4.0 =
* The site tells Plairsoft its plugin version and technical setup with each API request and once a day (see External services), so the Plairsoft team can see which sites need an update or are failing.
* A response from Plairsoft with an unexpected format no longer replaces the last good copy: the site keeps showing it and the administrator sees a notice.
* The login check (Site Health and "Comprobar inicio de sesión") reads a status code from Plairsoft instead of the text of the page.
* Clear messages when Plairsoft disables this site's login client or a game belongs to another field.
* The insurance details (ID number, address, birth date) are only requested when the player logs in to sign up for a game of a field that requires insurance.
* The player's name is shown again after logging in (it was read from the wrong fields).
* A notice with a button to turn on automatic updates on the plugin's screens.

= 1.3.3 =
* Filter callbacks (page title, SEO title, description and canonical) return escaped values.

= 1.3.2 =
* All CSS and JS is now loaded with the WordPress enqueue functions.
* Appearance font settings only accept valid font-family values; inline CSS values are validated when printed.
* Video embeds are filtered with an HTML allowlist.
* The OAuth client secret is stored exactly as entered.

= 1.3.1 =
* Clearer payment method names: "Pago online" (card, online), "Efectivo en el campo" (cash at the field) and "Tarjeta en el campo" (card terminal at the field).

= 1.3.0 =
* With card, payment now happens on Stripe before the sign-up, and Stripe sends the player back to the same game page.
* A game that no longer exists returns 404.
* Settings, caching, Site Health checks and many security fixes.

== Upgrade Notice ==

= 1.7.0 =
New look with the Plairsoft colours, SVG icons and better contrast and focus. Custom colours are kept.

= 1.6.1 =
Game posters are no longer cropped.

= 1.6.0 =
Waiting list for full games, field closures and the full information of each game.

= 1.5.2 =
Activation creates the calendar and game pages.

= 1.5.1 =
Game page address in the site language, and redirects from the old address if it changes.

= 1.5.0 =
Portuguese translation and country-aware ID document for the insurance.

= 1.4.4 =
Sold-out extras are shown clearly instead of looking like they are missing.

= 1.4.3 =
Game times in the field time zone, 24-hour format.

= 1.4.2 =
Shows which extras are sold out, so players can't book more units than the field offers.

= 1.4.1 =
Sending the site's technical information to Plairsoft is now opt-in.

= 1.4.0 =
Safer against changes in the Plairsoft API, and lets the Plairsoft team see the plugin version of each site.

= 1.3.3 =
Escaping fixes from the WordPress.org review.

= 1.3.2 =
Security hardening from the WordPress.org review.

= 1.3.1 =
Clearer payment method names.

= 1.3.0 =
Card payments happen before sign-up. Requires the current Plairsoft API.
