Skip to content

fix: apply the share with subsites setting when a network snippet is saved - #598

Merged
lightbulbman merged 2 commits into
core-betafrom
hotfix/share-with-subsites/core
Oct 19, 2026
Merged

lightbulbman merged 2 commits into
core-betafrom
hotfix/share-with-subsites/core

Conversation

@TallblokeUK

Copy link
Copy Markdown
Contributor

Replaces #590, which targeted core-beta. The same two commits, based on core, as the fault is in the released 4.0.0.

On multisite, the "share with subsites" setting on a network snippet was never applied. save_snippet() reads the snippet back from the database and uses that copy from then on, but whether a snippet is shared is not a column: it is derived from the list of shared IDs, so the copy carried the old setting and the requested one was discarded. Sharing could not be switched on for a new or an existing snippet, nor switched off.

Reported, with the cause and a suggested fix, at https://wordpress.org/support/topic/thanks-to-claude-this-plugin-finally-works-bugfix-for-you/

Changes

  • The requested setting is carried onto the snippet read back, before the save hooks fire, so the hooks, the returned snippet and the shared list all agree.
  • The shared list holds each ID once. It was appended to on every save of a shared snippet.
  • Switching sharing off now reaches the loop that deactivates the snippet on each subsite, which the first bug had kept unreachable. That loop switched to every site and restored once, leaving the rest of the request on another site, and only covered the first hundred sites. Each switch is now undone in turn and every site is covered.

Verification

  • New tests cover switching sharing on and off for new and existing snippets, a save that does not mention sharing, what the save hooks receive, repeated saves, an already duplicated list, deactivation on subsites, and the site the request ends on. They need a multisite install, so they skip on a single-site run, as the existing network tests do.
  • Run with WP_TESTS_MULTISITE=1: all ten pass, and seven fail without the change. With only the first two changes, the test for the site the request ends on fails (site 4 rather than site 1).
  • Full suite passes on a single site. On multisite it has one failure, Uninstaller_Test::test_complete_uninstall_removes_stats_chart_view_preferences, which fails the same way on core without this change.
  • lint:php passes.

@TallblokeUK TallblokeUK added the run-tests Trigger automated tests label Oct 13, 2026
@lightbulbman
lightbulbman changed the base branch from core to core-beta October 19, 2026 13:29
@lightbulbman
lightbulbman merged commit 9ae281e into core-beta Oct 19, 2026
32 of 35 checks passed
@lightbulbman
lightbulbman deleted the hotfix/share-with-subsites/core branch October 19, 2026 13: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.

2 participants