Usage of `switch_to_site()` prevents plugins/themes active only on the receiving multisite instance from running
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Read includes/classes/InternalConnections/NetworkSiteConnection.php and trace the switch_to_blog() usage linked in the issue; compare that path with the external HTTP connection flow. The issue outlines two possible directions, but leaves the design decision open. Done means receiving site plugins run reliably when content is pulled, with tests covering the selected approach.
Written by the indexing model from the issue text.
Description
Describe the bug
This plugin uses WordPress' switch_to_blog() extensively: https://github.com/search?q=repo%3A10up%2Fdistributor+switch_to_blog&type=code
The problem is documented in switch_to_blog()'s own docs:
PHP code loaded with the originally requested site, such as code from a plugin or theme, does not switch. See #14941.
This means that plugins active only on the receiving site, such as 10up's Distributor Edit Remote Post Meta, don't function reliably in multisite networks.
There are a couple ways forward:
- Deprecate
switch_to_blog()functionality and the NetworkSiteConnection class: all pushes will be treated as external connections and mediated via HTTP, which ensures that the receiving site’s plugins will be loaded by the receiving site.- Optionally, remove code checking
is_multisite(), which is sometimes used by receiving network sites to get data directly from the origin network site's DB instead of making queries. Getting rid of this will reduce code complexity. - Testing complexity decreases somewhat, as removal of the multisite-specific behavior means that it will no longer be necessary to have two separate WordPress installs to run tests. If network sites are handled the same way as external sites, than a single multisite suffices for running tests.
- Optionally, remove code checking
- Update Distributor documentation to require code parity between the sending site and the receiving site
I don’t recommend option #2 because it’s a logistical problem for Distributor networks that don’t share codebases. The only places where Distributor would be guaranteed to function 100% reliably would be a multisite network, or sites with 1 shared repo for multiple sites. (example: @benlk's longest project)
Steps to Reproduce
This isn't something that's currently reproducible in Distributor, but it's a bug which will arise with the implementation of https://github.com/10up/distributor/pull/1417 to enable fixes for the bug that https://github.com/10up/distributor-edit-remote-post-meta/pull/19 tries to fix.
https://github.com/10up/distributor-edit-remote-post-meta/pull/19 points out that, with that PR's changes, that plugin must be active on both the sending and receiving site in order for that plugin to function as intended.
The reproduction case would look something like this:
- Create a multisite network and enable Distributor on the network
- On one receiving site, activate a plugin which modifies the received Distributor payload, such as by replacing all images in the post with an image of a kitten, or by ignoring Distributor's pushed updates to terms and post meta
- Publish a post on the origin site
- Pull a post to the receiving site
- Make an update to the post on the origin site:
- Expect that the receiving site's plugin functions as intended -> It doesn't. The images aren't replaced with kittens; the post meta and post terms are overwritten.
Screenshots, screen recording, code snippet
No response
Environment information
n/a
WordPress information
All.
Code of Conduct
- I agree to follow this project's Code of Conduct
- Dominant language
- PHP
- Stars
- 715
- Forks
- 160
- Avg merge
- 6h 10m
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 10up/distributor
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
10up/distributor#1373 ·
Maintainers usually reply within 1 day
-
Distributor 2.3.2 does not create parent-child relationships for terms when creating termsPossibly taken @boonstraworks claimed this 33 days ago. Opentype:bug
Difficulty 3/5 1-2 days Newbie friendliness 66/100
10up/distributor#1410 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
Distributor disables Block Editor Preferences pane; blocks closing the Preferences panePossibly taken @boonstraworks claimed this 33 days ago. Opentype:bug
Difficulty 3/5 1-2 days Newbie friendliness 56/100
10up/distributor#1409 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
help wanted
Difficulty 4/5 3-5 days Newbie friendliness 48/100
10up/distributor#1400 ·
Maintainers usually reply within 1 day
-
type:enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
10up/distributor#1376 ·
Maintainers usually reply within 1 day
All issues in 10up/distributor
Similar issues
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
10up/autoshare-for-twitter#438 ·
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
10up/Ad-Refresh-Control#240 ·
-
wpvc
Difficulty 1/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Backend bug severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
RunningJoke/allipunkte#74 ·