Skip to content

Post Notification Emails: handle Like clicks on WoW sites#48021

Merged
taipeicoder merged 7 commits intotrunkfrom
fix/dotcom-16569-email-like-atomic
Apr 10, 2026
Merged

Post Notification Emails: handle Like clicks on WoW sites#48021
taipeicoder merged 7 commits intotrunkfrom
fix/dotcom-16569-email-like-atomic

Conversation

@taipeicoder
Copy link
Copy Markdown
Contributor

@taipeicoder taipeicoder commented Apr 9, 2026

Fixes DOTCOM-16569

Proposed changes

  • Adds a new post-like-from-email feature in jetpack-mu-wpcom that hooks template_redirect at priority 1.
  • Detects email-like-button clicks (?like=1&postid=…&like_actor=…&like_hmac=…), then proxies them to the site-scoped wpcom/v2/sites/<blog_id>/email-like endpoint via Client::wpcom_json_api_request_as_blog() so the HMAC validation and Likes::set_post_like() happen on wpcom infrastructure.
  • The JSON body sends post_id (matching the wpcom endpoint's expected field name), like_actor, and like_hmac.
  • Always redirects the visitor to the post permalink afterwards (response body intentionally ignored).
  • Bails out on IS_WPCOM to avoid double-firing if jetpack-mu-wpcom is loaded inside wpcom.
  • Uses get_wpcom_blog_id() from utils.php to resolve the blog ID, matching the pattern used by replace-site-visibility.php.
  • Wires the new feature into Jetpack_Mu_Wpcom::load_features() (alphabetical, unconditional — the email recipient is anonymous, so the handler must run for visitors who are not logged into wpcom).

Related product discussion/links

  • Companion wpcom PR (endpoint): Automattic/wpcom#211090
  • Email template render PR (previously reverted, can be re-landed once this ships): Automattic/wpcom#210242

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

No. This PR only forwards an HMAC-signed (post_id, like_actor, like_hmac) triple to the wpcom endpoint — no new tracking, telemetry, or PII flow is introduced on the Jetpack side.

Testing instructions

Requires Automattic/wpcom#211090 to be deployed first (the wpcom/v2/sites/<blog_id>/email-like endpoint must exist).

  1. Deploy this branch to an Atomic/WoW staging site (ensure wpcom#211090 is also deployed).
  2. Add temporary error_log lines around the Client::wpcom_json_api_request_as_blog() call to see the wpcom response.
  3. Visit any post URL with ?like=1&postid=<post_id>&like_actor=<wpcom_user_id>&like_hmac=DEADBEEF appended.
  4. Expected: browser redirects to the post permalink; debug log shows HTTP 403 invalid_hmac (bad HMAC correctly rejected); no PHP errors.
  5. For a full positive-path test, generate a real HMAC via wpl_generate_like_hmac( $post_id, $user_id ) on a wpcom sandbox shell and substitute it into the URL — the like should be recorded.

Negative paths

  • Missing query params: handler bails on isset check — no wpcom call, page renders normally
  • On wpcom: handler's IS_WPCOM guard bails — the like is already handled on wpcom
  • Disconnected site (get_wpcom_blog_id() returns false): handler bails before making any call

Deploy order

  1. Automattic/wpcom#211090 (endpoint) — safe standalone, nothing calls it yet
  2. This PR (handler) — ships through normal Jetpack release train to Atomic
  3. Automattic/wpcom#210242 (email template render) — re-land once both above are deployed

)

Atomic/WoW sites do not include the Like button in post-notification
emails because the Simple-side `like-button.php` template_redirect handler
does not exist on Atomic. Adds a small jetpack-mu-wpcom feature that
proxies the email's like link to the new wpcom/v2/email-like endpoint
(Automattic/wpcom#211090) via Client::wpcom_json_api_request_as_blog(),
then redirects the visitor to the post permalink — restoring parity with
Simple sites and unblocking the re-landing of Automattic/wpcom#210242.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@taipeicoder taipeicoder added the [Status] Needs Review This PR is ready for review. label Apr 9, 2026
@taipeicoder taipeicoder self-assigned this Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 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 (WordPress.com Site Helper), and enable the fix/dotcom-16569-email-like-atomic branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/dotcom-16569-email-like-atomic

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 Apr 9, 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!

@taipeicoder taipeicoder marked this pull request as draft April 9, 2026 10:53
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control bot commented Apr 9, 2026

Code Coverage Summary

No summary data is available for parent commit cfe2e49, so cannot calculate coverage changes. 😴

If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for cfe2e49 is available.

Full summary · PHP report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

The wpcom/v2/email-like endpoint from Automattic/wpcom#211090 is
site-specific (wpcom_is_site_specific_endpoint = true) and expects
post_id (not postid) in the body. Resolve the blog id from
Jetpack_Options and prefix the request path with /sites/<blog_id>/,
matching the pattern used by class-wpcom-rest-api-v2-endpoint-jetpack-launch-site.php:60.

Without this, calls returned rest_no_route (verified on taipeiwoadev).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
taipeicoder and others added 2 commits April 10, 2026 10:00
Switch from Jetpack_Options::get_option( 'id' ) to the package's own
get_wpcom_blog_id() helper in utils.php. Matches the idiom used by
replace-site-visibility.php:244 and also avoids a hard dependency on
the Jetpack class being loaded (the helper reads jetpack_options
directly via get_option()).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… call

Verifies that wpcom_handle_post_like_from_email() POSTs to the site-scoped
/wpcom/v2/sites/<blog_id>/email-like endpoint with post_id/like_actor/
like_hmac in the body and redirects the visitor to the post permalink.
Regression guard for the path and body-shape drift we hit against
Automattic/wpcom#211090 during iteration.

Uses #[RunInSeparateProcess] to define IS_ATOMIC so get_wpcom_blog_id()
returns a test blog id, mocks the HTTP call via pre_http_request, and
throws from a wp_redirect filter to escape the handler before its exit;
runs. The redirect-escape exception lives in its own file to satisfy
Generic.Files.OneObjectStructurePerFile.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Jetpack Connection mocking required for
Client::wpcom_json_api_request_as_blog is too complex for the value
it provides. The handler has been verified manually against a staging
site with wpcom#211090 deployed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@taipeicoder taipeicoder added I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. and removed [Status] In Progress [Tests] Includes Tests labels Apr 10, 2026
@taipeicoder taipeicoder marked this pull request as ready for review April 10, 2026 04:39
taipeicoder and others added 2 commits April 10, 2026 12:46
Blog IDs are always integers — no characters to encode. Matches the
pattern used by wpcom-dashboard-widgets.php and avoids PhanTypeMismatchArgumentInternal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…on.php

These are wpcom internals that don't need to be documented in the
jetpack-mu-wpcom handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@taipeicoder taipeicoder changed the title Post Notification Emails: handle Like clicks on Atomic/WoW (DOTCOM-16569) Post Notification Emails: handle Like clicks on Atomic/WoW Apr 10, 2026
@taipeicoder taipeicoder changed the title Post Notification Emails: handle Like clicks on Atomic/WoW Post Notification Emails: handle Like clicks on WoW sites Apr 10, 2026
@taipeicoder taipeicoder merged commit 3cdfda3 into trunk Apr 10, 2026
69 of 70 checks passed
@taipeicoder taipeicoder deleted the fix/dotcom-16569-email-like-atomic branch April 10, 2026 05:11
@github-actions github-actions bot removed [Status] In Progress [Status] Needs Review This PR is ready for review. labels Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [mu wpcom Feature] Post Like From Email [Package] Jetpack mu wpcom WordPress.com Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant