Skip to content

wpcomsh: Add unauthenticated REST endpoint for Gutenberg version#48147

Open
markbiek wants to merge 7 commits intotrunkfrom
add/wpcomsh-gutenberg-version-endpoint
Open

wpcomsh: Add unauthenticated REST endpoint for Gutenberg version#48147
markbiek wants to merge 7 commits intotrunkfrom
add/wpcomsh-gutenberg-version-endpoint

Conversation

@markbiek
Copy link
Copy Markdown
Contributor

@markbiek markbiek commented Apr 17, 2026

Proposed changes

Adds GET /wpcomsh/v1/gutenberg-version, a minimal endpoint that reports the active Gutenberg plugin version on sites where it's explicitly enabled. This will be used by the gbstatus script that's still in development.

  • Response shape: { "version": "<GUTENBERG_VERSION>" }, or { "version": null } when the plugin isn't active
  • Auth: none — access is gated by the wpcomsh_expose_gutenberg_version WP option. Sites where this option is not truthy return 401. Enable per site via WP-CLI.
  • The endpoint sends Cache-Control: no-cache, no-store, must-revalidate, max-age=0 on both success and error responses so the option state is respected promptly. The WoA edge cache may still serve a stale response for a brief window; callers should include a cache-buster query param (e.g. ?cb=<timestamp>) to be safe.

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

No

Testing instructions

  1. Install this branch on a WoA test site (see comment below for Jetpack Beta Tester steps; you'll need define( 'JETPACK_AUTOLOAD_DEV', true ); in wp-config.php on WoA). All subsequent curl examples use a timestamp query param to sidestep the WoA edge cache.

  2. With no option set, confirm the endpoint returns 401:

    curl -i "https://YOUR-SITE/wp-json/wpcomsh/v1/gutenberg-version?cb=$(date +%s)"
    
  3. Enable the option on the site by ssh'ing into the site and running:

    wp option update wpcomsh_expose_gutenberg_version 1
    

    Confirm the endpoint now returns { "version": "<some version>" } (or { "version": null } if Gutenberg isn't active):

    curl -i "https://YOUR-SITE/wp-json/wpcomsh/v1/gutenberg-version?cb=$(date +%s)"
    
  4. Delete the option and confirm the endpoint returns 401 again:

    wp option delete wpcomsh_expose_gutenberg_version
    curl -i "https://YOUR-SITE/wp-json/wpcomsh/v1/gutenberg-version?cb=$(date +%s)"
    

Co-Authored-By: Claude noreply@anthropic.com

Introduce `GET /wpcomsh/v1/gutenberg-version`, gated by the
`gutenberg-version-endpoint` site sticker via
`wpcomsh_is_site_sticker_active()` so only designated test sites
expose it. Returns `{ "version": "<GUTENBERG_VERSION>" }` or
`{ "version": null }` when the plugin isn't active.

Used by the team `gbstatus` tool to report Gutenberg versions across
Atomic edge and production without requiring per-site application
passwords.

Co-Authored-By: Claude <noreply@anthropic.com>
@markbiek markbiek self-assigned this Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 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 add/wpcomsh-gutenberg-version-endpoint branch.

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 17, 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!


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

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 Apr 17, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control bot commented Apr 17, 2026

Code Coverage Summary

Coverage changed in 11 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/plugins/wpcomsh/i18n.php 35/75 (46.67%) 2.67% -2 💚
projects/plugins/wpcomsh/wpcom-features/functions-wpcom-features.php 32/179 (17.88%) 3.35% -6 💚
projects/plugins/wpcomsh/endpoints/rest-api.php 10/18 (55.56%) 55.56% -8 💚
projects/plugins/wpcomsh/endpoints/class-rest-api-code-deployment-logs-controller.php 9/20 (45.00%) 45.00% -9 💚
projects/plugins/wpcomsh/endpoints/rest-api-export.php 11/100 (11.00%) 11.00% -11 💚

1 file is newly checked for coverage.

File Coverage
projects/plugins/wpcomsh/endpoints/rest-api-gutenberg-version.php 23/23 (100.00%) 💚

Full summary · PHP report

Cover route registration, response shape, and permission callback
behavior (with and without the `gutenberg-version-endpoint` sticker)
using the existing `Atomic_Persistent_Data` test mock.

Co-Authored-By: Claude <noreply@anthropic.com>
markbiek and others added 4 commits April 17, 2026 13:00
The permission callback tests use the `Atomic_Persistent_Data` mock's
`set()`/`delete()` methods, which don't exist on the real class that
runs under the `wpcloud` testsuite. Exclude the test from `wpcloud`
and add it to `other`, matching the existing pattern used by
FrontendNoticesTest, WpcomFeaturesTest, etc.

Co-Authored-By: Claude <noreply@anthropic.com>
…point tests

Phan analyzes against the production `Atomic_Persistent_Data` class,
which lacks the `set()`/`delete()` methods that only exist on the test
mock. Match the existing suppression pattern used for FrontendNoticesTest,
PlanNoticesTest, WpcomFeaturesTest, and FeatureHookTest.

Co-Authored-By: Claude <noreply@anthropic.com>
…f a blog sticker

Blog stickers require an allowlist entry in wpcom's `atomic_site_stickers()`
before they propagate to `Atomic_Persistent_Data` on the Atomic side, which
makes enabling the endpoint a cross-repo operation. A WP option set via
WP-CLI on each designated site is a simpler, self-contained toggle and
removes the need for the test mock, so the tests can now run in the
wpcloud testsuite and the phan suppression is no longer needed.

Co-Authored-By: Claude <noreply@anthropic.com>
The WoA edge cache was serving stale 401/200 responses after the
`wpcomsh_expose_gutenberg_version` option was toggled, because
unauthenticated REST responses don't get `Cache-Control: no-cache` by
default. Filter `rest_post_dispatch` to attach no-cache headers to
responses for this route (covers both the 200 success path and the 401
permission-denied path).

Co-Authored-By: Claude <noreply@anthropic.com>
@markbiek markbiek added the [Status] Needs Review This PR is ready for review. label Apr 17, 2026
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Apr 17, 2026
@markbiek markbiek requested a review from paulopmt1 April 17, 2026 20:00
@markbiek markbiek added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Apr 17, 2026
paulopmt1
paulopmt1 previously approved these changes Apr 17, 2026
Copy link
Copy Markdown
Contributor

@paulopmt1 paulopmt1 left a comment

Choose a reason for hiding this comment

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

It's working as expected @markbiek. Thanks for thinking of ways to improve the Gutenberg deployment process!

Just to confirm that we want this only on Atomic sites, otherwise, if we want it also on simple sites, the jetpack-mu-plugin would be the place for this.

  1. 401 as expected before setting the flag:
    image

  2. Active plugin return:

    image
  3. No Gutenberg plugin active (though the site actually has the default Gutenberg on it by default):

    image
  4. After deletion, I got 401 again, as expected.

Comment thread projects/plugins/wpcomsh/changelog/add-gutenberg-version-endpoint Outdated
)
);

add_filter( 'rest_post_dispatch', 'wpcomsh_rest_api_gutenberg_version_nocache', 10, 3 );
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.

Can you check if this feedback makes a difference here?

The rest_post_dispatch filter runs for every REST response site-wide, just to do a single string comparison on routes that don't match. Negligible cost, but scoping is slightly noisier than needed.

Alternative: register the filter from inside the route callback, or use rest_pre_serve_request / a route-specific hook.

Co-authored-by: Paulo Marcos Trentin <paulo@paulotrentin.com.br>
@markbiek
Copy link
Copy Markdown
Contributor Author

Just to confirm that we want this only on Atomic sites

That's correct! We can get the Gutenberg version information for Simple sites from a different source.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants