Documentation

SettingsPageRegistrar
in package

Read onlyYes
FinalYes

Declarative settings pages: describe tabs → sections → {@see Field}s once and this registrar wires everything through the WordPress Settings API — `register_setting()` (with the field's type-default sanitizer), `add_settings_section()` and `add_settings_field()` (rendered by {@see FieldRenderer}).

Each tab registers under {page}-{tabSlug}; the consumer's page callback renders the active tab with settings_fields($optionGroup) + do_settings_sections("{page}-{tabSlug}"). Replaces the hand-rolled settings frameworks every plugin reinvents.

Use one option group per tab (call register() once per tab, each with its own $optionGroup). WordPress options.php saves every option of the posted group and writes null to the ones missing from the form, so a group shared by several tabs makes saving one tab erase the fields of the others.

The constructor needs no arguments: the staging SettingsRegistrar (an implementation detail) defaults to a fresh instance, so consumers never name it.

Table of Contents

Properties

$emitter  : ResponseEmitterInterface
$renderer  : FieldRenderer
$settings  : SettingsRegistrar

Methods

__construct()  : mixed
register()  : void
Stage and register every tab of a settings page.
tabPage()  : string
The settings-page slug a tab's sections register under.
echoField()  : string

Properties

Methods

register()

Stage and register every tab of a settings page.

public register(non-empty-string $page, non-empty-string $optionGroup, array<int, Tab> $tabs[, CapabilityInterface|string $capability = 'manage_options' ]) : void
Parameters
$page : non-empty-string

settings page slug (menu wiring is the consumer's concern)

$optionGroup : non-empty-string

register_setting() option group; use a distinct group for each tab (see the class docblock)

$tabs : array<int, Tab>
$capability : CapabilityInterface|string = 'manage_options'

capability required to WRITE the options (raw string or typed)

tabPage()

The settings-page slug a tab's sections register under.

public tabPage(string $page, Tab $tab) : string
Parameters
$page : string
$tab : Tab
Return values
string
On this page

Search results