Skip to content

Random Redirect: Defer to core's random content redirects on WordPress 7.2 - #54665

Open
kraftbj wants to merge 3 commits into
trunkfrom
update/random-redirect-defer-to-core
Open

kraftbj wants to merge 3 commits into
trunkfrom
update/random-redirect-defer-to-core

Conversation

@kraftbj

@kraftbj kraftbj commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes N/A

Proposed changes

WordPress 7.2 adds random content redirects to core (757cb9c): /random/, /random/category/news/ and friends, plus ?random on any archive or search URL. Core resolves those in WP::main(), before template_redirect, so on 7.2 it already wins every archive request and Jetpack's Random Redirect only fires on whatever core skips.

  • Stop loading modules/theme-tools/random-redirect.php when the site runs WordPress 7.2-beta or newer. The feature landed during 7.2 alpha, so every beta has it.
  • Do the same for the WordPress.com Simple copy in jetpack-mu-wpcom (features/random-redirect/), gated in Jetpack_Mu_Wpcom::load_wpcom_random_redirect().
  • Mark jetpack_matt_random_redirect() deprecated in its docblock. No runtime _deprecated_function() notice: it's a template_redirect callback that still runs on every request on older WordPress, where it's the only implementation.

What sites on 7.2+ lose

Deferring to core drops a few things the Jetpack version supported:

Jetpack Random Redirect Core (7.2)
?random_post_type=page (or any post type) Ignored. Core picks from post types registered as randomable, which is only post by default.
?random_cat_id=N Ignored. Use the category archive instead (/random/category/news/ or /category/news/?random).
?random on a single post or page URL Not handled; the page renders normally.
/&random, /&random=1 Not handled.
jetpack_random_redirect_enabled filter No effect. Core's switch is wp_enable_random_content_redirect.

The post type option is the real loss. That said, deferring to core is the more sustainable option: core's version comes with rewrite rules, term, author and post type archives, noindex headers and an opt-out filter, and it's maintained where the routing lives. Keeping a second implementation that core pre-empts on most requests anyway would mean shipping behavior that differs depending on which URL a visitor happens to hit.

On the function no longer existing on 7.2+: it was removed entirely between 13.6 and 16.1, and themes that depended on it started shipping their own copy (which the existing function_exists() guard respects). So I didn't add a stub.

Related product discussion/links

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

No.

Testing instructions

You need two sites: one on WordPress 7.2 (nightly) and one on 7.1, both running this branch with a few published posts, a page and pretty permalinks. On Jurassic Ninja, the default core is 7.1; for 7.2 run wp core update --version=nightly --force.

Turn off page caching first, or 302s get cached (wp config set WP_CACHE false --raw on JN).

WordPress 7.2:

  • wp eval 'var_dump( function_exists( "jetpack_matt_random_redirect" ) );' prints bool(false).
  • /random/, /?random and /category/<slug>/?random 302 to a random post, with X-Robots-Tag: noindex, follow (that header means core handled it).
  • /<some-page>/?random and /<some-post>/?random return 200 with no redirect. On trunk, Jetpack redirects these.

WordPress 7.1:

  • function_exists( "jetpack_matt_random_redirect" ) is true.
  • /?random 302s to a random post with no X-Robots-Tag header (Jetpack handled it).
  • /?random&random_post_type=page 302s to a page.
  • /random/ is a 404, as before.

WordPress.com Simple: on a sandboxed Simple site running 7.2, ?random on a single post or page no longer redirects, and /random/ is handled by core. I haven't tested this one; it needs a WordPress.com sandbox.

I ran both on Jurassic Ninja with Jetpack trunk plus this branch's two files, using a temporary mu-plugin to confirm which function issued each redirect. PHPUnit wasn't run locally: Random_Redirect_Test loads the module file directly, so the gate doesn't affect it, but CI runs it against trunk and older WordPress.

…s 7.2

WordPress 7.2 adds random content redirects (/random/, ?random) to core.
Stop loading Jetpack's Random Redirect on 7.2 betas and later, and mark
jetpack_matt_random_redirect() deprecated.
@kraftbj kraftbj added [Feature] Theme Tools [Status] Needs Review This PR is ready for review. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Focus] Compatibility Ensuring our products play well with third-parties labels Nov 7, 2026
@kraftbj kraftbj self-assigned this Nov 7, 2026
@kraftbj
kraftbj requested a review from jeherve November 7, 2026 21:53
@github-actions

github-actions Bot commented Nov 7, 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 update/random-redirect-defer-to-core branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/random-redirect-defer-to-core
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/random-redirect-defer-to-core

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

github-actions Bot commented Nov 7, 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:

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: December 8, 2026
    • Code freeze: December 7, 2026

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

Gate the jetpack-mu-wpcom copy the same way as the Jetpack plugin, and mark its jetpack_matt_random_redirect() deprecated.
@jp-launch-control

jp-launch-control Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit 82c222e, 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 82c222e is available.

Full summary · PHP report · JS report

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

[Feature] Theme Tools [Focus] Compatibility Ensuring our products play well with third-parties [mu wpcom Feature] Random Redirect [Package] Jetpack mu wpcom WordPress.com Features [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.

1 participant