Skip to content

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

Closed
TallblokeUK wants to merge 2 commits into
core-betafrom
fix/share-with-subsites/core
Closed

TallblokeUK wants to merge 2 commits into
core-betafrom
fix/share-with-subsites/core

Conversation

@TallblokeUK

Copy link
Copy Markdown
Contributor

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-beta without this change.
  • lint:php passes.

No changelog entry is included, as there is no open section after 4.0.0.

@TallblokeUK

Copy link
Copy Markdown
Contributor Author

Superseded by #598, which carries the same commits into core as a hotfix.

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