Skip to content

refactor: resolve the version switcher source and installer through filters - #568

Merged
lightbulbman merged 28 commits into
core-betafrom
refactor/version-switcher-seams/core
Oct 19, 2026
Merged

lightbulbman merged 28 commits into
core-betafrom
refactor/version-switcher-seams/core

Conversation

@lightbulbman

@lightbulbman lightbulbman commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Moves the two parts of the version switcher that an implementation may need to vary — where the list of available versions comes from, and how a package is written to disk — behind interfaces resolved through filters. Caching, the in-progress marker, capability and nonce checks, validation and rendering remain in Version_Switch.

Changes

  • Adds Version_Source and Package_Installer interfaces, with WordPress_Org_Version_Source and Upgrader_Package_Installer as the defaults. No registration is required; the defaults apply unless the code_snippets_version_source or code_snippets_package_installer filters supply a replacement.
  • Rewrites Version_Switch to resolve both services through those filters each time they are used, cache the catalogue under the source's own get_cache_key(), record the reason a catalogue request failed, and render the available, unavailable and in-progress states.
  • Labels each version in the dropdown as the current, latest, beta or release candidate build, and with the WordPress version it was tested up to, where the source supplies that data.
  • Adds a second line to the version switching warning noting that beta and release candidate builds are not recommended for production sites.
  • Deletes the cached version catalogue on upgrade to 4.0.0, so a site whose source has changed does not keep serving the previous list.
  • Changes the Reset Caches action to refetch the catalogue rather than only discard it, and to report the number of versions found, or why none could be listed when the source is unavailable or its request failed.
  • Returns an error from the Refresh Available Versions request when the source is unavailable or its request failed.
  • Removes the version switcher's transients on complete uninstall, including the WordPress.org catalogue when another source is active.
  • Writes a failed install to the PHP error log with the target version, error code and messages.
  • Returns instead of throwing in initVersionSwitch() when the switcher configuration is absent, so the unavailable state renders as a notice with no controls.
  • Stores the message of a failed catalogue request alongside its error code, and adds get_last_error_message().
  • Gives an empty catalogue its own state in the switcher field: the stored failure message where a request failed, and an explicit line stating that no versions are available to install where the source returned an empty list. Neither renders a disabled dropdown or switch button; the Refresh Available Versions button continues to render in both. The current version is still shown.
  • Renders the version floor notice only where the source reports a floor.
  • Records a failed package request the same way as a failed catalogue request, so a source that bases its availability on the last error code sees refusals from either.
  • Hides the Refresh Available Versions row while the source reports itself unavailable, through the code_snippets_settings_tab_contents filter.
  • Adds Version_Source::get_switch_warning(), for a source to attach a warning to an individual version. The warning is rendered as a data-warning attribute on the version's option and shown inside the switch warning when that version is selected. WordPress_Org_Version_Source returns no warning.
  • Renders the version switch warning inside the switcher field, above the Switch Version button, with the inline class so WordPress does not move it to the top of the screen. Removes the separate version_warning settings field and the tab-change handler that hid the relocated notice.
  • Gives the version switch warning a yellow background through a new --cs-color-surface-warning theme token, with body-coloured text for contrast.
  • Shows the Refreshing label on the Refresh Available Versions button while a refresh is in progress.
  • Renders the version switch result messages as text, and keeps the code-snippets-notice class on them so the admin notice filter does not hide them.
  • Merges core-beta. The changelog is taken from core-beta unchanged, as the 4.0.0 section it previously extended has been released; entries for this change belong in the next release section.

Verification

npm run test:php     OK (470 tests, 1158 assertions, 36 skipped)
npm run lint:php     clean
eslint src/js/services/settings tests/e2e/version-switch.spec.ts      clean
stylelint src/css/settings.scss src/css/common/_theme.scss  clean
playwright tests/e2e/version-switch.spec.ts tests/e2e/settings-tabs.spec.ts   6 passed

tests/unit/Settings/Version_Switch_Test.php adds 35 tests covering the cache key, uncached source errors, target validation, the install and cleanup paths on both success and failure, logging of a failed install, the filters replacing and restoring both services, a source registered after the first lookup, clearing the WordPress.org catalogue, the Reset Caches notices, and the markup rendered for a failed request, an empty catalogue, a populated catalogue, the floor notice, per-version warnings, the placement of the switch warning, and the refresh button while the source is unavailable. tests/unit/Settings/Version_Switch_Ajax_Test.php covers the refresh request's success and error responses. tests/unit/Core/Uninstaller_Test.php covers the transient removal. tests/e2e/version-switch.spec.ts covers a switch response containing markup being shown as text.

lightbulbman and others added 28 commits September 22, 2026 19:17
…-switcher-seams/core

# Conflicts:
#	src/php/Core/Uninstaller.php
#	src/php/Settings/Version_Switch.php
@lightbulbman
lightbulbman marked this pull request as ready for review October 19, 2026 14:31
@lightbulbman lightbulbman added the run-tests Trigger automated tests label Oct 19, 2026
@lightbulbman
lightbulbman merged commit d22d29e into core-beta Oct 19, 2026
23 of 26 checks passed
@lightbulbman
lightbulbman deleted the refactor/version-switcher-seams/core branch October 19, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant