Skip to content

Plugin Conflicts Guardian: migrate from jetpack-mu-wpcom to the Jetpack plugin#49048

Open
arthur791004 wants to merge 6 commits into
trunkfrom
add/pcg-migrate-to-jetpack-plugin
Open

Plugin Conflicts Guardian: migrate from jetpack-mu-wpcom to the Jetpack plugin#49048
arthur791004 wants to merge 6 commits into
trunkfrom
add/pcg-migrate-to-jetpack-plugin

Conversation

@arthur791004
Copy link
Copy Markdown
Contributor

Proposed changes

Migrates Plugin Conflicts Guardian (PCG) out of the jetpack-mu-wpcom package (which only ships to WordPress.com Atomic sites) and into the Jetpack plugin, so self-hosted Jetpack installs get the same conflict protection.

  • Source files relocated to projects/plugins/jetpack/modules/plugin-conflicts-guardian/. It lives under modules/ but is not a registered toggleable module (no Module Name: header) — same pattern as modules/seo-tools/ and modules/shortcodes/.
  • Loaded unconditionally from load-jetpack.php. PCG is a site-safety net, so it deliberately does not go through the standard module loader: that loader runs at after_setup_theme:-2 and is connection-gated, which would leave disconnected sites (the most fragile moment) unprotected and would load the probe too late.
  • probe-endpoint.php now hooks plugins_loaded at PHP_INT_MIN instead of running inline at require time. Forced by the new (pre-plugins_loaded) load point — and it closes the early-priority plugins_loaded callback gap the old mu-wpcom load point (load_features() priority 10) left open.
  • pcg-log.php rewritten for the Jetpack plugin: a Jetpack Tracks event when the site has a working connection, Jetpack_Mu_Wpcom::log2logstash() when that helper is present (Atomic), and an error_log fallback otherwise.
  • @package headers, jetpack text domain, and admin-notice copy ("WordPress.com blocked…" → "Jetpack blocked…") updated for the plugin context.
  • Removed from jetpack-mu-wpcom. PCG never shipped in a released version of the package, so its 11 unreleased PCG changelog entries are dropped. Jetpack_Mu_Wpcom::log2logstash() stays as a general-purpose logging helper.

Related product discussion/links

  • (add P2/Linear links)

Does this pull request change what data or activity we track or use?

Yes — PCG's events (Activation blocked, Update blocked, Update rolled back, Probe transport error) are now also emitted as Jetpack Tracks events (jetpack_pcg_*) on connected sites, in addition to the existing Atomic logstash bucket. No new personal data is collected; events carry plugin basenames and probe verdicts only (install-path prefixes are redacted).

Testing instructions

  • On a self-hosted Jetpack site, install a plugin whose main file triggers a PHP fatal on load, then click Activate — activation should be blocked with an admin notice naming the plugin, and the site should stay up.
  • Activate a healthy plugin — it should activate normally.
  • Trigger a plugin update that fatals post-install — PCG should roll it back to the previous version and surface a notice.
  • Confirm both work on a Jetpack site that is not connected to WordPress.com (the key behavior change vs. a normal module).
  • phpcs and changelogger validate pass for both jetpack and jetpack-mu-wpcom.

🤖 Generated with Claude Code

…ck plugin

Moves PCG out of the jetpack-mu-wpcom package (Atomic-only) into the Jetpack
plugin so self-hosted Jetpack sites get conflict protection too.

- Source files relocated to projects/plugins/jetpack/modules/plugin-conflicts-guardian/,
  loaded unconditionally from load-jetpack.php — not connection-gated, and not
  registered as a toggleable module (PCG is a safety net, not a user feature).
- probe-endpoint.php now hooks plugins_loaded at PHP_INT_MIN instead of running
  inline at require time; the new load point also closes the early-priority
  plugins_loaded callback gap the mu-wpcom load point left open.
- pcg-log.php rewritten for the Jetpack plugin: a Jetpack Tracks event when
  connected, Jetpack_Mu_Wpcom::log2logstash() when available (Atomic), and an
  error_log fallback otherwise.
- Text domain, @Package headers and admin-notice copy updated for the Jetpack
  plugin context.
- Removed from jetpack-mu-wpcom. PCG never shipped in a released version of the
  package, so its 11 unreleased PCG changelog entries are dropped; log2logstash()
  stays as a general-purpose helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the add/pcg-migrate-to-jetpack-plugin branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/pcg-migrate-to-jetpack-plugin
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/pcg-migrate-to-jetpack-plugin

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: June 2, 2026
    • Code freeze: June 1, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 21, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 21, 2026

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php 2/413 (0.48%) -6.52% 26 💔
projects/plugins/jetpack/load-jetpack.php 0/46 (0.00%) 0.00% 1 ❤️‍🩹

9 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/plugins/jetpack/modules/plugin-conflicts-guardian/plugin-conflicts-guardian.php 0/8 (0.00%) 💔
projects/plugins/jetpack/modules/plugin-conflicts-guardian/probe-endpoint.php 0/94 (0.00%) 💔
projects/plugins/jetpack/modules/plugin-conflicts-guardian/class-pcg-rollback.php 9/131 (6.87%) 💔
projects/plugins/jetpack/modules/plugin-conflicts-guardian/pcg-log.php 3/29 (10.34%) 💔
projects/plugins/jetpack/modules/plugin-conflicts-guardian/class-pcg-load-tester.php 18/171 (10.53%) 💔

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

…ibility

The Jetpack plugin supports PHP 7.2 (mu-wpcom required 7.4+), so the
`static fn () =>` arrow functions PCG carried over fail the parallel-lint
check. Convert all 7 to regular `static function () { return …; }`
closures — none captured outer scope, so no `use` clauses are needed.
A token scan confirms no trailing commas in function calls (PHP 7.3+)
remain either.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@simison
Copy link
Copy Markdown
Member

simison commented May 21, 2026

A couple of questions:

  • Is this force-enabled for everyone installing Jetpack? I think it would be better to have as a feature one that can enable/disable; it fits better with Jetpack's model.
  • Should this be part of one of the existing products, like Protect or Backup?
  • Have you considered whether this mechanism should be built into WordPress core?

The arrow-function replacements landed as single-line closures, which
trip Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace
(the opening brace must be the last content on its line). Pure
`(string)` casts inside array_map() become the `'strval'` callback;
the remaining filter/sanitize closures are expanded to multi-line form.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@arthur791004
Copy link
Copy Markdown
Contributor Author

Thanks @simison — good questions.

Force-enabled, or a toggleable feature?

Today it's behind two filters — pcg_guard_activation (activation probe + parse-error gate) and pcg_guard_updates (post-update healthcheck + rollback), both defaulting to true — so it's overridable in code, but there's no user-facing switch.

My first instinct was a normal module: on by default, user can turn it off. But the module system doesn't fit PCG:

  • Jetpack::load_modules() runs on after_setup_theme:-2, after plugins_loaded has finished. PCG's probe has to require the plugin-under-test during plugins_loaded so the plugin's own plugins_loaded callbacks still fire — as a module it would load too late.
  • load_modules() also bails when the site isn't connected. A fresh, unconnected install is exactly when a careless activation is most likely to take a site down, so gating the safety net on connection state is backwards.

So if we want a user-facing toggle, it'd have to be a Jetpack Settings option, separate from the module system.

But before adding one, I think the real question is: why would a user turn this off? It's a safety net — there's no plan or feature value in disabling it. The one scenario where an off switch genuinely matters is a false positive — PCG wrongly blocking a healthy plugin. PCG already works hard to avoid that (cache-intercepted, redirected, and otherwise inconclusive probes resolve as non-blocking, not as fatals), so a true false-block should be rare. And if one does happen, the better fix is probably to harden the probe, not to ship a switch that — for everyone who tripped it for a real reason — quietly turns the protection off.

So right now I'm leaning toward no UI toggle, with the filters as the escape hatch for the rare edge case. Happy to be talked out of that if there's a concrete user-facing reason I'm missing.

Part of Protect or Backup?

Honestly, I hadn't considered that — I'm not that familiar with the Jetpack product lineup, so this is useful to hear. Conceptually it does overlap both — Protect (prevents a class of site-down events) and Backup (local snapshot + rollback). One thing to weigh: PCG is plan- and connection-independent infrastructure, whereas the Protect/Backup modules are connection- and plan-gated. Which product should own it is worth a conversation with those teams — and where it lives in the tree doesn't have to match which product owns it.

WordPress core?

Core already has adjacent pieces — fatal-error protection / recovery mode (5.2) and rollback for failed plugin auto-updates (6.3). What core doesn't have is the pre-flight check: probing an activation/update in an isolated request and refusing it before the live site is affected, instead of recovering after. I'd suggest letting it prove out on Jetpack first — once it's stable here and we've gathered real-world data, moving it (or proposing it) to core would be a reasonable next step to consider.

The test was converted from WorDBless's BaseTestCase to WP_UnitTestCase
during the migration, but missed `use \Automattic\Jetpack\PHPUnit\WP_UnitTestCase_Fix`.
Without it, WP's test framework calls the PHPUnit\Util\Test::parseTestMethodAnnotations()
method that PHPUnit 10+ removed, erroring every test method. The trait
(loaded by tests/php/bootstrap.php, used by ~160 other Jetpack tests)
supplies a PHPUnit 10/11/12-compatible getAnnotations() implementation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@simison
Copy link
Copy Markdown
Member

simison commented May 21, 2026

But before adding one, I think the real question is: why would a user turn this off?

Just if the user doesn't want the feature; perhaps they wanted Jetpack for some other features. :-) There could be some technical "world of hosting sites is messy" reasons too, but I was mostly thinking marketing & perception angles of Jetpack. They might also have some alternative existing solutions for this problem that Jetpack might now compete with/take over.

Is there any user-facing indication or marketing that the feature exists, or it is "hidden until triggered"?

arthur791004 and others added 2 commits May 21, 2026 22:32
…f test output

`test_update_guard_check_blocks_plugin_with_parse_error` exercises a real
block, so `pcg_log_event()` reaches its `error_log()` fallback (no Tracks
connection, no mu-wpcom logstash in the Jetpack plugin test env). PHPUnit's
strict-output check then flags the test as risky.

Point the `error_log` ini at a scratch file in `set_up()` and restore it in
`tear_down()`, so the fallback writes there instead of into PHPUnit's
captured output. Production behaviour is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ng in tests

Pointing the `error_log` ini at a scratch file didn't keep PCG's logging
fallback out of PHPUnit's captured output. Gate `pcg_log_event()` behind a
new `pcg_log_enabled` filter instead — a legitimate hook for sites that
don't want PCG telemetry — and have the test disable it in set_up(). With
the dispatch short-circuited there's no error_log() call at all, so the
strict-output check has nothing to flag, independent of how error_log is
routed. Replaces the ineffective ini_set() approach.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@arthur791004 arthur791004 added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label May 21, 2026
@arthur791004
Copy link
Copy Markdown
Contributor Author

Is there any user-facing indication or marketing that the feature exists, or is it "hidden until triggered"?

Hidden until triggered — no Settings entry, no badge, no marketing. It only surfaces when it acts: an admin notice on a blocked activation or a rolled-back update. We can loop in the Jetpack team to do some marketing around it if that's worth pursuing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR Docs [Feature] Plugin Conflicts Guardian [mu wpcom Feature] Plugin Conflicts Guardian [Package] Jetpack mu wpcom WordPress.com Features [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants