=== Rankomodo Connector ===
Contributors: wporg-username-jarot
Tags: seo, meta description, redirects, internal links, schema
Requires at least: 6.6
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 0.9.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Apply the SEO fixes you approve in Rankomodo (title, meta description, redirect, internal link, JSON-LD) and revert them anytime.

== Description ==

Rankomodo finds SEO problems on your website and prepares fixes. This plugin is the connector that lets Rankomodo apply the fixes **you approve** in your Rankomodo account, and revert them if you change your mind.

It is deliberately small and strict:

* Only five kinds of change: the SEO title and meta description (for Yoast SEO, Rank Math, SEOPress, or All in One SEO), 301 redirects, internal links, and JSON-LD structured data blocks.
* No arbitrary code execution. The only change to post content is an internal link: a phrase that is already in your text is wrapped in a link to another page of your site. Your words are never changed, links are never placed in headings, existing links, code, or shortcodes, and the link is marked so it can be removed exactly.
* Every request from Rankomodo is signed (HMAC-SHA256) with a secret that only your site and your Rankomodo account know, with a timestamp, a one-time nonce, and a unique operation ID, so a request cannot be forged or replayed.
* Changes only apply to published pages on this site. Redirects never overwrite an existing redirect.
* JSON-LD blocks are stored with the page (or with the homepage when it lists your latest posts) and printed in the page head, marked so each one can be replaced or removed exactly. Only schema.org blocks with a type are accepted, at most 5 per page and 16 KB each; your content is not touched.
* You approve every change in Rankomodo first, and each applied change records the previous value so it can be reverted.
* Safety limits enforced by your own site, even if a Rankomodo account or server were ever compromised: at most 60 changes per hour and 150 per day (adjustable with `RANKOMODO_MAX_CHANGES_PER_HOUR` and `RANKOMODO_MAX_CHANGES_PER_DAY` in wp-config.php), titles and descriptions must be plain text, redirects and links can only point to this site and only redirect addresses that do not exist, and JSON-LD blocks with reviews or ratings are refused.
* Read-only mode: one checkbox in Settings > Rankomodo (or `define('RANKOMODO_READ_ONLY', true);` in wp-config.php) stops every change from Rankomodo, reverting included, while keeping the connection.
* The last 100 changes (time, page, value before and after) are listed in Settings > Rankomodo, stored on your site, so you can check and undo them yourself.
* AI crawler counts: when a known AI crawler (for example GPTBot, ClaudeBot, or PerplexityBot, recognised by its User-Agent) loads a page, the plugin adds one to a daily count for that page and crawler in its own table. Only the date, the page path, the crawler name, and the count are stored; no IP address, raw User-Agent, cookie, or visitor data, and human visitors are never counted. Counts older than 60 days are deleted daily, search result and paginated pages are not counted, and the number of new page and crawler pairs per day is capped so the table cannot be flooded. Pages served from a full-page cache are not counted. For crawlers whose operators publish official IP lists (GPTBot, OAI-SearchBot, ChatGPT-User, PerplexityBot, Perplexity-User), a visit from a public IP address outside that list is not counted, because its User-Agent is fake; the visitor's IP address is only compared in memory and never stored. Other crawlers are still recognised by User-Agent alone, which can be faked, so the counts are an indication rather than proof.
* After a change is applied or reverted, Rankomodo tells search engines that support IndexNow which pages changed, so they can recrawl them sooner. The plugin serves this site's IndexNow key file (a random text file at the root of your site) for that purpose.

An active Rankomodo account on a plan that includes automatic fixes is required to use this plugin. The plugin does nothing on its own.

= Connect in one click =

Go to Settings > Rankomodo and press **Connect to Rankomodo**. You sign in to Rankomodo with your own account (on rankomodo.com, never inside WordPress), confirm the site, and you are connected. Your Rankomodo password is never entered or stored in WordPress.

== External services ==

This plugin works with Rankomodo, an external SEO service operated by Simplicode (https://rankomodo.com). It is a connector: without a Rankomodo account it does nothing. Below is every connection the plugin makes or accepts, what is sent, and when.

= Rankomodo (app.rankomodo.com): connecting this site =

* **What it is used for:** pairing this site with your Rankomodo account, so Rankomodo can send signed change requests to this site.
* **When:** only when an administrator presses **Connect to Rankomodo** in Settings > Rankomodo. Nothing is sent on activation, in the background, or on a schedule.
* **What is sent:** your browser is sent to https://app.rankomodo.com/connect/wordpress with this site's address (for example https://example.com), the address of the settings page to return to, a random state value, and a PKCE challenge. You sign in and approve there; your Rankomodo password is never entered in WordPress. When you return, this site sends one request to https://app.rankomodo.com/api/wordpress/pair/token with the one-time code, the one-time PKCE verifier, and this site's address, and receives the connection secret. No other site, user, or visitor data is sent.
* Terms of Service: https://rankomodo.com/terms/
* Privacy Policy: https://rankomodo.com/privacy/

= Rankomodo: signed requests to this site after connecting =

* The plugin does not send data to Rankomodo on its own. It only answers requests that Rankomodo signs with this site's secret (REST routes under /wp-json/rankomodo/v1/).
* **What Rankomodo can read through them:** the current SEO title, meta description, redirect, internal link, or JSON-LD block of a page it is about to change (so the change can be reverted), whether read-only mode is on, this site's IndexNow key, and the daily AI crawler counts described above (date, page path, crawler name, count).
* **What Rankomodo can change through them:** only the changes you approved in your Rankomodo account, within the limits described above.
* Disconnect or delete the plugin at any time to stop this.

= IndexNow (api.indexnow.org), sent by Rankomodo, not by this plugin =

* The plugin creates a random IndexNow key for this site and serves it at https://your-site/<key>.txt.
* After a change is applied or reverted, the Rankomodo service (not this plugin) sends the changed page addresses and this key to the shared IndexNow endpoint (https://api.indexnow.org, used by Bing, Yandex, Seznam, Naver and others), so they can recrawl those pages sooner. Only addresses of pages Rankomodo changed are sent.
* IndexNow terms: https://www.indexnow.org/terms and privacy (Microsoft, which operates api.indexnow.org): https://privacy.microsoft.com/privacystatement

= Official AI crawler IP lists (openai.com, perplexity.com) =

* **What it is used for:** checking that visits counted as GPTBot, OAI-SearchBot, ChatGPT-User, PerplexityBot, or Perplexity-User really come from those crawlers (see AI crawler counts above).
* **When:** once a day, through WordPress cron (the plugin's daily clean-up task).
* **What is requested:** plain GET requests for the published lists https://openai.com/gptbot.json, https://openai.com/searchbot.json, https://openai.com/chatgpt-user.json, https://www.perplexity.com/perplexitybot.json, and https://www.perplexity.com/perplexity-user.json. No site address, visitor, or account data is sent (only what any HTTP request carries, such as your server's IP address and the WordPress user agent).
* OpenAI terms: https://openai.com/policies/terms-of-use/ and privacy: https://openai.com/policies/privacy-policy/
* Perplexity terms: https://www.perplexity.ai/hub/legal/terms-of-service and privacy: https://www.perplexity.ai/hub/legal/privacy-policy

= Update check (only in the build downloaded from rankomodo.com, not in the WordPress.org build) =

* **Update check:** WordPress itself asks https://rankomodo.com/wordpress-plugin/update.json whether a newer version exists, as part of its normal plugin update check. It is a plain GET request; no site address, account, or other data is sent. Set `define('RANKOMODO_DISABLE_UPDATES', true);` in wp-config.php to turn it off.

== Installation ==

1. Upload the plugin and activate it (WordPress 6.6+, PHP 8.1+).
2. Go to Settings > Rankomodo and press **Connect to Rankomodo**.
3. Sign in to Rankomodo and confirm the site.

Supported SEO plugins: Yoast SEO, Rank Math, SEOPress, and All in One SEO (4.9.9 or newer). Without one of them, SEO title and meta changes are refused (redirects still work).

Your site must use HTTPS at the root of its domain. WordPress installed in a subdirectory is not supported yet.

== Frequently Asked Questions ==

= Does this plugin change my site without my approval? =

No. Rankomodo only sends changes you approved in your Rankomodo account, and the plugin only accepts requests signed with your site's secret.

= Which plan do I need? =

Automatic fixes are part of Rankomodo's Ultimate and Agency plans. See https://rankomodo.com for current plans.

= How do I stop all changes immediately? =

Turn on **Read-only mode** in Settings > Rankomodo, or press **Disconnect**. Both take effect on the next request; nothing else is needed.

= How do I disconnect? =

Settings > Rankomodo > Disconnect, or just deactivate or delete the plugin. Deleting the plugin removes its stored secret, redirects, JSON-LD blocks, activity log, and temporary data. SEO titles and descriptions you approved stay in your SEO plugin.

= Does it work without a Rankomodo account? =

No. The plugin is the site side of the Rankomodo service: it applies changes that you approve in Rankomodo. On its own it only counts AI crawler visits and serves the IndexNow key file; nothing else happens until you connect.

= Does the plugin track my visitors? =

No. It sets no cookies, adds no scripts to your pages, and stores no visitor data. The AI crawler counts only store the date, the page path, the crawler name, and a number; human visitors are never counted, and IP addresses are only compared in memory against the crawlers' official lists, never stored or sent.

= Does the plugin load anything from other sites? =

No scripts, styles, fonts, or images are loaded from other sites, in the admin or on your pages. The only outgoing requests are listed under External services.

= What if my hosting blocks outgoing requests? =

Use "Connect manually with a secret" on the same settings page and paste the secret shown in Rankomodo.

== Screenshots ==

1. Settings > Rankomodo before connecting: one button, and a plain explanation of what Rankomodo can change.
2. After you approve the connection in your Rankomodo account: connected status, read-only mode, and the change limits enforced by your site.
3. The activity log on your own site: each change Rankomodo applied, with the value before and after.

== Changelog ==

= 0.9.0 =
* Planned internal links. Rankomodo first reads the post and shows you the sentence where the link will go. The link is inserted only if the post is still exactly the same as when you approved it; if someone edited it in the meantime, nothing is changed.
* Only text blocks are linked: paragraphs, lists, quotes, tables, and classic content. Headings, existing links, code, custom HTML, shortcodes, buttons, and blocks from other plugins are never touched.
* Pages built with Elementor, Bricks, Divi, Beaver Builder, or Oxygen are reported as not supported and left alone.
* At most 10 Rankomodo links per post (adjustable with the `RANKOMODO_MAX_LINKS_PER_POST` constant in wp-config.php), and never a second link to the same page.
* A WordPress revision of the post is saved before the link is added, and reverting is checked to restore the post byte for byte.
* WordPress.org directory compliance: the plugin passes Plugin Check, the readme follows the directory standard, and all admin texts are translatable. No change in behaviour.

= 0.8.0 =
* Security hardening. Requests are now checked in the REST API permission callback (signature and timestamp) before they reach the plugin.
* Read-only mode (setting or `RANKOMODO_READ_ONLY` constant): Rankomodo can read the site but every change, reverting included, is refused.
* Change limits counted on your site: 60 per hour and 150 per day by default, adjustable in wp-config.php.
* Activity log: the last 100 changes with the value before and after, shown in Settings > Rankomodo.
* Stricter values: restored titles and descriptions must also be plain text, control characters are refused, redirect and link targets must be http or https addresses on this site without user names, JSON-LD with reviews or ratings is refused, and a redirect only applies when WordPress would otherwise show "not found".
* Deleting the plugin also removes its JSON-LD blocks, activity log, and limit counters.

= 0.7.2 =
* AI crawler checks: X-Forwarded-For is now used only when the request comes from a local proxy (private or loopback address). From a public address the header can be set by anyone, so it no longer counts as proof of an official crawler IP.

= 0.7.1 =
* AI crawler counts: visits that claim to be GPTBot, OAI-SearchBot, ChatGPT-User, PerplexityBot, or Perplexity-User but come from a public IP address outside the crawler's official IP list are no longer counted. The lists are downloaded once a day; IP addresses are never stored. Sites behind Cloudflare or a proxy are supported (CF-Connecting-IP from Cloudflare addresses, X-Forwarded-For).

= 0.7.0 =
* AI crawler counts: daily per-page counts of visits by known AI crawlers (GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, Claude-User, Claude-SearchBot, PerplexityBot, Perplexity-User, and others), recognised by User-Agent and stored in the plugin's own table without IP addresses or visitor data. Rankomodo reads them through a signed request. The table is removed when the plugin is deleted.

= 0.6.0 =
* JSON-LD: an approved structured data block (for example WebSite and Organization on the homepage) is stored with the page and printed in the head as a marked application/ld+json script. Reverting removes the block, or restores the block that was there before.
* SEO title and meta description values containing a backslash are now saved unchanged.

= 0.5.0 =
* Internal links: an approved link suggestion wraps a phrase that already appears in the post with a link to another page on the same site. The post is saved exactly as before apart from that one link (embeds and scripts added by administrators are kept), a revision is created, and reverting removes the link and restores the post byte for byte.
* Tested with WordPress 7.1.3 (block editor content).

= 0.4.0 =
* IndexNow: after an approved change is applied or reverted, search engines that support IndexNow are told which pages changed. The plugin serves a random key file for this site; nothing is sent by the plugin itself.

= 0.3.0 =
* All in One SEO (4.9.9 or newer) is now supported for the SEO title and meta description. Other All in One SEO fields (canonical URL, social titles, focus keyphrase) are never touched. Older All in One SEO versions are refused because they overwrite those fields.
* Build downloaded from rankomodo.com: WordPress now offers new versions of the plugin itself, with a SHA-256 check before installing. The WordPress.org build is updated through WordPress.org instead.
* Tested with PHP 8.1 and 8.3, and with All in One SEO 4.9.9 and 5.0.3 on WordPress 7.1.

= 0.2.1 =
* Rank Math: changes are only written once Rank Math is set up (account connected or registration skipped), so they always show on the page.
* Titles and descriptions must be plain text; values with HTML tags are refused because SEO plugins strip them when printing.
* Tested with Yoast SEO 28.6, Rank Math SEO 1.0.280, and SEOPress 10.3 on WordPress 7.1 and 7.0.

= 0.2.0 =
* One-click connection from Settings > Rankomodo (OAuth authorization code with PKCE).
* Disconnect button, uninstall cleanup, translations support (Indonesian included), and WordPress.org readme.

= 0.1.0 =
* Initial release: signed read/apply endpoints, SEO title and meta description for Yoast SEO, Rank Math, SEOPress, and 301 redirects.

== Upgrade Notice ==

= 0.9.0 =
Planned internal links: the post must be unchanged since approval, only text blocks are linked, page builder pages are left alone, and a revision is saved first. Also wordpress.org directory compliance.

= 0.8.0 =
Security hardening: signature check in the REST permission callback, read-only mode, change limits counted on your site, and a local activity log. Recommended for all users.

= 0.7.2 =
AI crawler counts no longer trust X-Forwarded-For from public addresses.

= 0.7.1 =
AI crawler visits from addresses outside the official IP lists are no longer counted.

= 0.6.0 =
Adds JSON-LD structured data blocks and keeps SEO values with a backslash unchanged.
