Skip to content

Random Redirect: restore module to the Jetpack plugin - #50940

Merged
DevinWalker merged 5 commits into
trunkfrom
add/restore-random-redirect-module
Jul 31, 2026
Merged

Random Redirect: restore module to the Jetpack plugin#50940
DevinWalker merged 5 commits into
trunkfrom
add/restore-random-redirect-module

Conversation

@mlaetitia

@mlaetitia mlaetitia commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Restore the Random Redirect module that was removed from the Jetpack plugin in #38310, bringing back support for yoursite.example/?random redirects to a random published post.

While restoring it, the post-selection query was updated to use a COUNT plus random OFFSET lookup instead of ORDER BY RAND(), which is expensive and uncached on large sites.

Note: this 'module' can't be turned off on its own. If that is needed then we need to turn this into a proper Jetpack module. Alternatively, the jetpack_random_redirect_enabled filter can be used to turn this off, but it's undocumented at this point.

Related product discussion/links

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

No.

Testing instructions

  • Apply this PR to a Jetpack site with several published posts, some in a category.
  • Visit yoursite.example/?random — repeat visits should redirect to varying published posts.
  • Visit ?random&random_post_type=page — redirects to a random page.
  • Visit ?random&random_cat_id=<category term ID> — redirects stay within that category.
  • Visit ?random&random_cat_id=99999 (nonexistent) — page loads normally, no redirect.
  • Password-protected posts should never be a redirect target.
  • To disable the feature entirely, add add_filter( 'jetpack_random_redirect_enabled', '__return_false' ); and confirm ?random no longer redirects.

@mlaetitia mlaetitia self-assigned this Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 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), and enable the add/restore-random-redirect-module branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/restore-random-redirect-module

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 added [Feature] Theme Tools [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 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 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 Jul 30, 2026
@jp-launch-control

jp-launch-control Bot commented Jul 30, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/modules/module-extras.php 4/37 (10.81%) -0.30% 1 ❤️‍🩹

1 file is newly checked for coverage.

File Coverage
projects/plugins/jetpack/modules/theme-tools/random-redirect.php 38/50 (76.00%) 💚

Full summary · PHP report · JS report

@mlaetitia mlaetitia 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 Jul 30, 2026
@DevinWalker
DevinWalker marked this pull request as ready for review July 31, 2026 18:09
@DevinWalker

Copy link
Copy Markdown
Contributor

@mlaetitia I've published this PR because it's ready for review according to @marktmcgrath and the added label.

@DevinWalker DevinWalker 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.

I have tested this thoroughly and looked at the code. All your testing items above passed and this is ready to merge.

@DevinWalker
DevinWalker merged commit 89ae72d into trunk Jul 31, 2026
78 checks passed
@DevinWalker
DevinWalker deleted the add/restore-random-redirect-module branch July 31, 2026 18:33
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] In Progress [Status] Needs Review This PR is ready for review. labels Jul 31, 2026
haqadn added a commit that referenced this pull request Aug 4, 2026
… has (#51037)

The module was removed from the plugin in 13.6 (#38310) and restored in 16.1
(#50940). While it was gone, some themes and plugins started shipping their own
copy of jetpack_matt_random_redirect(). A theme's functions.php runs before
after_setup_theme, where Jetpack loads module-extras.php, so the theme declares
the function first and the plugin's copy fatals.

Wrap the declaration and its hook in a function_exists() check. The declaration
has to live inside the conditional rather than behind an early return: PHP binds
unconditional top-level function declarations when the file is compiled, so a
runtime check before one never gets the chance to prevent it.


Claude-Session: https://claude.ai/code/session_01U3VxzdSXMePRtoxepyNGYZ

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
haqadn added a commit that referenced this pull request Aug 4, 2026
… has (#51037)

The module was removed from the plugin in 13.6 (#38310) and restored in 16.1
(#50940). While it was gone, some themes and plugins started shipping their own
copy of jetpack_matt_random_redirect(). A theme's functions.php runs before
after_setup_theme, where Jetpack loads module-extras.php, so the theme declares
the function first and the plugin's copy fatals.

Wrap the declaration and its hook in a function_exists() check. The declaration
has to live inside the conditional rather than behind an early return: PHP binds
unconditional top-level function declarations when the file is compiled, so a
runtime check before one never gets the chance to prevent it.


Claude-Session: https://claude.ai/code/session_01U3VxzdSXMePRtoxepyNGYZ

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Theme Tools [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants