Settings rows
Every setting of Poly Community is a row on a page of Settings, in a card, with its owner: the core, the Community component, or a component by its slug. A row shows, saves and is found by the search of Settings only while its owner runs, so the settings of a component that is switched off are hidden with it and kept for when it is on again.
A component adds its own on poly_community_register_settings_rows. The callback is given the registry, and adds a card with add_section() and each row with add(). Both are stable.
Settings and pages drawn from data
Every page of Poly Community is one static file of its type for every reader, drawn by the browser from data (Pages drawn from data). A setting is the same for every reader, so reading one keeps a page that way: read it where the component registers what it draws, its blocks, its items and their who rules, as the starter reads its switch where it adds its menu item. Never read a setting together with a test of the reader to draw something for one reader in PHP. What depends on the reader is a fact the page shows its part by.
After a change, wp poly-community page-data check <page> on each page the setting changes says whether the page is still one drawing for every reader.
A card and a row
The starter of Building a component adds one card with one switch to its page, features/example-recipes, and reads the switch where it draws its menu item:
public function boot() {
add_action( 'poly_community_register_settings_rows', array( $this, 'settings' ) );
add_action( 'poly_community_register_ui', array( $this, 'ui' ) );
}
// Its settings: a card on its own page under Settings, Components, whose values $this->setting() reads.
public function settings( $rows ) {
$rows->add_section( array(
'id' => 'example-recipes-menu',
'page' => 'features/example-recipes',
'owner' => 'example-recipes',
'title' => __( 'The member menu', 'poly-community-recipes' ),
) );
$rows->add( array(
'key' => 'memberMenu',
'page' => 'features/example-recipes',
'section' => 'example-recipes-menu',
'owner' => 'example-recipes',
'type' => 'toggle',
'label' => __( 'Add a recipe in the member menu', 'poly-community-recipes' ),
'description' => __( 'An item under the picture of each member that opens the page of recipes.', 'poly-community-recipes' ),
'default' => true,
) );
}

$this->setting( 'memberMenu' ) then gives the value the owner saved, or the default until they save one. The plugin tests switch it off and check that the item leaves the menu (tests/specs/component-guide.spec.ts).
The rows of a component on its own page are kept with the component. They are saved with the rest of Settings, so a row needs no code to save it, and the value is cleaned by its type before it is kept.
A card
| Key | What |
|---|---|
id | Its id, prefixed with your component or plugin. Rows name it in their section. |
page | The page it is on: features/{slug} for the page of a component under Settings → Components. |
owner | The slug of the component, so the card shows while it is on. |
title, description | Its heading and the line under it. |
after | The id of the card it follows on that page. Without it, it goes last. |
A row
| Key | What |
|---|---|
key | Its name, which $this->setting() reads, each key once in a component. |
page, section | Its page and its card. |
owner | The slug of the component. |
type | How it is set, below. A switch when left out. |
label, description | Its words, and the line under them. |
default | Its value until the owner saves one. |
options | For a choice: a list of array( 'value' => …, 'label' => … ). |
min, max, step, unit | For a number: its bounds, its step (a step of 0.01 keeps two decimals) and the unit shown after it. For words, max is how many characters they keep (200 when left out). |
placeholder | What an empty field shows. |
when | The other rows of its page that must hold a value for this one to show: array( 'memberMenu' => true ) shows it only while that switch is on, and a list of values allows any of them. |
sanitize | A named function given the cleaned value and the value sent, answering the value to keep, for a rule of your own on top of its type. |
The types of row
type | Shows | Its value |
|---|---|---|
toggle | A switch | true or false |
number | A number field | A whole number, or one with the decimals of its step, held between min and max |
text | A line of words | The words, as plain text, at most max characters |
select | A dropdown of its options | The value chosen, or its default when the value is none of them |
choice | A radio button for each of its options | The same as select |
chips | A button for each of its options, any of them pressed | The list of values chosen |
ticks | A tick box for each of its options | The list of the options set off, so an option added later is on |
whocan | Who may do something, as the other "who can" rows of Poly Community | A rule of roles and member types |
The hook after a save
poly_community_kit_settings_saved runs after a save that changed the settings of one or more components, with the list of their slugs. A component that keeps something worked out from its settings forgets it there.
See also Building a component and What you can build.