=== Subset Fill ===
Contributors: functionform
Tags: acf, flexible content, ai, content, layouts
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 0.8.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Arrange pasted content into ACF Flexible Content layouts.

== Description ==

Subset Fill fills an ACF Flexible Content field from content you paste. The AI chooses which of your layouts each part belongs in and fills their sub-fields, using your words exactly as you wrote them. It arranges your content; it never writes or rewrites it.

**How it works**

* Turn the builder on for a Flexible Content field, and describe what each layout is for.
* On a post, click **Build from content**, paste your content (headings, lists, links, tables and images all come across) and click **Build**.
* The rows appear in the field, unsaved. Review them like any other edit, undo the build, or change anything. Nothing is saved until you click Update.

**Word for word, checked**

Every value is checked against what you pasted before it reaches the editor. Text, links, email addresses, image sources and numbers that aren't in your content are cleared, and the field is flagged so you can see what changed. Passages the AI didn't place anywhere are listed, so nothing goes missing quietly.

**Your provider, your key**

Choose Anthropic, OpenAI or OpenRouter and add your own API key, or on WordPress 7.0 and later use any provider connected in Settings → Connectors. Keys are stored encrypted, or can be defined in `wp-config.php`. The plugin calls the provider directly from your server: there's no account to create and nothing in between.

**Your layouts, your rules**

* Per layout: a description the AI chooses by, a maximum per page, and whether it belongs at the start, the end or anywhere.
* Per sub-field: fill it from the pasted content, or always leave it for a person.
* Text, textarea, email, URL, select, radio, checkbox, button group, WYSIWYG, number, true/false, link, image, group and repeater fields are filled. Other field types are left for a person and reported.

Requires ACF PRO or Secure Custom Fields, both of which include Flexible Content.

= For developers =

Filters change the schema the AI follows, the prompt, and the rows it returns, and the word-for-word check runs after all of them. Add a field type with a handler, or a provider on `sfcb_register_providers`. See the `docs` folder in the plugin.

== Installation ==

1. Install and activate ACF PRO or Secure Custom Fields.
2. Install and activate Subset Fill from Plugins → Add New.
3. Go to Subset → Fill, choose a provider and model, and add your API key.
4. Edit a field group, open a Flexible Content field and switch on **Content builder**. Add a **Builder description** to each layout.

== Frequently Asked Questions ==

= I uploaded the new version by hand and now see Subset Fill twice =

Before 0.7.0 the plugin lived in a folder called `subset-flexible-content-builder`, so uploading 0.7.0 adds it next to the old copy instead of replacing it. Both copies use the same settings. Deactivate the old copy, then delete it: the Plugins screen marks which one is the old copy. If you update through the Subset Installer you won't see this, because the update replaces the old folder.

= Does the AI write content for me? =

No. It only arranges the content you paste into your layouts. Anything it adds that isn't in your content is cleared before you see it.

= Does it work with the free version of ACF? =

No. Free ACF doesn't include Flexible Content. Use ACF PRO or Secure Custom Fields.

= Does it save the post? =

No. The rows are added to the field unsaved, for you to review. Nothing is saved until you click Update.

= What does it cost? =

The plugin is free. You pay your AI provider for what you use, under your own account.

= Where does my content go? =

Only to the provider you choose, and only when you click Build. The plugin doesn't store or log it. See "External services" below.

= Can I set it up from the command line? =

Yes, with WP-CLI: `wp subset content-builder provider set anthropic` chooses the provider and model, `wp subset content-builder key set anthropic` saves the API key (read from STDIN, never printed), and `wp subset content-builder key test` checks the connection. Run `wp help subset content-builder` for the rest.

= Why does Site Health say my API key can't be read? =

Saved keys are encrypted with your site's security keys in wp-config.php. If those change, the saved key can't be decrypted. Enter it again in Subset → Fill.

= How long can the content be? =

Up to 500 KB. Long content is split at headings and built in parts.

== External services ==

This plugin sends the content an editor pastes into the builder, together with the names, types and settings of the ACF fields it should fill, to the AI provider an administrator chooses in Subset → Fill. Nothing is sent until an editor clicks the build button, and only to the one provider selected. You bring your own API key, and the provider's terms apply to what it does with the data.

* Anthropic (api.anthropic.com): used when "Anthropic" is selected. [Terms](https://www.anthropic.com/legal/commercial-terms), [privacy policy](https://www.anthropic.com/legal/privacy).
* OpenAI (api.openai.com): used when "OpenAI" is selected. [Terms](https://openai.com/policies/terms-of-use/), [privacy policy](https://openai.com/policies/privacy-policy/).
* OpenRouter (openrouter.ai): used when "OpenRouter" is selected. OpenRouter forwards the request to the model provider behind the model ID you choose, such as Anthropic, OpenAI or Google. Requests carry the plugin's name in the X-OpenRouter-Title header, not this site's address. [Terms](https://openrouter.ai/terms), [privacy policy](https://openrouter.ai/privacy).
* WordPress AI Connectors (WordPress 7.0 and later): used when selected; the request goes to whichever provider you connected in Settings → Connectors.

"Test connection" also calls the selected provider, with your key and no pasted content (OpenRouter: openrouter.ai/api/v1/key and the model's endpoints).

The pasted content is not stored or logged by this plugin. The first time an editor opens the Build box, it says that their content is sent to the chosen provider. Settings → Privacy → Policy Guide has suggested text for your privacy policy.

== Screenshots ==

1. Paste your content into Build from content. Headings, lists, links and images come across.
2. The rows land in the field unsaved, with a summary, Undo build and the passages that weren't placed.
3. Text that wasn't in your content is removed, and the field says so.
4. Turn the builder on for a Flexible Content field, and describe each layout.
5. Subset → Fill: the provider, your API key and the model.

== Changelog ==

= 0.8.1 =
* Security: The Subset menu and its Overview page now need the same capability as a Subset page you can open, so a subscriber no longer reaches the Overview.
* Changed: Built on subset-core 1.13.3.

= 0.8.0 =
* Security: Cost estimates in the editor now have a rate limit of their own: 300 per user per hour, separate from builds. Over the limit, the estimate gets a "try again later" response, as builds do. Developers can change it with the new `sfcb_estimate_rate_limit` filter.
* Security: On some PHP builds, WP-CLI commands that call your AI provider no longer print the API key to the terminal.
* Changed: Built on subset-core 1.13.2.

= 0.7.1 =
* Changed: Built on subset-core 1.11.2.

= 0.7.0 =
* Changed: The plugin now lives in a `subset-fill` folder, with the text domain `subset-fill`. If you update through the Subset Installer, nothing changes for you: the update moves it and keeps it active. Settings, saved API keys, field group settings and integrations keep working.
* New: If you upload this version by hand, it lands next to the old `subset-flexible-content-builder` copy. It waits until you deactivate the old copy, then takes over with the same settings, and the Plugins screen and Site Health tell you to delete the old copy.
* Changed: Built on subset-core 1.10.0.

= 0.6.1 =
* Fixed: `wp help` no longer lists internal helpers as `key` and `provider` subcommands, and the command summaries are whole sentences.
* Changed: Built on subset-core 1.9.1.

= 0.6.0 =
* Changed: Builds run on the shared Subset AI code. Saved API keys, models, the 120-second time limit and error messages are unchanged.
* Changed: The build rate limit runs on the shared Subset rate limiter. Each user's count starts over once after this update.
* Changed: Built on subset-core 1.9.0.

= 0.5.0 =
* Fixed: A build that keeps failing now stops when its time limit runs out (120 seconds by default), instead of retrying for six minutes or more.
* Fixed: The per-layout settings in the field group editor now sit in valid markup, so a change to ACF's or SCF's layout screen can't break the page.
* Changed: A field's fill mode is saved only when it's set to "Always leave for a person" inside a Flexible Content field, so field group exports no longer carry it on every field.
* Fixed: Uninstalling now also removes the plugin's temporary data and each user's dismissed-notice flag.
* Changed: Subset Fill Pro can reuse more of this plugin's code instead of keeping its own copies.
* Changed: Built on subset-core 1.8.1.

= 0.4.3 =
* Changed: The plugin is now called Subset Fill. Settings and data are unchanged.

= 0.4.2 =
* The About tab uses plain WordPress admin styling.

= 0.4.1 =
* Accessibility and design fixes: the build dialog now works properly with keyboards and screen readers, status messages are announced once, and busy buttons keep focus.
* Better layout on small screens and in right-to-left and high-contrast modes.

= 0.4.0 =
* Content Builder now lives under the shared Subset menu (Subset > Content Builder). The old Settings URL redirects.

= 0.3.0 =
* Add-ons can add tabs to Settings > Content Builder.

= 0.2.0 =
* Initial release.
