Skip to content

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

Draft
lightbulbman wants to merge 11 commits into
core-betafrom
refactor/version-switcher-seams/core
Draft

lightbulbman wants to merge 11 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, 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.
  • Removes the version switcher's transients on complete uninstall.
  • 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(). get_last_error_code() still reads the previous transient shape, which a site holds until it expires.
  • 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.

Verification

npm run test:php     OK (373 tests, 880 assertions, 25 skipped)
npm run lint:php     clean
npm run lint:js      clean
npm run lint:styles  clean

tests/unit/Settings/Version_Switch_Test.php adds 28 tests covering the cache key, uncached source errors, target validation, the install and cleanup paths on both success and failure, the filters replacing and restoring both services, and the markup rendered for a failed request, an empty catalogue, a populated catalogue and the floor notice. tests/unit/Core/Uninstaller_Test.php covers the transient removal.

🤖 Generated with Claude Code

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