=== GymGrow Connect ===
Contributors: gymgrowplugin
Tags: rest-api, rankmath, yoast, seo, publishing, automation
Requires at least: 5.8
Tested up to: 6.8
Requires PHP: 7.4
Stable tag: 1.4.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Secure REST endpoints to publish article content, set SEO fields (RankMath or Yoast), and upload images from an external automation pipeline.

== Description ==

GymGrow Connect adds a small set of secure REST API endpoints under the `gymgrow/v1` namespace so an external system (for example, an AI content pipeline) can:

* Create or update a post — title, content, excerpt, slug, categories, tags, schedule date — in a single request.
* Set SEO fields (SEO title, meta description, focus keyword, canonical URL, robots) on the same request or on an existing post. The active SEO plugin is auto-detected: RankMath or Yoast SEO.
* Upload an image from a multipart file or a remote URL, set its alt text, and optionally assign it as the featured image.

It replaces ad-hoc `functions.php` snippets with a versioned, capability-checked plugin.

= Endpoints =

* `POST /wp-json/gymgrow/v1/article` — publish/update an article (also sets SEO and featured image).
* `POST /wp-json/gymgrow/v1/media` — upload an image.
* `POST /wp-json/gymgrow/v1/seo/{id}` — update SEO fields for a post (RankMath or Yoast, whichever is active).

A backward-compatible alias `POST /wp-json/custom/v1/rankmath/{id}` is also registered for pipelines that used the legacy route.

= Authentication =

Requests are authenticated with the plugin's own API key, sent in the `X-GymGrow-Key` header. The key is generated automatically on activation and shown under Settings → GymGrow Connect. A valid key authorises publish, upload and SEO requests directly — no WordPress username or Application Password is required. (Requests from a logged-in user with the right capabilities still work as a fallback.)

This plugin does not call any external services and stores no personal data.

== Installation ==

1. Upload the `gymgrow-connect` folder to `/wp-content/plugins/`, or install the ZIP via Plugins → Add New → Upload Plugin.
2. Activate the plugin through the Plugins screen. An API key is generated automatically on activation.
3. Visit Settings → GymGrow Connect, copy the API key (and your site URL), and paste them into the GymGrow portal's connection screen.
4. (Optional) Choose a default category and default status on the same settings screen.

== Frequently Asked Questions ==

= Does it require RankMath or Yoast? =

No. The plugin auto-detects the active SEO plugin: if RankMath is active it writes RankMath meta, if Yoast SEO is active it writes Yoast meta, and if both are active it writes both. If neither is active the meta is stored under the RankMath keys and becomes live once RankMath is installed.

= How are the endpoints secured? =

Each route has a `permission_callback`. A request carrying a valid `X-GymGrow-Key` header is authorised for publish, upload and SEO. Without a key, the plugin falls back to WordPress capability checks (`publish_posts`, `upload_files`, `edit_post`) for a logged-in user.

= Does it send data anywhere? =

No. The plugin only receives requests; it does not phone home or contact third-party services.

== Changelog ==

= 1.4.1 =
* The "All articles →" footer link follows the hub page wherever it lives: if the plugin's page is gone, a published page titled "Blog" (or Training Resources, Artigos, Articles) is used instead of a fixed /training-resources/ URL, and with no such page the link goes to the blog category archive.
* A hub page with its own content (for example one rebuilt in a page builder) is never re-rendered or renamed by the plugin.

= 1.4.0 =
* Brings the WordPress.org release up to date with versions 1.1.0–1.3.0 below. This build updates through WordPress.org as usual.

= 1.3.0 =
* The articles hub page and the "Latest from our blog" footer now follow the site's content language: English (Training Resources, /training-resources/), Portuguese (Artigos, /artigos/) or French (Articles, /articles/).
* New "Site content language" setting (Settings → GymGrow Connect), also writable as `gymgrow_connect_language` through `/wp/v2/settings`. Auto follows the WordPress locale.
* An existing hub page is renamed to match the language unless its title was changed by hand.

= 1.2.0 =
* The article endpoint accepts `create_categories` ([{ slug, name }]) to create a missing category before publishing. Used by GymGrow announcements, which publish to an events category separate from the blog.
* The article endpoint's response now includes the post's `categories`, so the portal can confirm where a post landed.

= 1.1.1 =
* Fix: the "Latest from our blog" footer block (and the Training Resources hub page) was never loaded after 1.1.0 because the blog-feed class was not wired into the plugin loader. It now renders again on the front end.

= 1.1.0 =
* API-key authentication: a connection key is auto-generated on activation and shown prominently in settings. A valid `X-GymGrow-Key` header now authorises publish/upload/SEO directly, with no Application Password required.
* New `POST /gymgrow/v1/verify-connection` handshake endpoint returns the site URL and WordPress version so the GymGrow portal can confirm the pairing.

= 1.0.0 =
* Initial release: article publish endpoint, media upload endpoint, RankMath SEO endpoint, optional API key, settings screen.

== Upgrade Notice ==

= 1.4.1 =
Fixes the "All articles →" footer link on sites whose articles page was renamed, e.g. to Blog.

= 1.4.0 =
Adds one-key connection, automatic events categories and a translated articles hub page.

= 1.3.0 =
Translates the articles hub page and blog footer. Portuguese sites built with an English WordPress language: set Site content language to Português.

= 1.2.0 =
Lets GymGrow create the events category for announcements automatically.

= 1.1.1 =
Restores the "Latest from our blog" footer section that stopped appearing in 1.1.0. Deactivate and reactivate once so the Training Resources page is created.

= 1.1.0 =
Adds one-key connection: activate, copy the API key from Settings → GymGrow Connect, and paste it into the GymGrow portal. Application Passwords are no longer needed.

= 1.0.0 =
Initial release.
