Skip to content

Monitor: Add a Monitor package and use it in the Jetpack plugin - #53691

Open
enejb wants to merge 5 commits into
trunkfrom
add/monitor-package
Open

enejb wants to merge 5 commits into
trunkfrom
add/monitor-package

Conversation

@enejb

@enejb enejb commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Fixes #

Proposed changes

Split out of #53685, the exploration that runs the shared Protect dashboard without the Jetpack plugin. This PR only adds the package and moves the Jetpack plugin onto it. Behaviour is unchanged, except for the two points under "Behaviour changes" below.

  • Add a new automattic/jetpack-monitor package with Automattic\Jetpack\Monitor\Monitor. It holds what modules/monitor.php did:
    • keeping each user's Downtime Monitor email choice in step with WordPress.com (jetpack.monitor.setNotifications / isUserInNotifications), with a local copy in monitor_receive_notifications<user_id>;
    • subscribing the user who turns the module on;
    • deleting the saved choice when a user unlinks or is deleted, or when the site disconnects;
    • fetching the last downtime.
  • Monitor::init() also adds monitor to jetpack_get_available_standalone_modules, so a plugin other than Jetpack (such as Protect, in Protect: Run the shared Protect dashboard without the Jetpack plugin #53685) can switch the module on.
  • Jetpack_Monitor in the Jetpack plugin becomes a shim: it calls Monitor::init() and every method forwards to the package, so existing callers (the REST settings endpoint, Abilities) keep working.
  • set_notifications() returns true|WP_Error instead of dying. The shim still wp_die()s where the module used to.
  • Add tests for the package.

Behaviour changes

  • Turning the module on no longer wp_die()s when WordPress.com rejects the subscription. The module turns on, no local copy is saved, and the next settings read asks WordPress.com.
  • The hooks are registered once, however many times Jetpack_Monitor is constructed. The REST endpoints construct it again, and on trunk each construction added a second set of callbacks.

Follow-up

  • Monitor_Abilities still makes its own setNotifications, isUserInNotifications and getLastDowntime calls. Moving it onto the package is left for a separate PR.

The mirror repo Automattic/jetpack-monitor is set up, with trunk holding only composer.json, the API_TOKEN_GITHUB secret for autotagger, and the Packagist package.

Related product discussion/links

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

No. The same XML-RPC calls and options are used as before.

Testing instructions

On a site running this branch of the Jetpack plugin, connected, with your user linked to WordPress.com:

  • Go to Jetpack › Settings › Security and turn on Downtime monitoring.
    • It turns on, and wp option get monitor_receive_notifications<your user id> returns 1.
  • Turn Get alerts if your site goes offline off and on again. Both saves succeed, and the option follows the toggle (0 / 1).
  • Reload the page. The toggle keeps its state.
  • Disconnect your user from WordPress.com (Jetpack › Dashboard › Connection), or disconnect the site.
    • monitor_receive_notifications<your user id> is deleted.
  • Check the PHP error log for errors mentioning Monitor.

@enejb enejb self-assigned this Oct 15, 2026
@github-actions github-actions Bot added [Package] Monitor [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests Docs labels Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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:

No scheduled milestone found for this plugin.

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

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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/monitor-package branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/monitor-package
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/monitor-package

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

@jp-launch-control

jp-launch-control Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/modules/monitor.php 8/21 (38.10%) -13.02% -9 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/monitor/src/class-monitor.php 20/33 (60.61%) 💚

Full summary · PHP report · JS report

@enejb
enejb marked this pull request as ready for review October 16, 2026 16:17

@kraftbj kraftbj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three small things inline.

Separately, nothing in the package checks that init() wires up the activation and unlink/disconnect hooks. The plugin's REST tests cover that through the shim today, but once Protect calls Monitor::init() directly (PR 53685), nothing will. Could the package get a test for that, plus one for activation still succeeding when WordPress.com rejects the subscription?

Comment thread projects/packages/monitor/tests/php/Monitor_Test.php Outdated
Comment thread projects/packages/monitor/README.md Outdated
Comment thread projects/packages/monitor/composer.json Outdated
@enejb

enejb commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Thanks! Added both in ccb2805:

  • test_init_wires_the_hooks checks that init() registers the standalone-module filter and the activation, unlink, user-delete and disconnect hooks.
  • test_activation_subscribes_the_user_without_failing_on_rejection fires jetpack_activate_module_monitor. When WordPress.com accepts, the choice is saved. When it rejects, activation still finishes and nothing is saved.

I mutation-checked both: dropping a hook from init(), failing activation on rejection, and skipping the subscription each fail exactly one test.

@enejb
enejb force-pushed the add/monitor-package branch from ccb2805 to f9a8e5c Compare October 20, 2026 00:00
enejb added 4 commits October 20, 2026 10:07
Move the monitor module's logic (per-user email alerts kept in step with
WordPress.com, and the cleanup on unlink, user deletion and disconnect) into
a new automattic/jetpack-monitor package, so plugins other than Jetpack can
offer Downtime Monitor. Jetpack_Monitor stays as a shim that forwards to it.
… leftovers

Test that init() wires its hooks and that activation subscribes the user
without failing when WordPress.com rejects it. Drop a standalone-module
assertion Modules::get_available() already guarantees, the empty README
headings, and the placeholder build scripts.
@enejb
enejb force-pushed the add/monitor-package branch from f9a8e5c to 1cac1f5 Compare October 20, 2026 17:09
@enejb enejb added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Oct 20, 2026
# Conflicts:
#	projects/plugins/jetpack/composer.lock

@kraftbj kraftbj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. One non-blocking note inline.

Comment on lines +70 to +71
// A failure doesn't block activation: with no local copy saved, the next settings read asks WordPress.com.
self::set_notifications( true );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking. This holds only when the user has no saved copy yet. Deactivating doesn't delete it, so if Monitor is turned off and back on while WordPress.com rejects the call, the user keeps whatever they had before, with no error. (Trunk leaves the same stale value, but at least the wp_die() surfaced it.) Deleting the copy on failure would make the comment true:

if ( is_wp_error( self::set_notifications( true ) ) ) {
	self::delete_notifications_copy( get_current_user_id() );
}

This branch has not been deployed

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

Labels

Docs [Package] Monitor [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants