Skip to content

Extract Settings schema, field HTML, and sanitization into collaborators. - #1994

Open
shadyvb wants to merge 2 commits into
ticket/XWPENG-50-list-table-splitfrom
ticket/XWPENG-51-settings-split
Open

Extract Settings schema, field HTML, and sanitization into collaborators.#1994
shadyvb wants to merge 2 commits into
ticket/XWPENG-50-list-table-splitfrom
ticket/XWPENG-51-settings-split

Conversation

@shadyvb

@shadyvb shadyvb commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Fixes XWPENG-51.

This PR continues the Settings decomposition started in the List Table split (XWPENG-50). The monolithic Settings class mixed three concerns—field schema, admin HTML rendering, and posted-value sanitization—that were hard to unit test without booting WordPress. Those responsibilities are now extracted into dedicated collaborators while Settings keeps option persistence, registration, AJAX helpers, and TTL side effects.

Approach

  • Settings_Registry — owns the settings schema: section/field definitions, defaults keyed by {section}_{name}, has_field() / get_field() lookup, role choices, deletion-warning copy, and serialized-label translations. Applies the existing wp_stream_settings_option_fields filter and sticky title sort.
  • Settings_Renderer — renders field markup for all supported types (checkbox, multi-checkbox, number, rule list, link actions, etc.) and connector-driven term labels.
  • Settings_Sanitizer — normalizes posted values by field type (number, checkbox, nested arrays, text). Exposes both the register_setting() callback and a reusable sanitize_settings( $input, $fields ) API.
  • Settings — wires the three collaborators as public properties ($registry, $renderer, $sanitizer) and delegates rendering/sanitization while retaining hooks, option reads/writes, and purge/TTL behavior.

Call sites that previously reached into Settings for schema or sanitization now use the collaborators directly (Ability_Update_Settings, Network, admin purge/screen, connector settings). Existing integration tests were updated for the new entry points.

Unit tests

Adds Brain Monkey unit coverage (no WordPress bootstrap):

  • Settings_Registry_Unit_Test — schema sections, {section}_{name} defaults/lookup, network filter injection, translation labels, deletion warnings, role resolution (with a dedicated WP_Roles stub file).
  • Settings_Renderer_Unit_Test — representative field HTML output and connector label helpers.
  • Settings_Sanitizer_Unit_Test — per-type sanitization and nested array handling.

Checklist

  • Project documentation has been updated to reflect the changes in this pull request, if applicable.
  • I have tested the changes in the local development environment (see contributing.md).
  • I have added phpunit tests.

Release Changelog

  • Fix: N/A — internal refactor; no user-facing behavior change intended.
  • New: N/A.

Release Checklist

  • This pull request is to the master branch. (Stacked on ticket/XWPENG-50-list-table-split.)
  • Release version follows semantic versioning. Does it include breaking changes? (No release; refactor only.)
  • Update changelog in readme.txt.
  • Bump version in stream.php.
  • Bump Stable tag in readme.txt.
  • Bump version in classes/class-plugin.php.
  • Draft a release on GitHub.

…ors so field definitions and type rules can be unit-tested without booting WordPress.
@shadyvb shadyvb changed the title ticket/XWPENG 51 settings split Extract Settings schema, field HTML, and sanitization into collaborators. Sep 5, 2026
@shadyvb
shadyvb marked this pull request as ready for review September 6, 2026 20:27
Move the WP_Roles test stub into its own file to satisfy OneObjectStructurePerFile and apply PHPCBF alignment fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant