=== Ruvma Connector ===
Contributors: ruvma
Tags: agency, content changes, preview, clients, editing
Requires at least: 6.4
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.9.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lets Ruvma make the text, link and image changes your agency approves, with a private preview before anything goes live.

== Description ==

Ruvma reads your clients' change requests, plans each change and sends your agency a preview to approve. On WordPress sites it works through this plugin, which makes every change exactly and checks it:

* Ruvma reads a page's texts, links and images through the plugin, and plans each change as an exact edit: this element, this field, this new value.
* The plugin applies the edits to a copy of the page and returns a private preview link. Previews are never cached or indexed, and expire after seven days.
* When your agency approves, the plugin checks nobody edited the page since the preview, saves it (WordPress keeps a revision of the page as it was), reads it back to confirm every byte, and purges the page from caches.
* A published change can be put back, as long as nobody has edited the page since.

= What Ruvma can change =

* Block editor pages and posts: paragraphs, headings, list items, buttons, quotes, tables, captions, details, verse and preformatted text, the links in them, images (replaced with one the client sent) and their alt text. Ruvma can also add a paragraph or an image after a block.
* Classic editor pages and posts: the same, in the HTML as stored, including text that WordPress turns into paragraphs, except adding blocks.
* Pages built with Elementor: what their widgets say, link to and show, including the items of a widget's list, for Elementor's own widgets and other plugins' alike. Nothing is added to them yet.
* Page and post titles, whichever editor made the page. The page's address stays as it is.
* Menus from Appearance → Menus: each item's label, and a custom link's address.
* Headers, footers and sidebars: Text, Custom HTML and Block widgets; the HTML, copyright and buttons of Astra's header and footer builder; and header and footer templates built with Elementor, from ElementsKit, Header Footer Elementor or Elementor Pro.
* Not yet: pages built with Divi, Beaver Builder, Bricks, Oxygen or WPBakery; block theme template parts, synced patterns and block theme navigation.

= Security =

* The plugin makes its own user, with a narrow role: it can edit and publish pages and posts and upload images. It can't sign in to the dashboard or reset its password, and its Application Password works only on this plugin's routes, not on WordPress's own REST API or XML-RPC.
* Through the plugin, Ruvma can also change what WordPress keeps outside pages and posts: menu items' labels and links, Text, Custom HTML and Block widgets, Astra's header and footer builder (its HTML, copyright and buttons), and header and footer templates built with Elementor. It can't install or change plugins, themes or users, or other settings.
* Deactivating the plugin revokes the connection key and takes the Ruvma user's role away, so nothing of Ruvma's works on the site while the plugin is off. Disconnecting the site in Ruvma revokes the key too.
* Every request needs that user's Application Password and a signature made with the site's own secret. Both are in the connection key. Making a new key stops the old one.
* Any administrator can pause Ruvma in Settings → Ruvma. Ruvma can pause itself too, but a pause set in WordPress can only be lifted there.
* The site needs HTTPS. Plain HTTP works only for a site on the same computer (localhost, *.localhost or *.test), for development.

= Privacy =

The plugin sends nothing about your site on its own. It answers signed requests from Ruvma, which reads your published pages and posts to make the changes your agency asks for. For updates, WordPress asks www.ruvma.com for the plugin's latest version, as it asks wordpress.org about other plugins: twice a day, and when you look for updates. It downloads each update from there too, and installs it only with Ruvma's signature. These requests carry the plugin's version and nothing about the site. The plugin keeps a log of what Ruvma did, and a copy of each changed page for putting changes back, for 180 days.

== Installation ==

1. Install and activate the plugin.
2. Go to Settings → Ruvma and select Create connection key.
3. In Ruvma, open the client's site and paste the key.

The site needs HTTPS and Application Passwords, which some security plugins turn off, and which WordPress keeps off when it doesn't see the site as HTTPS, as behind Cloudflare with SSL/TLS set to Flexible.

== Frequently Asked Questions ==

= Can Ruvma change anything without our approval? =

No. Ruvma publishes only after your agency approves the preview in Ruvma, and only what the preview shows.

One thing reaches the site before that: an image the client sent, which WordPress needs in the media library to show it on the preview. Until the change is approved it's private and left out of the Media Library, and its file is at an address only the preview shows. If the change isn't published, the plugin deletes it as soon as Ruvma tells it, or, if the site couldn't be reached then, within eight days.

= What happens if someone edits the page while a change waits for approval? =

Publishing stops, and Ruvma makes a new preview from the page as it is now.

= How does the plugin stay up to date? =

From version 0.8.0, WordPress offers each new version on the Plugins screen and in Dashboard → Updates, as it does for plugins from wordpress.org, with what changed under View details. To have WordPress install them by itself, select Enable auto-updates next to the plugin in Plugins. An older version doesn't know where its updates are: download the new one from Ruvma, then in Plugins select Add New Plugin, then Upload Plugin, choose the file, select Install Now, then Replace current with uploaded. Updating keeps the connection key and everything Ruvma did.

From version 0.9.1, the plugin installs an update only when it carries Ruvma's signature, made with a key that never leaves Ruvma's release machine. It checks the signature before WordPress unpacks anything. An update without one, or whose file changed on its way, isn't installed: the Plugins screen says why, and the site keeps the version it has.

= How do I disconnect Ruvma? =

Pause it in Settings → Ruvma, or deactivate the plugin, which revokes the connection key at once: activating it again needs a new key. Disconnecting the site in Ruvma revokes the key too. Deleting the plugin removes its user, its settings and its log.

= Ruvma can't reach the site. What's wrong? =

Select Check connection on the site's page in Ruvma: it tries each step and says what to change. The usual causes are a security plugin that turns Application Passwords off, a proxy or CDN that hides from WordPress that the site is on HTTPS, which turns them off too (in Cloudflare, set SSL/TLS to Full (strict) rather than Flexible), a firewall or bot protection that turns Ruvma's requests away (allow requests to `/wp-json/ruvma/v1/` that carry the `X-Ruvma-Signature` header), and a host that drops the `Authorization` header, which from version 0.9.0 the plugin works around by itself.

== Ruvma's API ==

Ruvma calls these routes under `/wp-json/ruvma/v1`. Each request carries Basic authentication with the Ruvma user's Application Password, and `X-Ruvma-Timestamp` (Unix seconds, within five minutes of the site's clock) and `X-Ruvma-Signature: v1=<hex>`, the HMAC-SHA256 with the site's secret of: the timestamp, the method, the route (such as `/ruvma/v1/changesets`) and the SHA-256 of the body in hex, joined by newlines. A refused sign-in answers 401 with WordPress's reason as its code, such as `incorrect_password`, and a time too far off with the site's time in `site_time`.

The same Basic credentials also come in `X-Ruvma-Authorization`. On a host that drops the `Authorization` header, the plugin reads them from there, for its own routes only and for the Ruvma user only; the signature is still needed. No cache keeps the routes' answers.

* `GET /probe`, without authentication: the plugin's version (`connector`), and whether the `Authorization`, `X-Ruvma-Authorization` and `X-Ruvma-Signature` headers reached WordPress on that request (`authorization`, `fallback`, `signature`). It says nothing about the site.
* `GET /health`: the plugin and WordPress versions, whether Ruvma is paused and by whom (`admin` or `ruvma`), the editors and cache plugins found.
* `POST /pause` with `{"paused": true}` or `false`. Turning Ruvma back on answers 423 when an administrator paused it.
* `POST /revoke`: revokes the connection key the request was made with, as Ruvma does when the agency disconnects the site or is deleted. The Ruvma user's Application Password goes and the site's secret changes, so no part of the key works after the answer, `{"revoked": true}`.
* `GET /pages`: every published page and post, with its ID, path, editor and a SHA-256 of its content, and its language (`lang`) on a site with WPML or Polylang.
* `GET /content/{id}`: the page's elements, each with an ID, a kind (text, link or image), a field (html, href, text or alt), its value and the SHA-256 of the value. The first is the page's title (`title`, field `text`), also on a page whose content Ruvma can't change. On an Elementor page, the elements are its widgets' settings (`e:<widget ID>/<setting>`, and `e:<widget ID>/<list>/<item ID>/<field>` for an item in a list), and `content_hash` is its Elementor data's.
* `GET /menus`: the menus, with the theme locations that show them, a `content_hash`, and their items as elements: `m:<item ID>` with its label (`text`), and a custom link's address (`href`).
* `GET /parts`: the headers, footers and widgets the site shows, each with an ID (`widget:<widget ID>`, `astra:<component>` or `template:<post ID>`), a kind (`widget`, `astra` or `template`), a name, an area (`header`, `footer` or `sidebar`), the page its preview shows (`link`), a `content_hash`, and its elements: a widget's title (`w:title`) and the elements of its HTML or blocks, as on a page; an Astra button's label and address (`button`, fields `text` and `href`); a template's widgets' settings, as on an Elementor page.
* `POST /media` with `{"url", "filename", "alt"}`: downloads an image over HTTPS into the media library and returns its `id`. A change uses it as `attachment:<id>`. Until a change set that uses it is published, it's private, the media list of WordPress's REST API and the Media Library leave it out, and its file's name has a random part. Discarding the change set deletes it, unless another open or published change set uses it; one no change set uses is deleted after a day, and one only open change sets use after eight. Publishing a change set again that is already published keeps its images.
* `POST /changesets` with `{"page_id", "base_hash", "changes": [{"op", "element", "field", "expected_hash", "value", "alt", "label"}]}`: returns the change set's ID, its preview link, and two review links (`review_urls`): the preview with each change outlined and its new words highlighted (`after`), and the page as it is with the words that go highlighted (`before`).
  * `op` is `set` (the default): sets an element's `html`, `href`, `text`, `alt` or `src`. A new `src` is `attachment:<id>`; the image's `wp-image-<id>` class and its block's `id` change with it.
  * Or `op` is `insert_after`, on block editor pages: adds a `paragraph` (`value` is its HTML) or an `image` (`value` is `attachment:<id>`, with an optional `alt`) after the element's block, or after the block around it when that one only holds certain blocks, such as a list. `expected_hash` is any of the element's fields'.
  * Or `op` is `insert_after` or `insert_before` with the field `list_item` (`value` is its HTML), and a list item as the element: the new item goes right after or before it, in the same list, on block editor and classic pages alike.
  * `label`, up to 8 letters and digits, is the number shown on the change; it's optional.
  * A change to the `title` sets its `text`. It's saved with the page's content and put back with it; every page's cache is purged, as menus and page lists show titles.
  * With `menu_id` in place of `page_id` and the menu's `content_hash` as `base_hash`, the changes set its items' `text` or `href`. The preview and review links show the front page with the menu changed.
  * With `part` in place of `page_id` and the part's `content_hash` as `base_hash`, the changes are to a header, a footer or a widget from `GET /parts`. The preview and review links show the part's `link`, and publishing purges every page.
  * A preview or review link may add `ruvma_with`, the `ruvma_preview` tokens of other change sets, comma-separated: what of them every page shows (a menu, a header, a footer, a widget, a page's new title) shows on the link's page too.
* `POST /changesets/{id}/publish`, `POST /changesets/{id}/revert` and `DELETE /changesets/{id}`.

While Ruvma is paused, every route except `/probe`, `/health`, `/pause` and `/revoke` answers 423. The signed routes take no query parameters: everything is in the signed route and body.

== Changelog ==

= 0.9.1 =
* Deactivating the plugin cuts Ruvma off at once: it revokes the connection key and takes the Ruvma user's role away, so the key works nowhere on the site, WordPress's own REST API and XML-RPC included. Activate the plugin and make a new key to connect again.
* Disconnecting the site in Ruvma, or deleting the agency, has the plugin revoke its own key.
* An image the client sent stays private and out of the Media Library while its preview waits, under a file name nobody can guess, and is deleted as soon as the request is rejected, cancelled or closed.
* Updates install only with Ruvma's signature, which the plugin checks before WordPress unpacks anything. The Plugins screen says why when one doesn't.
* A change's number on a review link no longer covers the words next to it.
* Settings, then Ruvma names the usual reason Application Passwords are off: WordPress doesn't see the site as HTTPS, as behind Cloudflare with SSL/TLS set to Flexible.

= 0.9.0 =
* Ruvma connects on hosts that drop the Authorization header, common where PHP runs as CGI or FastCGI: it sends its sign-in in its own header too, which the plugin reads for its routes only.
* Ruvma can check the connection: a probe says which of its headers reach WordPress, a refused sign-in says why, such as a key that was replaced, and a request signed at the wrong time says how far off the site's clock is.
* No page cache, CDN or browser keeps the plugin's answers to Ruvma.

= 0.8.0 =
* WordPress keeps the plugin up to date: each new version shows on the Plugins screen and in Dashboard → Updates, with what changed under View details, and installs by itself once you turn on auto-updates for the plugin.
* Updates come from www.ruvma.com. Checking for one and downloading it carry the plugin's version and nothing about the site.

= 0.7.0 =
* Ruvma can change headers, footers and sidebars: the words, links and images of Text, Custom HTML and Block widgets, and a widget's title; the HTML, copyright and buttons of Astra's header and footer builder; and the widgets of header and footer templates built with Elementor (ElementsKit, Header Footer Elementor, Elementor Pro).
* A header's or a footer's preview shows the front page, with the change numbered on a review link, and publishing purges every page.
* A preview can show a request's other changes that every page shows, such as a new footer on a page's preview.

= 0.6.0 =
* Ruvma can change what the widgets of a page built with Elementor say, link to and show: headings, text, buttons, images, the items of icon lists and other lists, and other plugins' widgets. It saves the page through Elementor, which renews the page's styles.
* An Elementor page's preview shows the change, with each changed widget numbered on a review link. Elementor keeps nothing a preview draws.
* On a site with WPML or Polylang, Ruvma knows each page's language.

= 0.5.0 =
* Ruvma can rename a page or a post: the title changes with the page, and its address stays.
* Ruvma can change a menu item's label, and where a custom link in a menu goes.
* A page built with Elementor counts as one only while Elementor is active.

= 0.4.0 =
* Ruvma can add an item to a list, before or after any of its items, on block editor and classic pages.

= 0.3.1 =
* Ruvma can add two blocks in the same place, such as an image and a paragraph after one block.

= 0.3.0 =
* Ruvma can replace an image with one the client sent, and add a paragraph or an image after a block, on block editor pages.
* Images Ruvma adds for a preview that's never published are deleted after eight days.

= 0.2.0 =
* Review links: Ruvma's review screen shows each change outlined and numbered, with the words it adds or takes away highlighted, on the preview and on the page as it is.

= 0.1.0 =
* First release.
